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	var resp *http.Response
104	resp, err = autorest.SendWithSender(client, req,
105		azure.DoRetryWithRegistration(client.Client))
106	if err != nil {
107		return
108	}
109	err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent))
110	if err != nil {
111		return
112	}
113	future.Future, err = azure.NewFutureFromResponse(resp)
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		client.ByInspecting(),
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
134func (client HardwareComponentGroupsClient) ListByDevice(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (result HardwareComponentGroupList, err error) {
135	if err := validation.Validate([]validation.Validation{
136		{TargetValue: managerName,
137			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
138				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
139		return result, validation.NewError("storsimple.HardwareComponentGroupsClient", "ListByDevice", err.Error())
140	}
141
142	req, err := client.ListByDevicePreparer(ctx, deviceName, resourceGroupName, managerName)
143	if err != nil {
144		err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", nil, "Failure preparing request")
145		return
146	}
147
148	resp, err := client.ListByDeviceSender(req)
149	if err != nil {
150		result.Response = autorest.Response{Response: resp}
151		err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", resp, "Failure sending request")
152		return
153	}
154
155	result, err = client.ListByDeviceResponder(resp)
156	if err != nil {
157		err = autorest.NewErrorWithError(err, "storsimple.HardwareComponentGroupsClient", "ListByDevice", resp, "Failure responding to request")
158	}
159
160	return
161}
162
163// ListByDevicePreparer prepares the ListByDevice request.
164func (client HardwareComponentGroupsClient) ListByDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (*http.Request, error) {
165	pathParameters := map[string]interface{}{
166		"deviceName":        deviceName,
167		"managerName":       managerName,
168		"resourceGroupName": resourceGroupName,
169		"subscriptionId":    client.SubscriptionID,
170	}
171
172	const APIVersion = "2017-06-01"
173	queryParameters := map[string]interface{}{
174		"api-version": APIVersion,
175	}
176
177	preparer := autorest.CreatePreparer(
178		autorest.AsGet(),
179		autorest.WithBaseURL(client.BaseURI),
180		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/hardwareComponentGroups", pathParameters),
181		autorest.WithQueryParameters(queryParameters))
182	return preparer.Prepare((&http.Request{}).WithContext(ctx))
183}
184
185// ListByDeviceSender sends the ListByDevice request. The method will close the
186// http.Response Body if it receives an error.
187func (client HardwareComponentGroupsClient) ListByDeviceSender(req *http.Request) (*http.Response, error) {
188	return autorest.SendWithSender(client, req,
189		azure.DoRetryWithRegistration(client.Client))
190}
191
192// ListByDeviceResponder handles the response to the ListByDevice request. The method always
193// closes the http.Response Body.
194func (client HardwareComponentGroupsClient) ListByDeviceResponder(resp *http.Response) (result HardwareComponentGroupList, err error) {
195	err = autorest.Respond(
196		resp,
197		client.ByInspecting(),
198		azure.WithErrorUnlessStatusCode(http.StatusOK),
199		autorest.ByUnmarshallingJSON(&result),
200		autorest.ByClosing())
201	result.Response = autorest.Response{Response: resp}
202	return
203}
204