1package 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 9import ( 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. 19type HardwareComponentGroupsClient struct { 20 BaseClient 21} 22 23// NewHardwareComponentGroupsClient creates an instance of the HardwareComponentGroupsClient client. 24func 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). 31func 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 42func (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", nil, "Failure sending request") 71 return 72 } 73 74 return 75} 76 77// ChangeControllerPowerStatePreparer prepares the ChangeControllerPowerState request. 78func (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. 104func (client HardwareComponentGroupsClient) ChangeControllerPowerStateSender(req *http.Request) (future HardwareComponentGroupsChangeControllerPowerStateFuture, err error) { 105 var resp *http.Response 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// ChangeControllerPowerStateResponder handles the response to the ChangeControllerPowerState request. The method always 118// closes the http.Response Body. 119func (client HardwareComponentGroupsClient) ChangeControllerPowerStateResponder(resp *http.Response) (result autorest.Response, err error) { 120 err = autorest.Respond( 121 resp, 122 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 123 autorest.ByClosing()) 124 result.Response = resp 125 return 126} 127 128// ListByDevice lists the hardware component groups at device-level. 129// Parameters: 130// deviceName - the device name 131// resourceGroupName - the resource group name 132// managerName - the manager name 133func (client HardwareComponentGroupsClient) ListByDevice(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (result HardwareComponentGroupList, err error) { 134 if tracing.IsEnabled() { 135 ctx = tracing.StartSpan(ctx, fqdn+"/HardwareComponentGroupsClient.ListByDevice") 136 defer func() { 137 sc := -1 138 if result.Response.Response != nil { 139 sc = result.Response.Response.StatusCode 140 } 141 tracing.EndSpan(ctx, sc, err) 142 }() 143 } 144 if err := validation.Validate([]validation.Validation{ 145 {TargetValue: managerName, 146 Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 147 {Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil { 148 return result, validation.NewError("storsimple.HardwareComponentGroupsClient", "ListByDevice", err.Error()) 149 } 150 151 req, err := client.ListByDevicePreparer(ctx, deviceName, resourceGroupName, managerName) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", nil, "Failure preparing request") 154 return 155 } 156 157 resp, err := client.ListByDeviceSender(req) 158 if err != nil { 159 result.Response = autorest.Response{Response: resp} 160 err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", resp, "Failure sending request") 161 return 162 } 163 164 result, err = client.ListByDeviceResponder(resp) 165 if err != nil { 166 err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", resp, "Failure responding to request") 167 return 168 } 169 170 return 171} 172 173// ListByDevicePreparer prepares the ListByDevice request. 174func (client HardwareComponentGroupsClient) ListByDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (*http.Request, error) { 175 pathParameters := map[string]interface{}{ 176 "deviceName": deviceName, 177 "managerName": managerName, 178 "resourceGroupName": resourceGroupName, 179 "subscriptionId": client.SubscriptionID, 180 } 181 182 const APIVersion = "2017-06-01" 183 queryParameters := map[string]interface{}{ 184 "api-version": APIVersion, 185 } 186 187 preparer := autorest.CreatePreparer( 188 autorest.AsGet(), 189 autorest.WithBaseURL(client.BaseURI), 190 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/hardwareComponentGroups", pathParameters), 191 autorest.WithQueryParameters(queryParameters)) 192 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 193} 194 195// ListByDeviceSender sends the ListByDevice request. The method will close the 196// http.Response Body if it receives an error. 197func (client HardwareComponentGroupsClient) ListByDeviceSender(req *http.Request) (*http.Response, error) { 198 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 199} 200 201// ListByDeviceResponder handles the response to the ListByDevice request. The method always 202// closes the http.Response Body. 203func (client HardwareComponentGroupsClient) ListByDeviceResponder(resp *http.Response) (result HardwareComponentGroupList, err error) { 204 err = autorest.Respond( 205 resp, 206 azure.WithErrorUnlessStatusCode(http.StatusOK), 207 autorest.ByUnmarshallingJSON(&result), 208 autorest.ByClosing()) 209 result.Response = autorest.Response{Response: resp} 210 return 211} 212