1package resourcemover 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// MoveResourcesClient is the a first party Azure service orchestrating the move of Azure resources from one Azure 19// region to another or between zones within a region. 20type MoveResourcesClient struct { 21 BaseClient 22} 23 24// NewMoveResourcesClient creates an instance of the MoveResourcesClient client. 25func NewMoveResourcesClient(subscriptionID string) MoveResourcesClient { 26 return NewMoveResourcesClientWithBaseURI(DefaultBaseURI, subscriptionID) 27} 28 29// NewMoveResourcesClientWithBaseURI creates an instance of the MoveResourcesClient client using a custom endpoint. 30// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 31func NewMoveResourcesClientWithBaseURI(baseURI string, subscriptionID string) MoveResourcesClient { 32 return MoveResourcesClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// Create creates or updates a Move Resource in the move collection. 36// Parameters: 37// resourceGroupName - the Resource Group Name. 38// moveCollectionName - the Move Collection Name. 39// moveResourceName - the Move Resource Name. 40func (client MoveResourcesClient) Create(ctx context.Context, resourceGroupName string, moveCollectionName string, moveResourceName string, body *MoveResource) (result MoveResourcesCreateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/MoveResourcesClient.Create") 43 defer func() { 44 sc := -1 45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 46 sc = result.FutureAPI.Response().StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 if err := validation.Validate([]validation.Validation{ 52 {TargetValue: body, 53 Constraints: []validation.Constraint{{Target: "body", Name: validation.Null, Rule: false, 54 Chain: []validation.Constraint{{Target: "body.Properties", Name: validation.Null, Rule: false, 55 Chain: []validation.Constraint{{Target: "body.Properties.SourceID", Name: validation.Null, Rule: true, Chain: nil}}}, 56 }}}}}); err != nil { 57 return result, validation.NewError("resourcemover.MoveResourcesClient", "Create", err.Error()) 58 } 59 60 req, err := client.CreatePreparer(ctx, resourceGroupName, moveCollectionName, moveResourceName, body) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "Create", nil, "Failure preparing request") 63 return 64 } 65 66 result, err = client.CreateSender(req) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "Create", nil, "Failure sending request") 69 return 70 } 71 72 return 73} 74 75// CreatePreparer prepares the Create request. 76func (client MoveResourcesClient) CreatePreparer(ctx context.Context, resourceGroupName string, moveCollectionName string, moveResourceName string, body *MoveResource) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "moveCollectionName": autorest.Encode("path", moveCollectionName), 79 "moveResourceName": autorest.Encode("path", moveResourceName), 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 82 } 83 84 const APIVersion = "2021-01-01" 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 89 body.ID = nil 90 body.Name = nil 91 body.Type = nil 92 preparer := autorest.CreatePreparer( 93 autorest.AsContentType("application/json; charset=utf-8"), 94 autorest.AsPut(), 95 autorest.WithBaseURL(client.BaseURI), 96 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Migrate/moveCollections/{moveCollectionName}/moveResources/{moveResourceName}", pathParameters), 97 autorest.WithQueryParameters(queryParameters)) 98 if body != nil { 99 preparer = autorest.DecoratePreparer(preparer, 100 autorest.WithJSON(body)) 101 } 102 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 103} 104 105// CreateSender sends the Create request. The method will close the 106// http.Response Body if it receives an error. 107func (client MoveResourcesClient) CreateSender(req *http.Request) (future MoveResourcesCreateFuture, err error) { 108 var resp *http.Response 109 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 110 if err != nil { 111 return 112 } 113 var azf azure.Future 114 azf, err = azure.NewFutureFromResponse(resp) 115 future.FutureAPI = &azf 116 future.Result = future.result 117 return 118} 119 120// CreateResponder handles the response to the Create request. The method always 121// closes the http.Response Body. 122func (client MoveResourcesClient) CreateResponder(resp *http.Response) (result MoveResource, err error) { 123 err = autorest.Respond( 124 resp, 125 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 126 autorest.ByUnmarshallingJSON(&result), 127 autorest.ByClosing()) 128 result.Response = autorest.Response{Response: resp} 129 return 130} 131 132// Delete deletes a Move Resource from the move collection. 133// Parameters: 134// resourceGroupName - the Resource Group Name. 135// moveCollectionName - the Move Collection Name. 136// moveResourceName - the Move Resource Name. 137func (client MoveResourcesClient) Delete(ctx context.Context, resourceGroupName string, moveCollectionName string, moveResourceName string) (result MoveResourcesDeleteFuture, err error) { 138 if tracing.IsEnabled() { 139 ctx = tracing.StartSpan(ctx, fqdn+"/MoveResourcesClient.Delete") 140 defer func() { 141 sc := -1 142 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 143 sc = result.FutureAPI.Response().StatusCode 144 } 145 tracing.EndSpan(ctx, sc, err) 146 }() 147 } 148 req, err := client.DeletePreparer(ctx, resourceGroupName, moveCollectionName, moveResourceName) 149 if err != nil { 150 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "Delete", nil, "Failure preparing request") 151 return 152 } 153 154 result, err = client.DeleteSender(req) 155 if err != nil { 156 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "Delete", nil, "Failure sending request") 157 return 158 } 159 160 return 161} 162 163// DeletePreparer prepares the Delete request. 164func (client MoveResourcesClient) DeletePreparer(ctx context.Context, resourceGroupName string, moveCollectionName string, moveResourceName string) (*http.Request, error) { 165 pathParameters := map[string]interface{}{ 166 "moveCollectionName": autorest.Encode("path", moveCollectionName), 167 "moveResourceName": autorest.Encode("path", moveResourceName), 168 "resourceGroupName": autorest.Encode("path", resourceGroupName), 169 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 170 } 171 172 const APIVersion = "2021-01-01" 173 queryParameters := map[string]interface{}{ 174 "api-version": APIVersion, 175 } 176 177 preparer := autorest.CreatePreparer( 178 autorest.AsDelete(), 179 autorest.WithBaseURL(client.BaseURI), 180 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Migrate/moveCollections/{moveCollectionName}/moveResources/{moveResourceName}", pathParameters), 181 autorest.WithQueryParameters(queryParameters)) 182 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 183} 184 185// DeleteSender sends the Delete request. The method will close the 186// http.Response Body if it receives an error. 187func (client MoveResourcesClient) DeleteSender(req *http.Request) (future MoveResourcesDeleteFuture, err error) { 188 var resp *http.Response 189 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 190 if err != nil { 191 return 192 } 193 var azf azure.Future 194 azf, err = azure.NewFutureFromResponse(resp) 195 future.FutureAPI = &azf 196 future.Result = future.result 197 return 198} 199 200// DeleteResponder handles the response to the Delete request. The method always 201// closes the http.Response Body. 202func (client MoveResourcesClient) DeleteResponder(resp *http.Response) (result OperationStatus, err error) { 203 err = autorest.Respond( 204 resp, 205 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 206 autorest.ByUnmarshallingJSON(&result), 207 autorest.ByClosing()) 208 result.Response = autorest.Response{Response: resp} 209 return 210} 211 212// Get gets the Move Resource. 213// Parameters: 214// resourceGroupName - the Resource Group Name. 215// moveCollectionName - the Move Collection Name. 216// moveResourceName - the Move Resource Name. 217func (client MoveResourcesClient) Get(ctx context.Context, resourceGroupName string, moveCollectionName string, moveResourceName string) (result MoveResource, err error) { 218 if tracing.IsEnabled() { 219 ctx = tracing.StartSpan(ctx, fqdn+"/MoveResourcesClient.Get") 220 defer func() { 221 sc := -1 222 if result.Response.Response != nil { 223 sc = result.Response.Response.StatusCode 224 } 225 tracing.EndSpan(ctx, sc, err) 226 }() 227 } 228 req, err := client.GetPreparer(ctx, resourceGroupName, moveCollectionName, moveResourceName) 229 if err != nil { 230 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "Get", nil, "Failure preparing request") 231 return 232 } 233 234 resp, err := client.GetSender(req) 235 if err != nil { 236 result.Response = autorest.Response{Response: resp} 237 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "Get", resp, "Failure sending request") 238 return 239 } 240 241 result, err = client.GetResponder(resp) 242 if err != nil { 243 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "Get", resp, "Failure responding to request") 244 return 245 } 246 247 return 248} 249 250// GetPreparer prepares the Get request. 251func (client MoveResourcesClient) GetPreparer(ctx context.Context, resourceGroupName string, moveCollectionName string, moveResourceName string) (*http.Request, error) { 252 pathParameters := map[string]interface{}{ 253 "moveCollectionName": autorest.Encode("path", moveCollectionName), 254 "moveResourceName": autorest.Encode("path", moveResourceName), 255 "resourceGroupName": autorest.Encode("path", resourceGroupName), 256 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 257 } 258 259 const APIVersion = "2021-01-01" 260 queryParameters := map[string]interface{}{ 261 "api-version": APIVersion, 262 } 263 264 preparer := autorest.CreatePreparer( 265 autorest.AsGet(), 266 autorest.WithBaseURL(client.BaseURI), 267 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Migrate/moveCollections/{moveCollectionName}/moveResources/{moveResourceName}", pathParameters), 268 autorest.WithQueryParameters(queryParameters)) 269 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 270} 271 272// GetSender sends the Get request. The method will close the 273// http.Response Body if it receives an error. 274func (client MoveResourcesClient) GetSender(req *http.Request) (*http.Response, error) { 275 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 276} 277 278// GetResponder handles the response to the Get request. The method always 279// closes the http.Response Body. 280func (client MoveResourcesClient) GetResponder(resp *http.Response) (result MoveResource, err error) { 281 err = autorest.Respond( 282 resp, 283 azure.WithErrorUnlessStatusCode(http.StatusOK), 284 autorest.ByUnmarshallingJSON(&result), 285 autorest.ByClosing()) 286 result.Response = autorest.Response{Response: resp} 287 return 288} 289 290// List lists the Move Resources in the move collection. 291// Parameters: 292// resourceGroupName - the Resource Group Name. 293// moveCollectionName - the Move Collection Name. 294// filter - the filter to apply on the operation. For example, you can use $filter=Properties/ProvisioningState 295// eq 'Succeeded'. 296func (client MoveResourcesClient) List(ctx context.Context, resourceGroupName string, moveCollectionName string, filter string) (result MoveResourceCollectionPage, err error) { 297 if tracing.IsEnabled() { 298 ctx = tracing.StartSpan(ctx, fqdn+"/MoveResourcesClient.List") 299 defer func() { 300 sc := -1 301 if result.mrc.Response.Response != nil { 302 sc = result.mrc.Response.Response.StatusCode 303 } 304 tracing.EndSpan(ctx, sc, err) 305 }() 306 } 307 result.fn = client.listNextResults 308 req, err := client.ListPreparer(ctx, resourceGroupName, moveCollectionName, filter) 309 if err != nil { 310 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "List", nil, "Failure preparing request") 311 return 312 } 313 314 resp, err := client.ListSender(req) 315 if err != nil { 316 result.mrc.Response = autorest.Response{Response: resp} 317 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "List", resp, "Failure sending request") 318 return 319 } 320 321 result.mrc, err = client.ListResponder(resp) 322 if err != nil { 323 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "List", resp, "Failure responding to request") 324 return 325 } 326 if result.mrc.hasNextLink() && result.mrc.IsEmpty() { 327 err = result.NextWithContext(ctx) 328 return 329 } 330 331 return 332} 333 334// ListPreparer prepares the List request. 335func (client MoveResourcesClient) ListPreparer(ctx context.Context, resourceGroupName string, moveCollectionName string, filter string) (*http.Request, error) { 336 pathParameters := map[string]interface{}{ 337 "moveCollectionName": autorest.Encode("path", moveCollectionName), 338 "resourceGroupName": autorest.Encode("path", resourceGroupName), 339 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 340 } 341 342 const APIVersion = "2021-01-01" 343 queryParameters := map[string]interface{}{ 344 "api-version": APIVersion, 345 } 346 if len(filter) > 0 { 347 queryParameters["$filter"] = autorest.Encode("query", filter) 348 } 349 350 preparer := autorest.CreatePreparer( 351 autorest.AsGet(), 352 autorest.WithBaseURL(client.BaseURI), 353 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Migrate/moveCollections/{moveCollectionName}/moveResources", pathParameters), 354 autorest.WithQueryParameters(queryParameters)) 355 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 356} 357 358// ListSender sends the List request. The method will close the 359// http.Response Body if it receives an error. 360func (client MoveResourcesClient) ListSender(req *http.Request) (*http.Response, error) { 361 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 362} 363 364// ListResponder handles the response to the List request. The method always 365// closes the http.Response Body. 366func (client MoveResourcesClient) ListResponder(resp *http.Response) (result MoveResourceCollection, err error) { 367 err = autorest.Respond( 368 resp, 369 azure.WithErrorUnlessStatusCode(http.StatusOK), 370 autorest.ByUnmarshallingJSON(&result), 371 autorest.ByClosing()) 372 result.Response = autorest.Response{Response: resp} 373 return 374} 375 376// listNextResults retrieves the next set of results, if any. 377func (client MoveResourcesClient) listNextResults(ctx context.Context, lastResults MoveResourceCollection) (result MoveResourceCollection, err error) { 378 req, err := lastResults.moveResourceCollectionPreparer(ctx) 379 if err != nil { 380 return result, autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "listNextResults", nil, "Failure preparing next results request") 381 } 382 if req == nil { 383 return 384 } 385 resp, err := client.ListSender(req) 386 if err != nil { 387 result.Response = autorest.Response{Response: resp} 388 return result, autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "listNextResults", resp, "Failure sending next results request") 389 } 390 result, err = client.ListResponder(resp) 391 if err != nil { 392 err = autorest.NewErrorWithError(err, "resourcemover.MoveResourcesClient", "listNextResults", resp, "Failure responding to next results request") 393 } 394 return 395} 396 397// ListComplete enumerates all values, automatically crossing page boundaries as required. 398func (client MoveResourcesClient) ListComplete(ctx context.Context, resourceGroupName string, moveCollectionName string, filter string) (result MoveResourceCollectionIterator, err error) { 399 if tracing.IsEnabled() { 400 ctx = tracing.StartSpan(ctx, fqdn+"/MoveResourcesClient.List") 401 defer func() { 402 sc := -1 403 if result.Response().Response.Response != nil { 404 sc = result.page.Response().Response.Response.StatusCode 405 } 406 tracing.EndSpan(ctx, sc, err) 407 }() 408 } 409 result.page, err = client.List(ctx, resourceGroupName, moveCollectionName, filter) 410 return 411} 412