...

Source file src/github.com/Azure/azure-sdk-for-go/services/storsimple8000series/mgmt/2017-06-01/storsimple/hardwarecomponentgroups.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  // HardwareComponentGroupsClient is the client for the HardwareComponentGroups methods of the Storsimple service.
    19  type HardwareComponentGroupsClient struct {
    20  	BaseClient
    21  }
    22  
    23  // NewHardwareComponentGroupsClient creates an instance of the HardwareComponentGroupsClient client.
    24  func NewHardwareComponentGroupsClient(subscriptionID string) HardwareComponentGroupsClient {
    25  	return NewHardwareComponentGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewHardwareComponentGroupsClientWithBaseURI creates an instance of the HardwareComponentGroupsClient client using a
    29  // custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds,
    30  // Azure stack).
    31  func NewHardwareComponentGroupsClientWithBaseURI(baseURI string, subscriptionID string) HardwareComponentGroupsClient {
    32  	return HardwareComponentGroupsClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // ChangeControllerPowerState changes the power state of the controller.
    36  // Parameters:
    37  // deviceName - the device name
    38  // hardwareComponentGroupName - the hardware component group name.
    39  // parameters - the controller power state change request.
    40  // resourceGroupName - the resource group name
    41  // managerName - the manager name
    42  func (client HardwareComponentGroupsClient) ChangeControllerPowerState(ctx context.Context, deviceName string, hardwareComponentGroupName string, parameters ControllerPowerStateChangeRequest, resourceGroupName string, managerName string) (result HardwareComponentGroupsChangeControllerPowerStateFuture, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/HardwareComponentGroupsClient.ChangeControllerPowerState")
    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.ControllerPowerStateChangeRequestProperties", 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.HardwareComponentGroupsClient", "ChangeControllerPowerState", err.Error())
    60  	}
    61  
    62  	req, err := client.ChangeControllerPowerStatePreparer(ctx, deviceName, hardwareComponentGroupName, parameters, resourceGroupName, managerName)
    63  	if err != nil {
    64  		err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ChangeControllerPowerState", nil, "Failure preparing request")
    65  		return
    66  	}
    67  
    68  	result, err = client.ChangeControllerPowerStateSender(req)
    69  	if err != nil {
    70  		err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ChangeControllerPowerState", result.Response(), "Failure sending request")
    71  		return
    72  	}
    73  
    74  	return
    75  }
    76  
    77  // ChangeControllerPowerStatePreparer prepares the ChangeControllerPowerState request.
    78  func (client HardwareComponentGroupsClient) ChangeControllerPowerStatePreparer(ctx context.Context, deviceName string, hardwareComponentGroupName string, parameters ControllerPowerStateChangeRequest, resourceGroupName string, managerName string) (*http.Request, error) {
    79  	pathParameters := map[string]interface{}{
    80  		"deviceName":                 deviceName,
    81  		"hardwareComponentGroupName": hardwareComponentGroupName,
    82  		"managerName":                managerName,
    83  		"resourceGroupName":          resourceGroupName,
    84  		"subscriptionId":             client.SubscriptionID,
    85  	}
    86  
    87  	const APIVersion = "2017-06-01"
    88  	queryParameters := map[string]interface{}{
    89  		"api-version": APIVersion,
    90  	}
    91  
    92  	preparer := autorest.CreatePreparer(
    93  		autorest.AsContentType("application/json; charset=utf-8"),
    94  		autorest.AsPost(),
    95  		autorest.WithBaseURL(client.BaseURI),
    96  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/hardwareComponentGroups/{hardwareComponentGroupName}/changeControllerPowerState", pathParameters),
    97  		autorest.WithJSON(parameters),
    98  		autorest.WithQueryParameters(queryParameters))
    99  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   100  }
   101  
   102  // ChangeControllerPowerStateSender sends the ChangeControllerPowerState request. The method will close the
   103  // http.Response Body if it receives an error.
   104  func (client HardwareComponentGroupsClient) ChangeControllerPowerStateSender(req *http.Request) (future HardwareComponentGroupsChangeControllerPowerStateFuture, err error) {
   105  	var resp *http.Response
   106  	future.FutureAPI = &azure.Future{}
   107  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   108  	if err != nil {
   109  		return
   110  	}
   111  	var azf azure.Future
   112  	azf, err = azure.NewFutureFromResponse(resp)
   113  	future.FutureAPI = &azf
   114  	future.Result = future.result
   115  	return
   116  }
   117  
   118  // ChangeControllerPowerStateResponder handles the response to the ChangeControllerPowerState request. The method always
   119  // closes the http.Response Body.
   120  func (client HardwareComponentGroupsClient) ChangeControllerPowerStateResponder(resp *http.Response) (result autorest.Response, err error) {
   121  	err = autorest.Respond(
   122  		resp,
   123  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   124  		autorest.ByClosing())
   125  	result.Response = resp
   126  	return
   127  }
   128  
   129  // ListByDevice lists the hardware component groups at device-level.
   130  // Parameters:
   131  // deviceName - the device name
   132  // resourceGroupName - the resource group name
   133  // managerName - the manager name
   134  func (client HardwareComponentGroupsClient) ListByDevice(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (result HardwareComponentGroupList, err error) {
   135  	if tracing.IsEnabled() {
   136  		ctx = tracing.StartSpan(ctx, fqdn+"/HardwareComponentGroupsClient.ListByDevice")
   137  		defer func() {
   138  			sc := -1
   139  			if result.Response.Response != nil {
   140  				sc = result.Response.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.HardwareComponentGroupsClient", "ListByDevice", err.Error())
   150  	}
   151  
   152  	req, err := client.ListByDevicePreparer(ctx, deviceName, resourceGroupName, managerName)
   153  	if err != nil {
   154  		err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", nil, "Failure preparing request")
   155  		return
   156  	}
   157  
   158  	resp, err := client.ListByDeviceSender(req)
   159  	if err != nil {
   160  		result.Response = autorest.Response{Response: resp}
   161  		err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", resp, "Failure sending request")
   162  		return
   163  	}
   164  
   165  	result, err = client.ListByDeviceResponder(resp)
   166  	if err != nil {
   167  		err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", resp, "Failure responding to request")
   168  		return
   169  	}
   170  
   171  	return
   172  }
   173  
   174  // ListByDevicePreparer prepares the ListByDevice request.
   175  func (client HardwareComponentGroupsClient) ListByDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (*http.Request, error) {
   176  	pathParameters := map[string]interface{}{
   177  		"deviceName":        deviceName,
   178  		"managerName":       managerName,
   179  		"resourceGroupName": resourceGroupName,
   180  		"subscriptionId":    client.SubscriptionID,
   181  	}
   182  
   183  	const APIVersion = "2017-06-01"
   184  	queryParameters := map[string]interface{}{
   185  		"api-version": APIVersion,
   186  	}
   187  
   188  	preparer := autorest.CreatePreparer(
   189  		autorest.AsGet(),
   190  		autorest.WithBaseURL(client.BaseURI),
   191  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/hardwareComponentGroups", pathParameters),
   192  		autorest.WithQueryParameters(queryParameters))
   193  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   194  }
   195  
   196  // ListByDeviceSender sends the ListByDevice request. The method will close the
   197  // http.Response Body if it receives an error.
   198  func (client HardwareComponentGroupsClient) ListByDeviceSender(req *http.Request) (*http.Response, error) {
   199  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   200  }
   201  
   202  // ListByDeviceResponder handles the response to the ListByDevice request. The method always
   203  // closes the http.Response Body.
   204  func (client HardwareComponentGroupsClient) ListByDeviceResponder(resp *http.Response) (result HardwareComponentGroupList, err error) {
   205  	err = autorest.Respond(
   206  		resp,
   207  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   208  		autorest.ByUnmarshallingJSON(&result),
   209  		autorest.ByClosing())
   210  	result.Response = autorest.Response{Response: resp}
   211  	return
   212  }
   213  

View as plain text