1package migrate 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/tracing" 14 "net/http" 15) 16 17// HyperVHostClient is the discover your workloads for Azure. 18type HyperVHostClient struct { 19 BaseClient 20} 21 22// NewHyperVHostClient creates an instance of the HyperVHostClient client. 23func NewHyperVHostClient() HyperVHostClient { 24 return NewHyperVHostClientWithBaseURI(DefaultBaseURI) 25} 26 27// NewHyperVHostClientWithBaseURI creates an instance of the HyperVHostClient client using a custom endpoint. Use this 28// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewHyperVHostClientWithBaseURI(baseURI string) HyperVHostClient { 30 return HyperVHostClient{NewWithBaseURI(baseURI)} 31} 32 33// GetAllHostsInSite sends the get all hosts in site request. 34// Parameters: 35// subscriptionID - the ID of the target subscription. 36// resourceGroupName - the name of the resource group. The name is case insensitive. 37// siteName - site name. 38// APIVersion - the API version to use for this operation. 39func (client HyperVHostClient) GetAllHostsInSite(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, APIVersion string, filter string) (result HyperVHostCollectionPage, err error) { 40 if tracing.IsEnabled() { 41 ctx = tracing.StartSpan(ctx, fqdn+"/HyperVHostClient.GetAllHostsInSite") 42 defer func() { 43 sc := -1 44 if result.hvhc.Response.Response != nil { 45 sc = result.hvhc.Response.Response.StatusCode 46 } 47 tracing.EndSpan(ctx, sc, err) 48 }() 49 } 50 result.fn = client.getAllHostsInSiteNextResults 51 req, err := client.GetAllHostsInSitePreparer(ctx, subscriptionID, resourceGroupName, siteName, APIVersion, filter) 52 if err != nil { 53 err = autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "GetAllHostsInSite", nil, "Failure preparing request") 54 return 55 } 56 57 resp, err := client.GetAllHostsInSiteSender(req) 58 if err != nil { 59 result.hvhc.Response = autorest.Response{Response: resp} 60 err = autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "GetAllHostsInSite", resp, "Failure sending request") 61 return 62 } 63 64 result.hvhc, err = client.GetAllHostsInSiteResponder(resp) 65 if err != nil { 66 err = autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "GetAllHostsInSite", resp, "Failure responding to request") 67 return 68 } 69 if result.hvhc.hasNextLink() && result.hvhc.IsEmpty() { 70 err = result.NextWithContext(ctx) 71 return 72 } 73 74 return 75} 76 77// GetAllHostsInSitePreparer prepares the GetAllHostsInSite request. 78func (client HyperVHostClient) GetAllHostsInSitePreparer(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, APIVersion string, filter string) (*http.Request, error) { 79 pathParameters := map[string]interface{}{ 80 "resourceGroupName": autorest.Encode("path", resourceGroupName), 81 "siteName": autorest.Encode("path", siteName), 82 "subscriptionId": autorest.Encode("path", subscriptionID), 83 } 84 85 queryParameters := map[string]interface{}{ 86 "api-version": APIVersion, 87 } 88 if len(filter) > 0 { 89 queryParameters["$filter"] = autorest.Encode("query", filter) 90 } 91 92 preparer := autorest.CreatePreparer( 93 autorest.AsGet(), 94 autorest.WithBaseURL(client.BaseURI), 95 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OffAzure/HyperVSites/{siteName}/hosts", pathParameters), 96 autorest.WithQueryParameters(queryParameters)) 97 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 98} 99 100// GetAllHostsInSiteSender sends the GetAllHostsInSite request. The method will close the 101// http.Response Body if it receives an error. 102func (client HyperVHostClient) GetAllHostsInSiteSender(req *http.Request) (*http.Response, error) { 103 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 104} 105 106// GetAllHostsInSiteResponder handles the response to the GetAllHostsInSite request. The method always 107// closes the http.Response Body. 108func (client HyperVHostClient) GetAllHostsInSiteResponder(resp *http.Response) (result HyperVHostCollection, err error) { 109 err = autorest.Respond( 110 resp, 111 azure.WithErrorUnlessStatusCode(http.StatusOK), 112 autorest.ByUnmarshallingJSON(&result), 113 autorest.ByClosing()) 114 result.Response = autorest.Response{Response: resp} 115 return 116} 117 118// getAllHostsInSiteNextResults retrieves the next set of results, if any. 119func (client HyperVHostClient) getAllHostsInSiteNextResults(ctx context.Context, lastResults HyperVHostCollection) (result HyperVHostCollection, err error) { 120 req, err := lastResults.hyperVHostCollectionPreparer(ctx) 121 if err != nil { 122 return result, autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "getAllHostsInSiteNextResults", nil, "Failure preparing next results request") 123 } 124 if req == nil { 125 return 126 } 127 resp, err := client.GetAllHostsInSiteSender(req) 128 if err != nil { 129 result.Response = autorest.Response{Response: resp} 130 return result, autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "getAllHostsInSiteNextResults", resp, "Failure sending next results request") 131 } 132 result, err = client.GetAllHostsInSiteResponder(resp) 133 if err != nil { 134 err = autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "getAllHostsInSiteNextResults", resp, "Failure responding to next results request") 135 } 136 return 137} 138 139// GetAllHostsInSiteComplete enumerates all values, automatically crossing page boundaries as required. 140func (client HyperVHostClient) GetAllHostsInSiteComplete(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, APIVersion string, filter string) (result HyperVHostCollectionIterator, err error) { 141 if tracing.IsEnabled() { 142 ctx = tracing.StartSpan(ctx, fqdn+"/HyperVHostClient.GetAllHostsInSite") 143 defer func() { 144 sc := -1 145 if result.Response().Response.Response != nil { 146 sc = result.page.Response().Response.Response.StatusCode 147 } 148 tracing.EndSpan(ctx, sc, err) 149 }() 150 } 151 result.page, err = client.GetAllHostsInSite(ctx, subscriptionID, resourceGroupName, siteName, APIVersion, filter) 152 return 153} 154 155// GetHost sends the get host request. 156// Parameters: 157// subscriptionID - the ID of the target subscription. 158// resourceGroupName - the name of the resource group. The name is case insensitive. 159// siteName - site name. 160// hostName - host ARM name. 161// APIVersion - the API version to use for this operation. 162func (client HyperVHostClient) GetHost(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, hostName string, APIVersion string) (result HyperVHost, err error) { 163 if tracing.IsEnabled() { 164 ctx = tracing.StartSpan(ctx, fqdn+"/HyperVHostClient.GetHost") 165 defer func() { 166 sc := -1 167 if result.Response.Response != nil { 168 sc = result.Response.Response.StatusCode 169 } 170 tracing.EndSpan(ctx, sc, err) 171 }() 172 } 173 req, err := client.GetHostPreparer(ctx, subscriptionID, resourceGroupName, siteName, hostName, APIVersion) 174 if err != nil { 175 err = autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "GetHost", nil, "Failure preparing request") 176 return 177 } 178 179 resp, err := client.GetHostSender(req) 180 if err != nil { 181 result.Response = autorest.Response{Response: resp} 182 err = autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "GetHost", resp, "Failure sending request") 183 return 184 } 185 186 result, err = client.GetHostResponder(resp) 187 if err != nil { 188 err = autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "GetHost", resp, "Failure responding to request") 189 return 190 } 191 192 return 193} 194 195// GetHostPreparer prepares the GetHost request. 196func (client HyperVHostClient) GetHostPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, hostName string, APIVersion string) (*http.Request, error) { 197 pathParameters := map[string]interface{}{ 198 "hostName": autorest.Encode("path", hostName), 199 "resourceGroupName": autorest.Encode("path", resourceGroupName), 200 "siteName": autorest.Encode("path", siteName), 201 "subscriptionId": autorest.Encode("path", subscriptionID), 202 } 203 204 queryParameters := map[string]interface{}{ 205 "api-version": APIVersion, 206 } 207 208 preparer := autorest.CreatePreparer( 209 autorest.AsGet(), 210 autorest.WithBaseURL(client.BaseURI), 211 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OffAzure/HyperVSites/{siteName}/hosts/{hostName}", pathParameters), 212 autorest.WithQueryParameters(queryParameters)) 213 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 214} 215 216// GetHostSender sends the GetHost request. The method will close the 217// http.Response Body if it receives an error. 218func (client HyperVHostClient) GetHostSender(req *http.Request) (*http.Response, error) { 219 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 220} 221 222// GetHostResponder handles the response to the GetHost request. The method always 223// closes the http.Response Body. 224func (client HyperVHostClient) GetHostResponder(resp *http.Response) (result HyperVHost, err error) { 225 err = autorest.Respond( 226 resp, 227 azure.WithErrorUnlessStatusCode(http.StatusOK), 228 autorest.ByUnmarshallingJSON(&result), 229 autorest.ByClosing()) 230 result.Response = autorest.Response{Response: resp} 231 return 232} 233 234// PutHost sends the put host request. 235// Parameters: 236// subscriptionID - the ID of the target subscription. 237// resourceGroupName - the name of the resource group. The name is case insensitive. 238// siteName - site name. 239// hostName - host ARM name. 240// body - put host body. 241// APIVersion - the API version to use for this operation. 242func (client HyperVHostClient) PutHost(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, hostName string, body HyperVHost, APIVersion string) (result autorest.Response, err error) { 243 if tracing.IsEnabled() { 244 ctx = tracing.StartSpan(ctx, fqdn+"/HyperVHostClient.PutHost") 245 defer func() { 246 sc := -1 247 if result.Response != nil { 248 sc = result.Response.StatusCode 249 } 250 tracing.EndSpan(ctx, sc, err) 251 }() 252 } 253 req, err := client.PutHostPreparer(ctx, subscriptionID, resourceGroupName, siteName, hostName, body, APIVersion) 254 if err != nil { 255 err = autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "PutHost", nil, "Failure preparing request") 256 return 257 } 258 259 resp, err := client.PutHostSender(req) 260 if err != nil { 261 result.Response = resp 262 err = autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "PutHost", resp, "Failure sending request") 263 return 264 } 265 266 result, err = client.PutHostResponder(resp) 267 if err != nil { 268 err = autorest.NewErrorWithError(err, "migrate.HyperVHostClient", "PutHost", resp, "Failure responding to request") 269 return 270 } 271 272 return 273} 274 275// PutHostPreparer prepares the PutHost request. 276func (client HyperVHostClient) PutHostPreparer(ctx context.Context, subscriptionID string, resourceGroupName string, siteName string, hostName string, body HyperVHost, APIVersion string) (*http.Request, error) { 277 pathParameters := map[string]interface{}{ 278 "hostName": autorest.Encode("path", hostName), 279 "resourceGroupName": autorest.Encode("path", resourceGroupName), 280 "siteName": autorest.Encode("path", siteName), 281 "subscriptionId": autorest.Encode("path", subscriptionID), 282 } 283 284 queryParameters := map[string]interface{}{ 285 "api-version": APIVersion, 286 } 287 288 body.ID = nil 289 body.Type = nil 290 preparer := autorest.CreatePreparer( 291 autorest.AsContentType("application/json; charset=utf-8"), 292 autorest.AsPut(), 293 autorest.WithBaseURL(client.BaseURI), 294 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.OffAzure/HyperVSites/{siteName}/hosts/{hostName}", pathParameters), 295 autorest.WithJSON(body), 296 autorest.WithQueryParameters(queryParameters)) 297 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 298} 299 300// PutHostSender sends the PutHost request. The method will close the 301// http.Response Body if it receives an error. 302func (client HyperVHostClient) PutHostSender(req *http.Request) (*http.Response, error) { 303 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 304} 305 306// PutHostResponder handles the response to the PutHost request. The method always 307// closes the http.Response Body. 308func (client HyperVHostClient) PutHostResponder(resp *http.Response) (result autorest.Response, err error) { 309 err = autorest.Respond( 310 resp, 311 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 312 autorest.ByClosing()) 313 result.Response = resp 314 return 315} 316