1package network 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// VirtualHubIPConfigurationClient is the network Client 19type VirtualHubIPConfigurationClient struct { 20 BaseClient 21} 22 23// NewVirtualHubIPConfigurationClient creates an instance of the VirtualHubIPConfigurationClient client. 24func NewVirtualHubIPConfigurationClient(subscriptionID string) VirtualHubIPConfigurationClient { 25 return NewVirtualHubIPConfigurationClientWithBaseURI(DefaultBaseURI, subscriptionID) 26} 27 28// NewVirtualHubIPConfigurationClientWithBaseURI creates an instance of the VirtualHubIPConfigurationClient client 29// using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign 30// clouds, Azure stack). 31func NewVirtualHubIPConfigurationClientWithBaseURI(baseURI string, subscriptionID string) VirtualHubIPConfigurationClient { 32 return VirtualHubIPConfigurationClient{NewWithBaseURI(baseURI, subscriptionID)} 33} 34 35// CreateOrUpdate creates a VirtualHubIpConfiguration resource if it doesn't exist else updates the existing 36// VirtualHubIpConfiguration. 37// Parameters: 38// resourceGroupName - the resource group name of the VirtualHub. 39// virtualHubName - the name of the VirtualHub. 40// IPConfigName - the name of the ipconfig. 41// parameters - hub Ip Configuration parameters. 42func (client VirtualHubIPConfigurationClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, virtualHubName string, IPConfigName string, parameters HubIPConfiguration) (result VirtualHubIPConfigurationCreateOrUpdateFuture, err error) { 43 if tracing.IsEnabled() { 44 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubIPConfigurationClient.CreateOrUpdate") 45 defer func() { 46 sc := -1 47 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 48 sc = result.FutureAPI.Response().StatusCode 49 } 50 tracing.EndSpan(ctx, sc, err) 51 }() 52 } 53 if err := validation.Validate([]validation.Validation{ 54 {TargetValue: parameters, 55 Constraints: []validation.Constraint{{Target: "parameters.HubIPConfigurationPropertiesFormat", Name: validation.Null, Rule: false, 56 Chain: []validation.Constraint{{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress", Name: validation.Null, Rule: false, 57 Chain: []validation.Constraint{{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.ExtendedLocation", Name: validation.Null, Rule: false, 58 Chain: []validation.Constraint{{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.ExtendedLocation.Name", Name: validation.Null, Rule: true, Chain: nil}, 59 {Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.ExtendedLocation.Type", Name: validation.Null, Rule: true, Chain: nil}, 60 }}, 61 {Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat", Name: validation.Null, Rule: false, 62 Chain: []validation.Constraint{{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration", Name: validation.Null, Rule: false, 63 Chain: []validation.Constraint{{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration.IPConfigurationPropertiesFormat", Name: validation.Null, Rule: false, 64 Chain: []validation.Constraint{{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration.IPConfigurationPropertiesFormat.PublicIPAddress", Name: validation.Null, Rule: false, Chain: nil}}}, 65 }}, 66 }}, 67 }}, 68 }}}}}); err != nil { 69 return result, validation.NewError("network.VirtualHubIPConfigurationClient", "CreateOrUpdate", err.Error()) 70 } 71 72 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, virtualHubName, IPConfigName, parameters) 73 if err != nil { 74 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "CreateOrUpdate", nil, "Failure preparing request") 75 return 76 } 77 78 result, err = client.CreateOrUpdateSender(req) 79 if err != nil { 80 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "CreateOrUpdate", nil, "Failure sending request") 81 return 82 } 83 84 return 85} 86 87// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 88func (client VirtualHubIPConfigurationClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, virtualHubName string, IPConfigName string, parameters HubIPConfiguration) (*http.Request, error) { 89 pathParameters := map[string]interface{}{ 90 "ipConfigName": autorest.Encode("path", IPConfigName), 91 "resourceGroupName": autorest.Encode("path", resourceGroupName), 92 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 93 "virtualHubName": autorest.Encode("path", virtualHubName), 94 } 95 96 const APIVersion = "2020-08-01" 97 queryParameters := map[string]interface{}{ 98 "api-version": APIVersion, 99 } 100 101 parameters.Etag = nil 102 parameters.Type = nil 103 preparer := autorest.CreatePreparer( 104 autorest.AsContentType("application/json; charset=utf-8"), 105 autorest.AsPut(), 106 autorest.WithBaseURL(client.BaseURI), 107 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/ipConfigurations/{ipConfigName}", pathParameters), 108 autorest.WithJSON(parameters), 109 autorest.WithQueryParameters(queryParameters)) 110 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 111} 112 113// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 114// http.Response Body if it receives an error. 115func (client VirtualHubIPConfigurationClient) CreateOrUpdateSender(req *http.Request) (future VirtualHubIPConfigurationCreateOrUpdateFuture, err error) { 116 var resp *http.Response 117 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 118 if err != nil { 119 return 120 } 121 var azf azure.Future 122 azf, err = azure.NewFutureFromResponse(resp) 123 future.FutureAPI = &azf 124 future.Result = future.result 125 return 126} 127 128// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 129// closes the http.Response Body. 130func (client VirtualHubIPConfigurationClient) CreateOrUpdateResponder(resp *http.Response) (result HubIPConfiguration, err error) { 131 err = autorest.Respond( 132 resp, 133 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 134 autorest.ByUnmarshallingJSON(&result), 135 autorest.ByClosing()) 136 result.Response = autorest.Response{Response: resp} 137 return 138} 139 140// Delete deletes a VirtualHubIpConfiguration. 141// Parameters: 142// resourceGroupName - the resource group name of the VirtualHubBgpConnection. 143// virtualHubName - the name of the VirtualHub. 144// IPConfigName - the name of the ipconfig. 145func (client VirtualHubIPConfigurationClient) Delete(ctx context.Context, resourceGroupName string, virtualHubName string, IPConfigName string) (result VirtualHubIPConfigurationDeleteFuture, err error) { 146 if tracing.IsEnabled() { 147 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubIPConfigurationClient.Delete") 148 defer func() { 149 sc := -1 150 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 151 sc = result.FutureAPI.Response().StatusCode 152 } 153 tracing.EndSpan(ctx, sc, err) 154 }() 155 } 156 req, err := client.DeletePreparer(ctx, resourceGroupName, virtualHubName, IPConfigName) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "Delete", nil, "Failure preparing request") 159 return 160 } 161 162 result, err = client.DeleteSender(req) 163 if err != nil { 164 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "Delete", nil, "Failure sending request") 165 return 166 } 167 168 return 169} 170 171// DeletePreparer prepares the Delete request. 172func (client VirtualHubIPConfigurationClient) DeletePreparer(ctx context.Context, resourceGroupName string, virtualHubName string, IPConfigName string) (*http.Request, error) { 173 pathParameters := map[string]interface{}{ 174 "ipConfigName": autorest.Encode("path", IPConfigName), 175 "resourceGroupName": autorest.Encode("path", resourceGroupName), 176 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 177 "virtualHubName": autorest.Encode("path", virtualHubName), 178 } 179 180 const APIVersion = "2020-08-01" 181 queryParameters := map[string]interface{}{ 182 "api-version": APIVersion, 183 } 184 185 preparer := autorest.CreatePreparer( 186 autorest.AsDelete(), 187 autorest.WithBaseURL(client.BaseURI), 188 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/ipConfigurations/{ipConfigName}", pathParameters), 189 autorest.WithQueryParameters(queryParameters)) 190 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 191} 192 193// DeleteSender sends the Delete request. The method will close the 194// http.Response Body if it receives an error. 195func (client VirtualHubIPConfigurationClient) DeleteSender(req *http.Request) (future VirtualHubIPConfigurationDeleteFuture, err error) { 196 var resp *http.Response 197 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 198 if err != nil { 199 return 200 } 201 var azf azure.Future 202 azf, err = azure.NewFutureFromResponse(resp) 203 future.FutureAPI = &azf 204 future.Result = future.result 205 return 206} 207 208// DeleteResponder handles the response to the Delete request. The method always 209// closes the http.Response Body. 210func (client VirtualHubIPConfigurationClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 211 err = autorest.Respond( 212 resp, 213 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 214 autorest.ByClosing()) 215 result.Response = resp 216 return 217} 218 219// Get retrieves the details of a Virtual Hub Ip configuration. 220// Parameters: 221// resourceGroupName - the resource group name of the VirtualHub. 222// virtualHubName - the name of the VirtualHub. 223// IPConfigName - the name of the ipconfig. 224func (client VirtualHubIPConfigurationClient) Get(ctx context.Context, resourceGroupName string, virtualHubName string, IPConfigName string) (result HubIPConfiguration, err error) { 225 if tracing.IsEnabled() { 226 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubIPConfigurationClient.Get") 227 defer func() { 228 sc := -1 229 if result.Response.Response != nil { 230 sc = result.Response.Response.StatusCode 231 } 232 tracing.EndSpan(ctx, sc, err) 233 }() 234 } 235 req, err := client.GetPreparer(ctx, resourceGroupName, virtualHubName, IPConfigName) 236 if err != nil { 237 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "Get", nil, "Failure preparing request") 238 return 239 } 240 241 resp, err := client.GetSender(req) 242 if err != nil { 243 result.Response = autorest.Response{Response: resp} 244 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "Get", resp, "Failure sending request") 245 return 246 } 247 248 result, err = client.GetResponder(resp) 249 if err != nil { 250 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "Get", resp, "Failure responding to request") 251 return 252 } 253 254 return 255} 256 257// GetPreparer prepares the Get request. 258func (client VirtualHubIPConfigurationClient) GetPreparer(ctx context.Context, resourceGroupName string, virtualHubName string, IPConfigName string) (*http.Request, error) { 259 pathParameters := map[string]interface{}{ 260 "ipConfigName": autorest.Encode("path", IPConfigName), 261 "resourceGroupName": autorest.Encode("path", resourceGroupName), 262 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 263 "virtualHubName": autorest.Encode("path", virtualHubName), 264 } 265 266 const APIVersion = "2020-08-01" 267 queryParameters := map[string]interface{}{ 268 "api-version": APIVersion, 269 } 270 271 preparer := autorest.CreatePreparer( 272 autorest.AsGet(), 273 autorest.WithBaseURL(client.BaseURI), 274 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/ipConfigurations/{ipConfigName}", pathParameters), 275 autorest.WithQueryParameters(queryParameters)) 276 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 277} 278 279// GetSender sends the Get request. The method will close the 280// http.Response Body if it receives an error. 281func (client VirtualHubIPConfigurationClient) GetSender(req *http.Request) (*http.Response, error) { 282 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 283} 284 285// GetResponder handles the response to the Get request. The method always 286// closes the http.Response Body. 287func (client VirtualHubIPConfigurationClient) GetResponder(resp *http.Response) (result HubIPConfiguration, err error) { 288 err = autorest.Respond( 289 resp, 290 azure.WithErrorUnlessStatusCode(http.StatusOK), 291 autorest.ByUnmarshallingJSON(&result), 292 autorest.ByClosing()) 293 result.Response = autorest.Response{Response: resp} 294 return 295} 296 297// List retrieves the details of all VirtualHubIpConfigurations. 298// Parameters: 299// resourceGroupName - the resource group name of the VirtualHub. 300// virtualHubName - the name of the VirtualHub. 301func (client VirtualHubIPConfigurationClient) List(ctx context.Context, resourceGroupName string, virtualHubName string) (result ListVirtualHubIPConfigurationResultsPage, err error) { 302 if tracing.IsEnabled() { 303 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubIPConfigurationClient.List") 304 defer func() { 305 sc := -1 306 if result.lvhicr.Response.Response != nil { 307 sc = result.lvhicr.Response.Response.StatusCode 308 } 309 tracing.EndSpan(ctx, sc, err) 310 }() 311 } 312 result.fn = client.listNextResults 313 req, err := client.ListPreparer(ctx, resourceGroupName, virtualHubName) 314 if err != nil { 315 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "List", nil, "Failure preparing request") 316 return 317 } 318 319 resp, err := client.ListSender(req) 320 if err != nil { 321 result.lvhicr.Response = autorest.Response{Response: resp} 322 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "List", resp, "Failure sending request") 323 return 324 } 325 326 result.lvhicr, err = client.ListResponder(resp) 327 if err != nil { 328 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "List", resp, "Failure responding to request") 329 return 330 } 331 if result.lvhicr.hasNextLink() && result.lvhicr.IsEmpty() { 332 err = result.NextWithContext(ctx) 333 return 334 } 335 336 return 337} 338 339// ListPreparer prepares the List request. 340func (client VirtualHubIPConfigurationClient) ListPreparer(ctx context.Context, resourceGroupName string, virtualHubName string) (*http.Request, error) { 341 pathParameters := map[string]interface{}{ 342 "resourceGroupName": autorest.Encode("path", resourceGroupName), 343 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 344 "virtualHubName": autorest.Encode("path", virtualHubName), 345 } 346 347 const APIVersion = "2020-08-01" 348 queryParameters := map[string]interface{}{ 349 "api-version": APIVersion, 350 } 351 352 preparer := autorest.CreatePreparer( 353 autorest.AsGet(), 354 autorest.WithBaseURL(client.BaseURI), 355 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/ipConfigurations", pathParameters), 356 autorest.WithQueryParameters(queryParameters)) 357 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 358} 359 360// ListSender sends the List request. The method will close the 361// http.Response Body if it receives an error. 362func (client VirtualHubIPConfigurationClient) ListSender(req *http.Request) (*http.Response, error) { 363 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 364} 365 366// ListResponder handles the response to the List request. The method always 367// closes the http.Response Body. 368func (client VirtualHubIPConfigurationClient) ListResponder(resp *http.Response) (result ListVirtualHubIPConfigurationResults, err error) { 369 err = autorest.Respond( 370 resp, 371 azure.WithErrorUnlessStatusCode(http.StatusOK), 372 autorest.ByUnmarshallingJSON(&result), 373 autorest.ByClosing()) 374 result.Response = autorest.Response{Response: resp} 375 return 376} 377 378// listNextResults retrieves the next set of results, if any. 379func (client VirtualHubIPConfigurationClient) listNextResults(ctx context.Context, lastResults ListVirtualHubIPConfigurationResults) (result ListVirtualHubIPConfigurationResults, err error) { 380 req, err := lastResults.listVirtualHubIPConfigurationResultsPreparer(ctx) 381 if err != nil { 382 return result, autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "listNextResults", nil, "Failure preparing next results request") 383 } 384 if req == nil { 385 return 386 } 387 resp, err := client.ListSender(req) 388 if err != nil { 389 result.Response = autorest.Response{Response: resp} 390 return result, autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "listNextResults", resp, "Failure sending next results request") 391 } 392 result, err = client.ListResponder(resp) 393 if err != nil { 394 err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "listNextResults", resp, "Failure responding to next results request") 395 } 396 return 397} 398 399// ListComplete enumerates all values, automatically crossing page boundaries as required. 400func (client VirtualHubIPConfigurationClient) ListComplete(ctx context.Context, resourceGroupName string, virtualHubName string) (result ListVirtualHubIPConfigurationResultsIterator, err error) { 401 if tracing.IsEnabled() { 402 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubIPConfigurationClient.List") 403 defer func() { 404 sc := -1 405 if result.Response().Response.Response != nil { 406 sc = result.page.Response().Response.Response.StatusCode 407 } 408 tracing.EndSpan(ctx, sc, err) 409 }() 410 } 411 result.page, err = client.List(ctx, resourceGroupName, virtualHubName) 412 return 413} 414