...

Source file src/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network/virtualhubipconfiguration.go

Documentation: github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-08-01/network

     1  package 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  
     9  import (
    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
    19  type VirtualHubIPConfigurationClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewVirtualHubIPConfigurationClient creates an instance of the VirtualHubIPConfigurationClient client.
    24  func 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).
    31  func 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.
    42  func (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.PublicIPAddressPropertiesFormat", Name: validation.Null, Rule: false,
    58  						Chain: []validation.Constraint{{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration", Name: validation.Null, Rule: false,
    59  							Chain: []validation.Constraint{{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration.IPConfigurationPropertiesFormat", Name: validation.Null, Rule: false,
    60  								Chain: []validation.Constraint{{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.IPConfiguration.IPConfigurationPropertiesFormat.PublicIPAddress", Name: validation.Null, Rule: false, Chain: nil}}},
    61  							}},
    62  							{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.ServicePublicIPAddress", Name: validation.Null, Rule: false, Chain: nil},
    63  							{Target: "parameters.HubIPConfigurationPropertiesFormat.PublicIPAddress.PublicIPAddressPropertiesFormat.LinkedPublicIPAddress", Name: validation.Null, Rule: false, Chain: nil},
    64  						}},
    65  					}},
    66  				}}}}}); err != nil {
    67  		return result, validation.NewError("network.VirtualHubIPConfigurationClient", "CreateOrUpdate", err.Error())
    68  	}
    69  
    70  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, virtualHubName, IPConfigName, parameters)
    71  	if err != nil {
    72  		err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "CreateOrUpdate", nil, "Failure preparing request")
    73  		return
    74  	}
    75  
    76  	result, err = client.CreateOrUpdateSender(req)
    77  	if err != nil {
    78  		err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    79  		return
    80  	}
    81  
    82  	return
    83  }
    84  
    85  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    86  func (client VirtualHubIPConfigurationClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, virtualHubName string, IPConfigName string, parameters HubIPConfiguration) (*http.Request, error) {
    87  	pathParameters := map[string]interface{}{
    88  		"ipConfigName":      autorest.Encode("path", IPConfigName),
    89  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    90  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    91  		"virtualHubName":    autorest.Encode("path", virtualHubName),
    92  	}
    93  
    94  	const APIVersion = "2021-08-01"
    95  	queryParameters := map[string]interface{}{
    96  		"api-version": APIVersion,
    97  	}
    98  
    99  	parameters.Etag = nil
   100  	parameters.Type = nil
   101  	preparer := autorest.CreatePreparer(
   102  		autorest.AsContentType("application/json; charset=utf-8"),
   103  		autorest.AsPut(),
   104  		autorest.WithBaseURL(client.BaseURI),
   105  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/ipConfigurations/{ipConfigName}", pathParameters),
   106  		autorest.WithJSON(parameters),
   107  		autorest.WithQueryParameters(queryParameters))
   108  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   109  }
   110  
   111  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   112  // http.Response Body if it receives an error.
   113  func (client VirtualHubIPConfigurationClient) CreateOrUpdateSender(req *http.Request) (future VirtualHubIPConfigurationCreateOrUpdateFuture, err error) {
   114  	var resp *http.Response
   115  	future.FutureAPI = &azure.Future{}
   116  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   117  	if err != nil {
   118  		return
   119  	}
   120  	var azf azure.Future
   121  	azf, err = azure.NewFutureFromResponse(resp)
   122  	future.FutureAPI = &azf
   123  	future.Result = future.result
   124  	return
   125  }
   126  
   127  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   128  // closes the http.Response Body.
   129  func (client VirtualHubIPConfigurationClient) CreateOrUpdateResponder(resp *http.Response) (result HubIPConfiguration, err error) {
   130  	err = autorest.Respond(
   131  		resp,
   132  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   133  		autorest.ByUnmarshallingJSON(&result),
   134  		autorest.ByClosing())
   135  	result.Response = autorest.Response{Response: resp}
   136  	return
   137  }
   138  
   139  // Delete deletes a VirtualHubIpConfiguration.
   140  // Parameters:
   141  // resourceGroupName - the resource group name of the VirtualHubBgpConnection.
   142  // virtualHubName - the name of the VirtualHub.
   143  // IPConfigName - the name of the ipconfig.
   144  func (client VirtualHubIPConfigurationClient) Delete(ctx context.Context, resourceGroupName string, virtualHubName string, IPConfigName string) (result VirtualHubIPConfigurationDeleteFuture, err error) {
   145  	if tracing.IsEnabled() {
   146  		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualHubIPConfigurationClient.Delete")
   147  		defer func() {
   148  			sc := -1
   149  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   150  				sc = result.FutureAPI.Response().StatusCode
   151  			}
   152  			tracing.EndSpan(ctx, sc, err)
   153  		}()
   154  	}
   155  	req, err := client.DeletePreparer(ctx, resourceGroupName, virtualHubName, IPConfigName)
   156  	if err != nil {
   157  		err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "Delete", nil, "Failure preparing request")
   158  		return
   159  	}
   160  
   161  	result, err = client.DeleteSender(req)
   162  	if err != nil {
   163  		err = autorest.NewErrorWithError(err, "network.VirtualHubIPConfigurationClient", "Delete", result.Response(), "Failure sending request")
   164  		return
   165  	}
   166  
   167  	return
   168  }
   169  
   170  // DeletePreparer prepares the Delete request.
   171  func (client VirtualHubIPConfigurationClient) DeletePreparer(ctx context.Context, resourceGroupName string, virtualHubName string, IPConfigName string) (*http.Request, error) {
   172  	pathParameters := map[string]interface{}{
   173  		"ipConfigName":      autorest.Encode("path", IPConfigName),
   174  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   175  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   176  		"virtualHubName":    autorest.Encode("path", virtualHubName),
   177  	}
   178  
   179  	const APIVersion = "2021-08-01"
   180  	queryParameters := map[string]interface{}{
   181  		"api-version": APIVersion,
   182  	}
   183  
   184  	preparer := autorest.CreatePreparer(
   185  		autorest.AsDelete(),
   186  		autorest.WithBaseURL(client.BaseURI),
   187  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualHubs/{virtualHubName}/ipConfigurations/{ipConfigName}", pathParameters),
   188  		autorest.WithQueryParameters(queryParameters))
   189  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   190  }
   191  
   192  // DeleteSender sends the Delete request. The method will close the
   193  // http.Response Body if it receives an error.
   194  func (client VirtualHubIPConfigurationClient) DeleteSender(req *http.Request) (future VirtualHubIPConfigurationDeleteFuture, err error) {
   195  	var resp *http.Response
   196  	future.FutureAPI = &azure.Future{}
   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.
   210  func (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.
   224  func (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.
   258  func (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 = "2021-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.
   281  func (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.
   287  func (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.
   301  func (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.
   340  func (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 = "2021-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.
   362  func (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.
   368  func (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.
   379  func (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.
   400  func (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  

View as plain text