...

Source file src/github.com/Azure/azure-sdk-for-go/services/network/mgmt/2022-01-01/network/dscpconfiguration.go

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

View as plain text