1package storsimple 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "net/http" 26) 27 28// HardwareComponentGroupsClient is the client for the HardwareComponentGroups methods of the Storsimple service. 29type HardwareComponentGroupsClient struct { 30 BaseClient 31} 32 33// NewHardwareComponentGroupsClient creates an instance of the HardwareComponentGroupsClient client. 34func NewHardwareComponentGroupsClient(subscriptionID string) HardwareComponentGroupsClient { 35 return NewHardwareComponentGroupsClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewHardwareComponentGroupsClientWithBaseURI creates an instance of the HardwareComponentGroupsClient client. 39func NewHardwareComponentGroupsClientWithBaseURI(baseURI string, subscriptionID string) HardwareComponentGroupsClient { 40 return HardwareComponentGroupsClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// ChangeControllerPowerState changes the power state of the controller. 44// Parameters: 45// deviceName - the device name 46// hardwareComponentGroupName - the hardware component group name. 47// parameters - the controller power state change request. 48// resourceGroupName - the resource group name 49// managerName - the manager name 50func (client HardwareComponentGroupsClient) ChangeControllerPowerState(ctx context.Context, deviceName string, hardwareComponentGroupName string, parameters ControllerPowerStateChangeRequest, resourceGroupName string, managerName string) (result HardwareComponentGroupsChangeControllerPowerStateFuture, err error) { 51 if err := validation.Validate([]validation.Validation{ 52 {TargetValue: parameters, 53 Constraints: []validation.Constraint{{Target: "parameters.ControllerPowerStateChangeRequestProperties", Name: validation.Null, Rule: true, Chain: nil}}}, 54 {TargetValue: managerName, 55 Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 56 {Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil { 57 return result, validation.NewError("storsimple.HardwareComponentGroupsClient", "ChangeControllerPowerState", err.Error()) 58 } 59 60 req, err := client.ChangeControllerPowerStatePreparer(ctx, deviceName, hardwareComponentGroupName, parameters, resourceGroupName, managerName) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ChangeControllerPowerState", nil, "Failure preparing request") 63 return 64 } 65 66 result, err = client.ChangeControllerPowerStateSender(req) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ChangeControllerPowerState", result.Response(), "Failure sending request") 69 return 70 } 71 72 return 73} 74 75// ChangeControllerPowerStatePreparer prepares the ChangeControllerPowerState request. 76func (client HardwareComponentGroupsClient) ChangeControllerPowerStatePreparer(ctx context.Context, deviceName string, hardwareComponentGroupName string, parameters ControllerPowerStateChangeRequest, resourceGroupName string, managerName string) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "deviceName": deviceName, 79 "hardwareComponentGroupName": hardwareComponentGroupName, 80 "managerName": managerName, 81 "resourceGroupName": resourceGroupName, 82 "subscriptionId": client.SubscriptionID, 83 } 84 85 const APIVersion = "2017-06-01" 86 queryParameters := map[string]interface{}{ 87 "api-version": APIVersion, 88 } 89 90 preparer := autorest.CreatePreparer( 91 autorest.AsContentType("application/json; charset=utf-8"), 92 autorest.AsPost(), 93 autorest.WithBaseURL(client.BaseURI), 94 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/hardwareComponentGroups/{hardwareComponentGroupName}/changeControllerPowerState", pathParameters), 95 autorest.WithJSON(parameters), 96 autorest.WithQueryParameters(queryParameters)) 97 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 98} 99 100// ChangeControllerPowerStateSender sends the ChangeControllerPowerState request. The method will close the 101// http.Response Body if it receives an error. 102func (client HardwareComponentGroupsClient) ChangeControllerPowerStateSender(req *http.Request) (future HardwareComponentGroupsChangeControllerPowerStateFuture, err error) { 103 sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client)) 104 future.Future = azure.NewFuture(req) 105 future.req = req 106 _, err = future.Done(sender) 107 if err != nil { 108 return 109 } 110 err = autorest.Respond(future.Response(), 111 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent)) 112 return 113} 114 115// ChangeControllerPowerStateResponder handles the response to the ChangeControllerPowerState request. The method always 116// closes the http.Response Body. 117func (client HardwareComponentGroupsClient) ChangeControllerPowerStateResponder(resp *http.Response) (result autorest.Response, err error) { 118 err = autorest.Respond( 119 resp, 120 client.ByInspecting(), 121 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 122 autorest.ByClosing()) 123 result.Response = resp 124 return 125} 126 127// ListByDevice lists the hardware component groups at device-level. 128// Parameters: 129// deviceName - the device name 130// resourceGroupName - the resource group name 131// managerName - the manager name 132func (client HardwareComponentGroupsClient) ListByDevice(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (result HardwareComponentGroupList, err error) { 133 if err := validation.Validate([]validation.Validation{ 134 {TargetValue: managerName, 135 Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil}, 136 {Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil { 137 return result, validation.NewError("storsimple.HardwareComponentGroupsClient", "ListByDevice", err.Error()) 138 } 139 140 req, err := client.ListByDevicePreparer(ctx, deviceName, resourceGroupName, managerName) 141 if err != nil { 142 err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", nil, "Failure preparing request") 143 return 144 } 145 146 resp, err := client.ListByDeviceSender(req) 147 if err != nil { 148 result.Response = autorest.Response{Response: resp} 149 err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", resp, "Failure sending request") 150 return 151 } 152 153 result, err = client.ListByDeviceResponder(resp) 154 if err != nil { 155 err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", resp, "Failure responding to request") 156 } 157 158 return 159} 160 161// ListByDevicePreparer prepares the ListByDevice request. 162func (client HardwareComponentGroupsClient) ListByDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (*http.Request, error) { 163 pathParameters := map[string]interface{}{ 164 "deviceName": deviceName, 165 "managerName": managerName, 166 "resourceGroupName": resourceGroupName, 167 "subscriptionId": client.SubscriptionID, 168 } 169 170 const APIVersion = "2017-06-01" 171 queryParameters := map[string]interface{}{ 172 "api-version": APIVersion, 173 } 174 175 preparer := autorest.CreatePreparer( 176 autorest.AsGet(), 177 autorest.WithBaseURL(client.BaseURI), 178 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/hardwareComponentGroups", pathParameters), 179 autorest.WithQueryParameters(queryParameters)) 180 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 181} 182 183// ListByDeviceSender sends the ListByDevice request. The method will close the 184// http.Response Body if it receives an error. 185func (client HardwareComponentGroupsClient) ListByDeviceSender(req *http.Request) (*http.Response, error) { 186 return autorest.SendWithSender(client, req, 187 azure.DoRetryWithRegistration(client.Client)) 188} 189 190// ListByDeviceResponder handles the response to the ListByDevice request. The method always 191// closes the http.Response Body. 192func (client HardwareComponentGroupsClient) ListByDeviceResponder(resp *http.Response) (result HardwareComponentGroupList, err error) { 193 err = autorest.Respond( 194 resp, 195 client.ByInspecting(), 196 azure.WithErrorUnlessStatusCode(http.StatusOK), 197 autorest.ByUnmarshallingJSON(&result), 198 autorest.ByClosing()) 199 result.Response = autorest.Response{Response: resp} 200 return 201} 202