...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/network/mgmt/2021-05-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/tracing"
    14  	"net/http"
    15  )
    16  
    17  // SubnetsClient is the network Client
    18  type SubnetsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewSubnetsClient creates an instance of the SubnetsClient client.
    23  func NewSubnetsClient(subscriptionID string) SubnetsClient {
    24  	return NewSubnetsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewSubnetsClientWithBaseURI creates an instance of the SubnetsClient client using a custom endpoint.  Use this when
    28  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewSubnetsClientWithBaseURI(baseURI string, subscriptionID string) SubnetsClient {
    30  	return SubnetsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // CreateOrUpdate creates or updates a subnet in the specified virtual network.
    34  // Parameters:
    35  // resourceGroupName - the name of the resource group.
    36  // virtualNetworkName - the name of the virtual network.
    37  // subnetName - the name of the subnet.
    38  // subnetParameters - parameters supplied to the create or update subnet operation.
    39  func (client SubnetsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters Subnet) (result SubnetsCreateOrUpdateFuture, err error) {
    40  	if tracing.IsEnabled() {
    41  		ctx = tracing.StartSpan(ctx, fqdn+"/SubnetsClient.CreateOrUpdate")
    42  		defer func() {
    43  			sc := -1
    44  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    45  				sc = result.FutureAPI.Response().StatusCode
    46  			}
    47  			tracing.EndSpan(ctx, sc, err)
    48  		}()
    49  	}
    50  	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, virtualNetworkName, subnetName, subnetParameters)
    51  	if err != nil {
    52  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "CreateOrUpdate", nil, "Failure preparing request")
    53  		return
    54  	}
    55  
    56  	result, err = client.CreateOrUpdateSender(req)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    59  		return
    60  	}
    61  
    62  	return
    63  }
    64  
    65  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    66  func (client SubnetsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, subnetParameters Subnet) (*http.Request, error) {
    67  	pathParameters := map[string]interface{}{
    68  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
    69  		"subnetName":         autorest.Encode("path", subnetName),
    70  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
    71  		"virtualNetworkName": autorest.Encode("path", virtualNetworkName),
    72  	}
    73  
    74  	const APIVersion = "2021-05-01"
    75  	queryParameters := map[string]interface{}{
    76  		"api-version": APIVersion,
    77  	}
    78  
    79  	subnetParameters.Etag = nil
    80  	preparer := autorest.CreatePreparer(
    81  		autorest.AsContentType("application/json; charset=utf-8"),
    82  		autorest.AsPut(),
    83  		autorest.WithBaseURL(client.BaseURI),
    84  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}", pathParameters),
    85  		autorest.WithJSON(subnetParameters),
    86  		autorest.WithQueryParameters(queryParameters))
    87  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    88  }
    89  
    90  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    91  // http.Response Body if it receives an error.
    92  func (client SubnetsClient) CreateOrUpdateSender(req *http.Request) (future SubnetsCreateOrUpdateFuture, err error) {
    93  	var resp *http.Response
    94  	future.FutureAPI = &azure.Future{}
    95  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
    96  	if err != nil {
    97  		return
    98  	}
    99  	var azf azure.Future
   100  	azf, err = azure.NewFutureFromResponse(resp)
   101  	future.FutureAPI = &azf
   102  	future.Result = future.result
   103  	return
   104  }
   105  
   106  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   107  // closes the http.Response Body.
   108  func (client SubnetsClient) CreateOrUpdateResponder(resp *http.Response) (result Subnet, err error) {
   109  	err = autorest.Respond(
   110  		resp,
   111  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
   112  		autorest.ByUnmarshallingJSON(&result),
   113  		autorest.ByClosing())
   114  	result.Response = autorest.Response{Response: resp}
   115  	return
   116  }
   117  
   118  // Delete deletes the specified subnet.
   119  // Parameters:
   120  // resourceGroupName - the name of the resource group.
   121  // virtualNetworkName - the name of the virtual network.
   122  // subnetName - the name of the subnet.
   123  func (client SubnetsClient) Delete(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string) (result SubnetsDeleteFuture, err error) {
   124  	if tracing.IsEnabled() {
   125  		ctx = tracing.StartSpan(ctx, fqdn+"/SubnetsClient.Delete")
   126  		defer func() {
   127  			sc := -1
   128  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   129  				sc = result.FutureAPI.Response().StatusCode
   130  			}
   131  			tracing.EndSpan(ctx, sc, err)
   132  		}()
   133  	}
   134  	req, err := client.DeletePreparer(ctx, resourceGroupName, virtualNetworkName, subnetName)
   135  	if err != nil {
   136  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "Delete", nil, "Failure preparing request")
   137  		return
   138  	}
   139  
   140  	result, err = client.DeleteSender(req)
   141  	if err != nil {
   142  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "Delete", result.Response(), "Failure sending request")
   143  		return
   144  	}
   145  
   146  	return
   147  }
   148  
   149  // DeletePreparer prepares the Delete request.
   150  func (client SubnetsClient) DeletePreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string) (*http.Request, error) {
   151  	pathParameters := map[string]interface{}{
   152  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   153  		"subnetName":         autorest.Encode("path", subnetName),
   154  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   155  		"virtualNetworkName": autorest.Encode("path", virtualNetworkName),
   156  	}
   157  
   158  	const APIVersion = "2021-05-01"
   159  	queryParameters := map[string]interface{}{
   160  		"api-version": APIVersion,
   161  	}
   162  
   163  	preparer := autorest.CreatePreparer(
   164  		autorest.AsDelete(),
   165  		autorest.WithBaseURL(client.BaseURI),
   166  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}", pathParameters),
   167  		autorest.WithQueryParameters(queryParameters))
   168  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   169  }
   170  
   171  // DeleteSender sends the Delete request. The method will close the
   172  // http.Response Body if it receives an error.
   173  func (client SubnetsClient) DeleteSender(req *http.Request) (future SubnetsDeleteFuture, err error) {
   174  	var resp *http.Response
   175  	future.FutureAPI = &azure.Future{}
   176  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   177  	if err != nil {
   178  		return
   179  	}
   180  	var azf azure.Future
   181  	azf, err = azure.NewFutureFromResponse(resp)
   182  	future.FutureAPI = &azf
   183  	future.Result = future.result
   184  	return
   185  }
   186  
   187  // DeleteResponder handles the response to the Delete request. The method always
   188  // closes the http.Response Body.
   189  func (client SubnetsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   190  	err = autorest.Respond(
   191  		resp,
   192  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   193  		autorest.ByClosing())
   194  	result.Response = resp
   195  	return
   196  }
   197  
   198  // Get gets the specified subnet by virtual network and resource group.
   199  // Parameters:
   200  // resourceGroupName - the name of the resource group.
   201  // virtualNetworkName - the name of the virtual network.
   202  // subnetName - the name of the subnet.
   203  // expand - expands referenced resources.
   204  func (client SubnetsClient) Get(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, expand string) (result Subnet, err error) {
   205  	if tracing.IsEnabled() {
   206  		ctx = tracing.StartSpan(ctx, fqdn+"/SubnetsClient.Get")
   207  		defer func() {
   208  			sc := -1
   209  			if result.Response.Response != nil {
   210  				sc = result.Response.Response.StatusCode
   211  			}
   212  			tracing.EndSpan(ctx, sc, err)
   213  		}()
   214  	}
   215  	req, err := client.GetPreparer(ctx, resourceGroupName, virtualNetworkName, subnetName, expand)
   216  	if err != nil {
   217  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "Get", nil, "Failure preparing request")
   218  		return
   219  	}
   220  
   221  	resp, err := client.GetSender(req)
   222  	if err != nil {
   223  		result.Response = autorest.Response{Response: resp}
   224  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "Get", resp, "Failure sending request")
   225  		return
   226  	}
   227  
   228  	result, err = client.GetResponder(resp)
   229  	if err != nil {
   230  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "Get", resp, "Failure responding to request")
   231  		return
   232  	}
   233  
   234  	return
   235  }
   236  
   237  // GetPreparer prepares the Get request.
   238  func (client SubnetsClient) GetPreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, expand string) (*http.Request, error) {
   239  	pathParameters := map[string]interface{}{
   240  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   241  		"subnetName":         autorest.Encode("path", subnetName),
   242  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   243  		"virtualNetworkName": autorest.Encode("path", virtualNetworkName),
   244  	}
   245  
   246  	const APIVersion = "2021-05-01"
   247  	queryParameters := map[string]interface{}{
   248  		"api-version": APIVersion,
   249  	}
   250  	if len(expand) > 0 {
   251  		queryParameters["$expand"] = autorest.Encode("query", expand)
   252  	}
   253  
   254  	preparer := autorest.CreatePreparer(
   255  		autorest.AsGet(),
   256  		autorest.WithBaseURL(client.BaseURI),
   257  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}", pathParameters),
   258  		autorest.WithQueryParameters(queryParameters))
   259  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   260  }
   261  
   262  // GetSender sends the Get request. The method will close the
   263  // http.Response Body if it receives an error.
   264  func (client SubnetsClient) GetSender(req *http.Request) (*http.Response, error) {
   265  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   266  }
   267  
   268  // GetResponder handles the response to the Get request. The method always
   269  // closes the http.Response Body.
   270  func (client SubnetsClient) GetResponder(resp *http.Response) (result Subnet, err error) {
   271  	err = autorest.Respond(
   272  		resp,
   273  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   274  		autorest.ByUnmarshallingJSON(&result),
   275  		autorest.ByClosing())
   276  	result.Response = autorest.Response{Response: resp}
   277  	return
   278  }
   279  
   280  // List gets all subnets in a virtual network.
   281  // Parameters:
   282  // resourceGroupName - the name of the resource group.
   283  // virtualNetworkName - the name of the virtual network.
   284  func (client SubnetsClient) List(ctx context.Context, resourceGroupName string, virtualNetworkName string) (result SubnetListResultPage, err error) {
   285  	if tracing.IsEnabled() {
   286  		ctx = tracing.StartSpan(ctx, fqdn+"/SubnetsClient.List")
   287  		defer func() {
   288  			sc := -1
   289  			if result.slr.Response.Response != nil {
   290  				sc = result.slr.Response.Response.StatusCode
   291  			}
   292  			tracing.EndSpan(ctx, sc, err)
   293  		}()
   294  	}
   295  	result.fn = client.listNextResults
   296  	req, err := client.ListPreparer(ctx, resourceGroupName, virtualNetworkName)
   297  	if err != nil {
   298  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "List", nil, "Failure preparing request")
   299  		return
   300  	}
   301  
   302  	resp, err := client.ListSender(req)
   303  	if err != nil {
   304  		result.slr.Response = autorest.Response{Response: resp}
   305  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "List", resp, "Failure sending request")
   306  		return
   307  	}
   308  
   309  	result.slr, err = client.ListResponder(resp)
   310  	if err != nil {
   311  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "List", resp, "Failure responding to request")
   312  		return
   313  	}
   314  	if result.slr.hasNextLink() && result.slr.IsEmpty() {
   315  		err = result.NextWithContext(ctx)
   316  		return
   317  	}
   318  
   319  	return
   320  }
   321  
   322  // ListPreparer prepares the List request.
   323  func (client SubnetsClient) ListPreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string) (*http.Request, error) {
   324  	pathParameters := map[string]interface{}{
   325  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   326  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   327  		"virtualNetworkName": autorest.Encode("path", virtualNetworkName),
   328  	}
   329  
   330  	const APIVersion = "2021-05-01"
   331  	queryParameters := map[string]interface{}{
   332  		"api-version": APIVersion,
   333  	}
   334  
   335  	preparer := autorest.CreatePreparer(
   336  		autorest.AsGet(),
   337  		autorest.WithBaseURL(client.BaseURI),
   338  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets", pathParameters),
   339  		autorest.WithQueryParameters(queryParameters))
   340  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   341  }
   342  
   343  // ListSender sends the List request. The method will close the
   344  // http.Response Body if it receives an error.
   345  func (client SubnetsClient) ListSender(req *http.Request) (*http.Response, error) {
   346  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   347  }
   348  
   349  // ListResponder handles the response to the List request. The method always
   350  // closes the http.Response Body.
   351  func (client SubnetsClient) ListResponder(resp *http.Response) (result SubnetListResult, err error) {
   352  	err = autorest.Respond(
   353  		resp,
   354  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   355  		autorest.ByUnmarshallingJSON(&result),
   356  		autorest.ByClosing())
   357  	result.Response = autorest.Response{Response: resp}
   358  	return
   359  }
   360  
   361  // listNextResults retrieves the next set of results, if any.
   362  func (client SubnetsClient) listNextResults(ctx context.Context, lastResults SubnetListResult) (result SubnetListResult, err error) {
   363  	req, err := lastResults.subnetListResultPreparer(ctx)
   364  	if err != nil {
   365  		return result, autorest.NewErrorWithError(err, "network.SubnetsClient", "listNextResults", nil, "Failure preparing next results request")
   366  	}
   367  	if req == nil {
   368  		return
   369  	}
   370  	resp, err := client.ListSender(req)
   371  	if err != nil {
   372  		result.Response = autorest.Response{Response: resp}
   373  		return result, autorest.NewErrorWithError(err, "network.SubnetsClient", "listNextResults", resp, "Failure sending next results request")
   374  	}
   375  	result, err = client.ListResponder(resp)
   376  	if err != nil {
   377  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "listNextResults", resp, "Failure responding to next results request")
   378  	}
   379  	return
   380  }
   381  
   382  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   383  func (client SubnetsClient) ListComplete(ctx context.Context, resourceGroupName string, virtualNetworkName string) (result SubnetListResultIterator, err error) {
   384  	if tracing.IsEnabled() {
   385  		ctx = tracing.StartSpan(ctx, fqdn+"/SubnetsClient.List")
   386  		defer func() {
   387  			sc := -1
   388  			if result.Response().Response.Response != nil {
   389  				sc = result.page.Response().Response.Response.StatusCode
   390  			}
   391  			tracing.EndSpan(ctx, sc, err)
   392  		}()
   393  	}
   394  	result.page, err = client.List(ctx, resourceGroupName, virtualNetworkName)
   395  	return
   396  }
   397  
   398  // PrepareNetworkPolicies prepares a subnet by applying network intent policies.
   399  // Parameters:
   400  // resourceGroupName - the name of the resource group.
   401  // virtualNetworkName - the name of the virtual network.
   402  // subnetName - the name of the subnet.
   403  // prepareNetworkPoliciesRequestParameters - parameters supplied to prepare subnet by applying network intent
   404  // policies.
   405  func (client SubnetsClient) PrepareNetworkPolicies(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, prepareNetworkPoliciesRequestParameters PrepareNetworkPoliciesRequest) (result SubnetsPrepareNetworkPoliciesFuture, err error) {
   406  	if tracing.IsEnabled() {
   407  		ctx = tracing.StartSpan(ctx, fqdn+"/SubnetsClient.PrepareNetworkPolicies")
   408  		defer func() {
   409  			sc := -1
   410  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   411  				sc = result.FutureAPI.Response().StatusCode
   412  			}
   413  			tracing.EndSpan(ctx, sc, err)
   414  		}()
   415  	}
   416  	req, err := client.PrepareNetworkPoliciesPreparer(ctx, resourceGroupName, virtualNetworkName, subnetName, prepareNetworkPoliciesRequestParameters)
   417  	if err != nil {
   418  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "PrepareNetworkPolicies", nil, "Failure preparing request")
   419  		return
   420  	}
   421  
   422  	result, err = client.PrepareNetworkPoliciesSender(req)
   423  	if err != nil {
   424  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "PrepareNetworkPolicies", result.Response(), "Failure sending request")
   425  		return
   426  	}
   427  
   428  	return
   429  }
   430  
   431  // PrepareNetworkPoliciesPreparer prepares the PrepareNetworkPolicies request.
   432  func (client SubnetsClient) PrepareNetworkPoliciesPreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, prepareNetworkPoliciesRequestParameters PrepareNetworkPoliciesRequest) (*http.Request, error) {
   433  	pathParameters := map[string]interface{}{
   434  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   435  		"subnetName":         autorest.Encode("path", subnetName),
   436  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   437  		"virtualNetworkName": autorest.Encode("path", virtualNetworkName),
   438  	}
   439  
   440  	const APIVersion = "2021-05-01"
   441  	queryParameters := map[string]interface{}{
   442  		"api-version": APIVersion,
   443  	}
   444  
   445  	preparer := autorest.CreatePreparer(
   446  		autorest.AsContentType("application/json; charset=utf-8"),
   447  		autorest.AsPost(),
   448  		autorest.WithBaseURL(client.BaseURI),
   449  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}/PrepareNetworkPolicies", pathParameters),
   450  		autorest.WithJSON(prepareNetworkPoliciesRequestParameters),
   451  		autorest.WithQueryParameters(queryParameters))
   452  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   453  }
   454  
   455  // PrepareNetworkPoliciesSender sends the PrepareNetworkPolicies request. The method will close the
   456  // http.Response Body if it receives an error.
   457  func (client SubnetsClient) PrepareNetworkPoliciesSender(req *http.Request) (future SubnetsPrepareNetworkPoliciesFuture, err error) {
   458  	var resp *http.Response
   459  	future.FutureAPI = &azure.Future{}
   460  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   461  	if err != nil {
   462  		return
   463  	}
   464  	var azf azure.Future
   465  	azf, err = azure.NewFutureFromResponse(resp)
   466  	future.FutureAPI = &azf
   467  	future.Result = future.result
   468  	return
   469  }
   470  
   471  // PrepareNetworkPoliciesResponder handles the response to the PrepareNetworkPolicies request. The method always
   472  // closes the http.Response Body.
   473  func (client SubnetsClient) PrepareNetworkPoliciesResponder(resp *http.Response) (result autorest.Response, err error) {
   474  	err = autorest.Respond(
   475  		resp,
   476  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   477  		autorest.ByClosing())
   478  	result.Response = resp
   479  	return
   480  }
   481  
   482  // UnprepareNetworkPolicies unprepares a subnet by removing network intent policies.
   483  // Parameters:
   484  // resourceGroupName - the name of the resource group.
   485  // virtualNetworkName - the name of the virtual network.
   486  // subnetName - the name of the subnet.
   487  // unprepareNetworkPoliciesRequestParameters - parameters supplied to unprepare subnet to remove network intent
   488  // policies.
   489  func (client SubnetsClient) UnprepareNetworkPolicies(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, unprepareNetworkPoliciesRequestParameters UnprepareNetworkPoliciesRequest) (result SubnetsUnprepareNetworkPoliciesFuture, err error) {
   490  	if tracing.IsEnabled() {
   491  		ctx = tracing.StartSpan(ctx, fqdn+"/SubnetsClient.UnprepareNetworkPolicies")
   492  		defer func() {
   493  			sc := -1
   494  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   495  				sc = result.FutureAPI.Response().StatusCode
   496  			}
   497  			tracing.EndSpan(ctx, sc, err)
   498  		}()
   499  	}
   500  	req, err := client.UnprepareNetworkPoliciesPreparer(ctx, resourceGroupName, virtualNetworkName, subnetName, unprepareNetworkPoliciesRequestParameters)
   501  	if err != nil {
   502  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "UnprepareNetworkPolicies", nil, "Failure preparing request")
   503  		return
   504  	}
   505  
   506  	result, err = client.UnprepareNetworkPoliciesSender(req)
   507  	if err != nil {
   508  		err = autorest.NewErrorWithError(err, "network.SubnetsClient", "UnprepareNetworkPolicies", result.Response(), "Failure sending request")
   509  		return
   510  	}
   511  
   512  	return
   513  }
   514  
   515  // UnprepareNetworkPoliciesPreparer prepares the UnprepareNetworkPolicies request.
   516  func (client SubnetsClient) UnprepareNetworkPoliciesPreparer(ctx context.Context, resourceGroupName string, virtualNetworkName string, subnetName string, unprepareNetworkPoliciesRequestParameters UnprepareNetworkPoliciesRequest) (*http.Request, error) {
   517  	pathParameters := map[string]interface{}{
   518  		"resourceGroupName":  autorest.Encode("path", resourceGroupName),
   519  		"subnetName":         autorest.Encode("path", subnetName),
   520  		"subscriptionId":     autorest.Encode("path", client.SubscriptionID),
   521  		"virtualNetworkName": autorest.Encode("path", virtualNetworkName),
   522  	}
   523  
   524  	const APIVersion = "2021-05-01"
   525  	queryParameters := map[string]interface{}{
   526  		"api-version": APIVersion,
   527  	}
   528  
   529  	preparer := autorest.CreatePreparer(
   530  		autorest.AsContentType("application/json; charset=utf-8"),
   531  		autorest.AsPost(),
   532  		autorest.WithBaseURL(client.BaseURI),
   533  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/virtualNetworks/{virtualNetworkName}/subnets/{subnetName}/UnprepareNetworkPolicies", pathParameters),
   534  		autorest.WithJSON(unprepareNetworkPoliciesRequestParameters),
   535  		autorest.WithQueryParameters(queryParameters))
   536  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   537  }
   538  
   539  // UnprepareNetworkPoliciesSender sends the UnprepareNetworkPolicies request. The method will close the
   540  // http.Response Body if it receives an error.
   541  func (client SubnetsClient) UnprepareNetworkPoliciesSender(req *http.Request) (future SubnetsUnprepareNetworkPoliciesFuture, err error) {
   542  	var resp *http.Response
   543  	future.FutureAPI = &azure.Future{}
   544  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   545  	if err != nil {
   546  		return
   547  	}
   548  	var azf azure.Future
   549  	azf, err = azure.NewFutureFromResponse(resp)
   550  	future.FutureAPI = &azf
   551  	future.Result = future.result
   552  	return
   553  }
   554  
   555  // UnprepareNetworkPoliciesResponder handles the response to the UnprepareNetworkPolicies request. The method always
   556  // closes the http.Response Body.
   557  func (client SubnetsClient) UnprepareNetworkPoliciesResponder(resp *http.Response) (result autorest.Response, err error) {
   558  	err = autorest.Respond(
   559  		resp,
   560  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   561  		autorest.ByClosing())
   562  	result.Response = resp
   563  	return
   564  }
   565  

View as plain text