1package migrate 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/tracing" 25 "net/http" 26) 27 28// MachinesClient is the migrate your workloads to Azure. 29type MachinesClient struct { 30 BaseClient 31} 32 33// NewMachinesClient creates an instance of the MachinesClient client. 34func NewMachinesClient(subscriptionID string, acceptLanguage string) MachinesClient { 35 return NewMachinesClientWithBaseURI(DefaultBaseURI, subscriptionID, acceptLanguage) 36} 37 38// NewMachinesClientWithBaseURI creates an instance of the MachinesClient client. 39func NewMachinesClientWithBaseURI(baseURI string, subscriptionID string, acceptLanguage string) MachinesClient { 40 return MachinesClient{NewWithBaseURI(baseURI, subscriptionID, acceptLanguage)} 41} 42 43// EnumerateMachines sends the enumerate machines request. 44// Parameters: 45// resourceGroupName - name of the Azure Resource Group that migrate project is part of. 46// migrateProjectName - name of the Azure Migrate project. 47// continuationToken - the continuation token. 48// pageSize - the number of items to be returned in a single page. This value is honored only if it is less 49// than the 100. 50func (client MachinesClient) EnumerateMachines(ctx context.Context, resourceGroupName string, migrateProjectName string, continuationToken string, pageSize *int32) (result MachineCollection, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/MachinesClient.EnumerateMachines") 53 defer func() { 54 sc := -1 55 if result.Response.Response != nil { 56 sc = result.Response.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 req, err := client.EnumerateMachinesPreparer(ctx, resourceGroupName, migrateProjectName, continuationToken, pageSize) 62 if err != nil { 63 err = autorest.NewErrorWithError(err, "migrate.MachinesClient", "EnumerateMachines", nil, "Failure preparing request") 64 return 65 } 66 67 resp, err := client.EnumerateMachinesSender(req) 68 if err != nil { 69 result.Response = autorest.Response{Response: resp} 70 err = autorest.NewErrorWithError(err, "migrate.MachinesClient", "EnumerateMachines", resp, "Failure sending request") 71 return 72 } 73 74 result, err = client.EnumerateMachinesResponder(resp) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "migrate.MachinesClient", "EnumerateMachines", resp, "Failure responding to request") 77 } 78 79 return 80} 81 82// EnumerateMachinesPreparer prepares the EnumerateMachines request. 83func (client MachinesClient) EnumerateMachinesPreparer(ctx context.Context, resourceGroupName string, migrateProjectName string, continuationToken string, pageSize *int32) (*http.Request, error) { 84 pathParameters := map[string]interface{}{ 85 "migrateProjectName": autorest.Encode("path", migrateProjectName), 86 "resourceGroupName": autorest.Encode("path", resourceGroupName), 87 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 88 } 89 90 const APIVersion = "2018-09-01-preview" 91 queryParameters := map[string]interface{}{ 92 "api-version": APIVersion, 93 } 94 if len(continuationToken) > 0 { 95 queryParameters["continuationToken"] = autorest.Encode("query", continuationToken) 96 } 97 if pageSize != nil { 98 queryParameters["pageSize"] = autorest.Encode("query", *pageSize) 99 } 100 101 preparer := autorest.CreatePreparer( 102 autorest.AsGet(), 103 autorest.WithBaseURL(client.BaseURI), 104 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Migrate/migrateProjects/{migrateProjectName}/machines", pathParameters), 105 autorest.WithQueryParameters(queryParameters)) 106 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 107} 108 109// EnumerateMachinesSender sends the EnumerateMachines request. The method will close the 110// http.Response Body if it receives an error. 111func (client MachinesClient) EnumerateMachinesSender(req *http.Request) (*http.Response, error) { 112 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 113 return autorest.SendWithSender(client, req, sd...) 114} 115 116// EnumerateMachinesResponder handles the response to the EnumerateMachines request. The method always 117// closes the http.Response Body. 118func (client MachinesClient) EnumerateMachinesResponder(resp *http.Response) (result MachineCollection, err error) { 119 err = autorest.Respond( 120 resp, 121 client.ByInspecting(), 122 azure.WithErrorUnlessStatusCode(http.StatusOK), 123 autorest.ByUnmarshallingJSON(&result), 124 autorest.ByClosing()) 125 result.Response = autorest.Response{Response: resp} 126 return 127} 128 129// GetMachine sends the get machine request. 130// Parameters: 131// resourceGroupName - name of the Azure Resource Group that migrate project is part of. 132// migrateProjectName - name of the Azure Migrate project. 133// machineName - unique name of a machine in Azure migration hub. 134func (client MachinesClient) GetMachine(ctx context.Context, resourceGroupName string, migrateProjectName string, machineName string) (result Machine, err error) { 135 if tracing.IsEnabled() { 136 ctx = tracing.StartSpan(ctx, fqdn+"/MachinesClient.GetMachine") 137 defer func() { 138 sc := -1 139 if result.Response.Response != nil { 140 sc = result.Response.Response.StatusCode 141 } 142 tracing.EndSpan(ctx, sc, err) 143 }() 144 } 145 req, err := client.GetMachinePreparer(ctx, resourceGroupName, migrateProjectName, machineName) 146 if err != nil { 147 err = autorest.NewErrorWithError(err, "migrate.MachinesClient", "GetMachine", nil, "Failure preparing request") 148 return 149 } 150 151 resp, err := client.GetMachineSender(req) 152 if err != nil { 153 result.Response = autorest.Response{Response: resp} 154 err = autorest.NewErrorWithError(err, "migrate.MachinesClient", "GetMachine", resp, "Failure sending request") 155 return 156 } 157 158 result, err = client.GetMachineResponder(resp) 159 if err != nil { 160 err = autorest.NewErrorWithError(err, "migrate.MachinesClient", "GetMachine", resp, "Failure responding to request") 161 } 162 163 return 164} 165 166// GetMachinePreparer prepares the GetMachine request. 167func (client MachinesClient) GetMachinePreparer(ctx context.Context, resourceGroupName string, migrateProjectName string, machineName string) (*http.Request, error) { 168 pathParameters := map[string]interface{}{ 169 "machineName": autorest.Encode("path", machineName), 170 "migrateProjectName": autorest.Encode("path", migrateProjectName), 171 "resourceGroupName": autorest.Encode("path", resourceGroupName), 172 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 173 } 174 175 const APIVersion = "2018-09-01-preview" 176 queryParameters := map[string]interface{}{ 177 "api-version": APIVersion, 178 } 179 180 preparer := autorest.CreatePreparer( 181 autorest.AsGet(), 182 autorest.WithBaseURL(client.BaseURI), 183 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Migrate/migrateProjects/{migrateProjectName}/machines/{machineName}", pathParameters), 184 autorest.WithQueryParameters(queryParameters)) 185 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 186} 187 188// GetMachineSender sends the GetMachine request. The method will close the 189// http.Response Body if it receives an error. 190func (client MachinesClient) GetMachineSender(req *http.Request) (*http.Response, error) { 191 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 192 return autorest.SendWithSender(client, req, sd...) 193} 194 195// GetMachineResponder handles the response to the GetMachine request. The method always 196// closes the http.Response Body. 197func (client MachinesClient) GetMachineResponder(resp *http.Response) (result Machine, err error) { 198 err = autorest.Respond( 199 resp, 200 client.ByInspecting(), 201 azure.WithErrorUnlessStatusCode(http.StatusOK), 202 autorest.ByUnmarshallingJSON(&result), 203 autorest.ByClosing()) 204 result.Response = autorest.Response{Response: resp} 205 return 206} 207