...

Source file src/github.com/Azure/azure-sdk-for-go/services/storsimple8000series/mgmt/2017-06-01/storsimple/bandwidthsettings.go

Documentation: github.com/Azure/azure-sdk-for-go/services/storsimple8000series/mgmt/2017-06-01/storsimple

     1  package storsimple
     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  // BandwidthSettingsClient is the client for the BandwidthSettings methods of the Storsimple service.
    19  type BandwidthSettingsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewBandwidthSettingsClient creates an instance of the BandwidthSettingsClient client.
    24  func NewBandwidthSettingsClient(subscriptionID string) BandwidthSettingsClient {
    25  	return NewBandwidthSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewBandwidthSettingsClientWithBaseURI creates an instance of the BandwidthSettingsClient client using a custom
    29  // endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
    30  // stack).
    31  func NewBandwidthSettingsClientWithBaseURI(baseURI string, subscriptionID string) BandwidthSettingsClient {
    32  	return BandwidthSettingsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // CreateOrUpdate creates or updates the bandwidth setting
    36  // Parameters:
    37  // bandwidthSettingName - the bandwidth setting name.
    38  // parameters - the bandwidth setting to be added or updated.
    39  // resourceGroupName - the resource group name
    40  // managerName - the manager name
    41  func (client BandwidthSettingsClient) CreateOrUpdate(ctx context.Context, bandwidthSettingName string, parameters BandwidthSetting, resourceGroupName string, managerName string) (result BandwidthSettingsCreateOrUpdateFuture, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/BandwidthSettingsClient.CreateOrUpdate")
    44  		defer func() {
    45  			sc := -1
    46  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    47  				sc = result.FutureAPI.Response().StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	if err := validation.Validate([]validation.Validation{
    53  		{TargetValue: parameters,
    54  			Constraints: []validation.Constraint{{Target: "parameters.BandwidthRateSettingProperties", Name: validation.Null, Rule: true,
    55  				Chain: []validation.Constraint{{Target: "parameters.BandwidthRateSettingProperties.Schedules", Name: validation.Null, Rule: true, Chain: nil}}}}},
    56  		{TargetValue: managerName,
    57  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
    58  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
    59  		return result, validation.NewError("storsimple.BandwidthSettingsClient", "CreateOrUpdate", err.Error())
    60  	}
    61  
    62  	req, err := client.CreateOrUpdatePreparer(ctx, bandwidthSettingName, parameters, resourceGroupName, managerName)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "CreateOrUpdate", nil, "Failure preparing request")
    65  		return
    66  	}
    67  
    68  	result, err = client.CreateOrUpdateSender(req)
    69  	if err != nil {
    70  		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
    71  		return
    72  	}
    73  
    74  	return
    75  }
    76  
    77  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    78  func (client BandwidthSettingsClient) CreateOrUpdatePreparer(ctx context.Context, bandwidthSettingName string, parameters BandwidthSetting, resourceGroupName string, managerName string) (*http.Request, error) {
    79  	pathParameters := map[string]interface{}{
    80  		"bandwidthSettingName": bandwidthSettingName,
    81  		"managerName":          managerName,
    82  		"resourceGroupName":    resourceGroupName,
    83  		"subscriptionId":       client.SubscriptionID,
    84  	}
    85  
    86  	const APIVersion = "2017-06-01"
    87  	queryParameters := map[string]interface{}{
    88  		"api-version": APIVersion,
    89  	}
    90  
    91  	preparer := autorest.CreatePreparer(
    92  		autorest.AsContentType("application/json; charset=utf-8"),
    93  		autorest.AsPut(),
    94  		autorest.WithBaseURL(client.BaseURI),
    95  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/bandwidthSettings/{bandwidthSettingName}", pathParameters),
    96  		autorest.WithJSON(parameters),
    97  		autorest.WithQueryParameters(queryParameters))
    98  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    99  }
   100  
   101  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   102  // http.Response Body if it receives an error.
   103  func (client BandwidthSettingsClient) CreateOrUpdateSender(req *http.Request) (future BandwidthSettingsCreateOrUpdateFuture, err error) {
   104  	var resp *http.Response
   105  	future.FutureAPI = &azure.Future{}
   106  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   107  	if err != nil {
   108  		return
   109  	}
   110  	var azf azure.Future
   111  	azf, err = azure.NewFutureFromResponse(resp)
   112  	future.FutureAPI = &azf
   113  	future.Result = future.result
   114  	return
   115  }
   116  
   117  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   118  // closes the http.Response Body.
   119  func (client BandwidthSettingsClient) CreateOrUpdateResponder(resp *http.Response) (result BandwidthSetting, err error) {
   120  	err = autorest.Respond(
   121  		resp,
   122  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   123  		autorest.ByUnmarshallingJSON(&result),
   124  		autorest.ByClosing())
   125  	result.Response = autorest.Response{Response: resp}
   126  	return
   127  }
   128  
   129  // Delete deletes the bandwidth setting
   130  // Parameters:
   131  // bandwidthSettingName - the name of the bandwidth setting.
   132  // resourceGroupName - the resource group name
   133  // managerName - the manager name
   134  func (client BandwidthSettingsClient) Delete(ctx context.Context, bandwidthSettingName string, resourceGroupName string, managerName string) (result BandwidthSettingsDeleteFuture, err error) {
   135  	if tracing.IsEnabled() {
   136  		ctx = tracing.StartSpan(ctx, fqdn+"/BandwidthSettingsClient.Delete")
   137  		defer func() {
   138  			sc := -1
   139  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   140  				sc = result.FutureAPI.Response().StatusCode
   141  			}
   142  			tracing.EndSpan(ctx, sc, err)
   143  		}()
   144  	}
   145  	if err := validation.Validate([]validation.Validation{
   146  		{TargetValue: managerName,
   147  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   148  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   149  		return result, validation.NewError("storsimple.BandwidthSettingsClient", "Delete", err.Error())
   150  	}
   151  
   152  	req, err := client.DeletePreparer(ctx, bandwidthSettingName, resourceGroupName, managerName)
   153  	if err != nil {
   154  		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "Delete", nil, "Failure preparing request")
   155  		return
   156  	}
   157  
   158  	result, err = client.DeleteSender(req)
   159  	if err != nil {
   160  		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "Delete", result.Response(), "Failure sending request")
   161  		return
   162  	}
   163  
   164  	return
   165  }
   166  
   167  // DeletePreparer prepares the Delete request.
   168  func (client BandwidthSettingsClient) DeletePreparer(ctx context.Context, bandwidthSettingName string, resourceGroupName string, managerName string) (*http.Request, error) {
   169  	pathParameters := map[string]interface{}{
   170  		"bandwidthSettingName": bandwidthSettingName,
   171  		"managerName":          managerName,
   172  		"resourceGroupName":    resourceGroupName,
   173  		"subscriptionId":       client.SubscriptionID,
   174  	}
   175  
   176  	const APIVersion = "2017-06-01"
   177  	queryParameters := map[string]interface{}{
   178  		"api-version": APIVersion,
   179  	}
   180  
   181  	preparer := autorest.CreatePreparer(
   182  		autorest.AsDelete(),
   183  		autorest.WithBaseURL(client.BaseURI),
   184  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/bandwidthSettings/{bandwidthSettingName}", pathParameters),
   185  		autorest.WithQueryParameters(queryParameters))
   186  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   187  }
   188  
   189  // DeleteSender sends the Delete request. The method will close the
   190  // http.Response Body if it receives an error.
   191  func (client BandwidthSettingsClient) DeleteSender(req *http.Request) (future BandwidthSettingsDeleteFuture, err error) {
   192  	var resp *http.Response
   193  	future.FutureAPI = &azure.Future{}
   194  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   195  	if err != nil {
   196  		return
   197  	}
   198  	var azf azure.Future
   199  	azf, err = azure.NewFutureFromResponse(resp)
   200  	future.FutureAPI = &azf
   201  	future.Result = future.result
   202  	return
   203  }
   204  
   205  // DeleteResponder handles the response to the Delete request. The method always
   206  // closes the http.Response Body.
   207  func (client BandwidthSettingsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   208  	err = autorest.Respond(
   209  		resp,
   210  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   211  		autorest.ByClosing())
   212  	result.Response = resp
   213  	return
   214  }
   215  
   216  // Get returns the properties of the specified bandwidth setting name.
   217  // Parameters:
   218  // bandwidthSettingName - the name of bandwidth setting to be fetched.
   219  // resourceGroupName - the resource group name
   220  // managerName - the manager name
   221  func (client BandwidthSettingsClient) Get(ctx context.Context, bandwidthSettingName string, resourceGroupName string, managerName string) (result BandwidthSetting, err error) {
   222  	if tracing.IsEnabled() {
   223  		ctx = tracing.StartSpan(ctx, fqdn+"/BandwidthSettingsClient.Get")
   224  		defer func() {
   225  			sc := -1
   226  			if result.Response.Response != nil {
   227  				sc = result.Response.Response.StatusCode
   228  			}
   229  			tracing.EndSpan(ctx, sc, err)
   230  		}()
   231  	}
   232  	if err := validation.Validate([]validation.Validation{
   233  		{TargetValue: managerName,
   234  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   235  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   236  		return result, validation.NewError("storsimple.BandwidthSettingsClient", "Get", err.Error())
   237  	}
   238  
   239  	req, err := client.GetPreparer(ctx, bandwidthSettingName, resourceGroupName, managerName)
   240  	if err != nil {
   241  		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "Get", nil, "Failure preparing request")
   242  		return
   243  	}
   244  
   245  	resp, err := client.GetSender(req)
   246  	if err != nil {
   247  		result.Response = autorest.Response{Response: resp}
   248  		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "Get", resp, "Failure sending request")
   249  		return
   250  	}
   251  
   252  	result, err = client.GetResponder(resp)
   253  	if err != nil {
   254  		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "Get", resp, "Failure responding to request")
   255  		return
   256  	}
   257  
   258  	return
   259  }
   260  
   261  // GetPreparer prepares the Get request.
   262  func (client BandwidthSettingsClient) GetPreparer(ctx context.Context, bandwidthSettingName string, resourceGroupName string, managerName string) (*http.Request, error) {
   263  	pathParameters := map[string]interface{}{
   264  		"bandwidthSettingName": bandwidthSettingName,
   265  		"managerName":          managerName,
   266  		"resourceGroupName":    resourceGroupName,
   267  		"subscriptionId":       client.SubscriptionID,
   268  	}
   269  
   270  	const APIVersion = "2017-06-01"
   271  	queryParameters := map[string]interface{}{
   272  		"api-version": APIVersion,
   273  	}
   274  
   275  	preparer := autorest.CreatePreparer(
   276  		autorest.AsGet(),
   277  		autorest.WithBaseURL(client.BaseURI),
   278  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/bandwidthSettings/{bandwidthSettingName}", pathParameters),
   279  		autorest.WithQueryParameters(queryParameters))
   280  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   281  }
   282  
   283  // GetSender sends the Get request. The method will close the
   284  // http.Response Body if it receives an error.
   285  func (client BandwidthSettingsClient) GetSender(req *http.Request) (*http.Response, error) {
   286  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   287  }
   288  
   289  // GetResponder handles the response to the Get request. The method always
   290  // closes the http.Response Body.
   291  func (client BandwidthSettingsClient) GetResponder(resp *http.Response) (result BandwidthSetting, err error) {
   292  	err = autorest.Respond(
   293  		resp,
   294  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   295  		autorest.ByUnmarshallingJSON(&result),
   296  		autorest.ByClosing())
   297  	result.Response = autorest.Response{Response: resp}
   298  	return
   299  }
   300  
   301  // ListByManager retrieves all the bandwidth setting in a manager.
   302  // Parameters:
   303  // resourceGroupName - the resource group name
   304  // managerName - the manager name
   305  func (client BandwidthSettingsClient) ListByManager(ctx context.Context, resourceGroupName string, managerName string) (result BandwidthSettingList, err error) {
   306  	if tracing.IsEnabled() {
   307  		ctx = tracing.StartSpan(ctx, fqdn+"/BandwidthSettingsClient.ListByManager")
   308  		defer func() {
   309  			sc := -1
   310  			if result.Response.Response != nil {
   311  				sc = result.Response.Response.StatusCode
   312  			}
   313  			tracing.EndSpan(ctx, sc, err)
   314  		}()
   315  	}
   316  	if err := validation.Validate([]validation.Validation{
   317  		{TargetValue: managerName,
   318  			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
   319  				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
   320  		return result, validation.NewError("storsimple.BandwidthSettingsClient", "ListByManager", err.Error())
   321  	}
   322  
   323  	req, err := client.ListByManagerPreparer(ctx, resourceGroupName, managerName)
   324  	if err != nil {
   325  		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "ListByManager", nil, "Failure preparing request")
   326  		return
   327  	}
   328  
   329  	resp, err := client.ListByManagerSender(req)
   330  	if err != nil {
   331  		result.Response = autorest.Response{Response: resp}
   332  		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "ListByManager", resp, "Failure sending request")
   333  		return
   334  	}
   335  
   336  	result, err = client.ListByManagerResponder(resp)
   337  	if err != nil {
   338  		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "ListByManager", resp, "Failure responding to request")
   339  		return
   340  	}
   341  
   342  	return
   343  }
   344  
   345  // ListByManagerPreparer prepares the ListByManager request.
   346  func (client BandwidthSettingsClient) ListByManagerPreparer(ctx context.Context, resourceGroupName string, managerName string) (*http.Request, error) {
   347  	pathParameters := map[string]interface{}{
   348  		"managerName":       managerName,
   349  		"resourceGroupName": resourceGroupName,
   350  		"subscriptionId":    client.SubscriptionID,
   351  	}
   352  
   353  	const APIVersion = "2017-06-01"
   354  	queryParameters := map[string]interface{}{
   355  		"api-version": APIVersion,
   356  	}
   357  
   358  	preparer := autorest.CreatePreparer(
   359  		autorest.AsGet(),
   360  		autorest.WithBaseURL(client.BaseURI),
   361  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/bandwidthSettings", pathParameters),
   362  		autorest.WithQueryParameters(queryParameters))
   363  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   364  }
   365  
   366  // ListByManagerSender sends the ListByManager request. The method will close the
   367  // http.Response Body if it receives an error.
   368  func (client BandwidthSettingsClient) ListByManagerSender(req *http.Request) (*http.Response, error) {
   369  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   370  }
   371  
   372  // ListByManagerResponder handles the response to the ListByManager request. The method always
   373  // closes the http.Response Body.
   374  func (client BandwidthSettingsClient) ListByManagerResponder(resp *http.Response) (result BandwidthSettingList, err error) {
   375  	err = autorest.Respond(
   376  		resp,
   377  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   378  		autorest.ByUnmarshallingJSON(&result),
   379  		autorest.ByClosing())
   380  	result.Response = autorest.Response{Response: resp}
   381  	return
   382  }
   383  

View as plain text