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