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// BandwidthSettingsClient is the client for the BandwidthSettings methods of the Storsimple service.
19type BandwidthSettingsClient struct {
20	BaseClient
21}
22
23// NewBandwidthSettingsClient creates an instance of the BandwidthSettingsClient client.
24func NewBandwidthSettingsClient(subscriptionID string) BandwidthSettingsClient {
25	return NewBandwidthSettingsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewBandwidthSettingsClientWithBaseURI creates an instance of the BandwidthSettingsClient client using a custom
29// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
30// stack).
31func NewBandwidthSettingsClientWithBaseURI(baseURI string, subscriptionID string) BandwidthSettingsClient {
32	return BandwidthSettingsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// CreateOrUpdate creates or updates the bandwidth setting
36// Parameters:
37// bandwidthSettingName - the bandwidth setting name.
38// parameters - the bandwidth setting to be added or updated.
39// resourceGroupName - the resource group name
40// managerName - the manager name
41func (client BandwidthSettingsClient) CreateOrUpdate(ctx context.Context, bandwidthSettingName string, parameters BandwidthSetting, resourceGroupName string, managerName string) (result BandwidthSettingsCreateOrUpdateFuture, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/BandwidthSettingsClient.CreateOrUpdate")
44		defer func() {
45			sc := -1
46			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
47				sc = result.FutureAPI.Response().StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: parameters,
54			Constraints: []validation.Constraint{{Target: "parameters.BandwidthRateSettingProperties", Name: validation.Null, Rule: true,
55				Chain: []validation.Constraint{{Target: "parameters.BandwidthRateSettingProperties.Schedules", 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.BandwidthSettingsClient", "CreateOrUpdate", err.Error())
60	}
61
62	req, err := client.CreateOrUpdatePreparer(ctx, bandwidthSettingName, parameters, resourceGroupName, managerName)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "CreateOrUpdate", nil, "Failure preparing request")
65		return
66	}
67
68	result, err = client.CreateOrUpdateSender(req)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "CreateOrUpdate", nil, "Failure sending request")
71		return
72	}
73
74	return
75}
76
77// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
78func (client BandwidthSettingsClient) CreateOrUpdatePreparer(ctx context.Context, bandwidthSettingName string, parameters BandwidthSetting, resourceGroupName string, managerName string) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"bandwidthSettingName": bandwidthSettingName,
81		"managerName":          managerName,
82		"resourceGroupName":    resourceGroupName,
83		"subscriptionId":       client.SubscriptionID,
84	}
85
86	const APIVersion = "2017-06-01"
87	queryParameters := map[string]interface{}{
88		"api-version": APIVersion,
89	}
90
91	preparer := autorest.CreatePreparer(
92		autorest.AsContentType("application/json; charset=utf-8"),
93		autorest.AsPut(),
94		autorest.WithBaseURL(client.BaseURI),
95		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/bandwidthSettings/{bandwidthSettingName}", pathParameters),
96		autorest.WithJSON(parameters),
97		autorest.WithQueryParameters(queryParameters))
98	return preparer.Prepare((&http.Request{}).WithContext(ctx))
99}
100
101// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
102// http.Response Body if it receives an error.
103func (client BandwidthSettingsClient) CreateOrUpdateSender(req *http.Request) (future BandwidthSettingsCreateOrUpdateFuture, err error) {
104	var resp *http.Response
105	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
106	if err != nil {
107		return
108	}
109	var azf azure.Future
110	azf, err = azure.NewFutureFromResponse(resp)
111	future.FutureAPI = &azf
112	future.Result = future.result
113	return
114}
115
116// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
117// closes the http.Response Body.
118func (client BandwidthSettingsClient) CreateOrUpdateResponder(resp *http.Response) (result BandwidthSetting, err error) {
119	err = autorest.Respond(
120		resp,
121		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
122		autorest.ByUnmarshallingJSON(&result),
123		autorest.ByClosing())
124	result.Response = autorest.Response{Response: resp}
125	return
126}
127
128// Delete deletes the bandwidth setting
129// Parameters:
130// bandwidthSettingName - the name of the bandwidth setting.
131// resourceGroupName - the resource group name
132// managerName - the manager name
133func (client BandwidthSettingsClient) Delete(ctx context.Context, bandwidthSettingName string, resourceGroupName string, managerName string) (result BandwidthSettingsDeleteFuture, err error) {
134	if tracing.IsEnabled() {
135		ctx = tracing.StartSpan(ctx, fqdn+"/BandwidthSettingsClient.Delete")
136		defer func() {
137			sc := -1
138			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
139				sc = result.FutureAPI.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.BandwidthSettingsClient", "Delete", err.Error())
149	}
150
151	req, err := client.DeletePreparer(ctx, bandwidthSettingName, resourceGroupName, managerName)
152	if err != nil {
153		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "Delete", nil, "Failure preparing request")
154		return
155	}
156
157	result, err = client.DeleteSender(req)
158	if err != nil {
159		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "Delete", nil, "Failure sending request")
160		return
161	}
162
163	return
164}
165
166// DeletePreparer prepares the Delete request.
167func (client BandwidthSettingsClient) DeletePreparer(ctx context.Context, bandwidthSettingName string, resourceGroupName string, managerName string) (*http.Request, error) {
168	pathParameters := map[string]interface{}{
169		"bandwidthSettingName": bandwidthSettingName,
170		"managerName":          managerName,
171		"resourceGroupName":    resourceGroupName,
172		"subscriptionId":       client.SubscriptionID,
173	}
174
175	const APIVersion = "2017-06-01"
176	queryParameters := map[string]interface{}{
177		"api-version": APIVersion,
178	}
179
180	preparer := autorest.CreatePreparer(
181		autorest.AsDelete(),
182		autorest.WithBaseURL(client.BaseURI),
183		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/bandwidthSettings/{bandwidthSettingName}", pathParameters),
184		autorest.WithQueryParameters(queryParameters))
185	return preparer.Prepare((&http.Request{}).WithContext(ctx))
186}
187
188// DeleteSender sends the Delete request. The method will close the
189// http.Response Body if it receives an error.
190func (client BandwidthSettingsClient) DeleteSender(req *http.Request) (future BandwidthSettingsDeleteFuture, err error) {
191	var resp *http.Response
192	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
193	if err != nil {
194		return
195	}
196	var azf azure.Future
197	azf, err = azure.NewFutureFromResponse(resp)
198	future.FutureAPI = &azf
199	future.Result = future.result
200	return
201}
202
203// DeleteResponder handles the response to the Delete request. The method always
204// closes the http.Response Body.
205func (client BandwidthSettingsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
206	err = autorest.Respond(
207		resp,
208		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
209		autorest.ByClosing())
210	result.Response = resp
211	return
212}
213
214// Get returns the properties of the specified bandwidth setting name.
215// Parameters:
216// bandwidthSettingName - the name of bandwidth setting to be fetched.
217// resourceGroupName - the resource group name
218// managerName - the manager name
219func (client BandwidthSettingsClient) Get(ctx context.Context, bandwidthSettingName string, resourceGroupName string, managerName string) (result BandwidthSetting, err error) {
220	if tracing.IsEnabled() {
221		ctx = tracing.StartSpan(ctx, fqdn+"/BandwidthSettingsClient.Get")
222		defer func() {
223			sc := -1
224			if result.Response.Response != nil {
225				sc = result.Response.Response.StatusCode
226			}
227			tracing.EndSpan(ctx, sc, err)
228		}()
229	}
230	if err := validation.Validate([]validation.Validation{
231		{TargetValue: managerName,
232			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
233				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
234		return result, validation.NewError("storsimple.BandwidthSettingsClient", "Get", err.Error())
235	}
236
237	req, err := client.GetPreparer(ctx, bandwidthSettingName, resourceGroupName, managerName)
238	if err != nil {
239		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "Get", nil, "Failure preparing request")
240		return
241	}
242
243	resp, err := client.GetSender(req)
244	if err != nil {
245		result.Response = autorest.Response{Response: resp}
246		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "Get", resp, "Failure sending request")
247		return
248	}
249
250	result, err = client.GetResponder(resp)
251	if err != nil {
252		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "Get", resp, "Failure responding to request")
253		return
254	}
255
256	return
257}
258
259// GetPreparer prepares the Get request.
260func (client BandwidthSettingsClient) GetPreparer(ctx context.Context, bandwidthSettingName string, resourceGroupName string, managerName string) (*http.Request, error) {
261	pathParameters := map[string]interface{}{
262		"bandwidthSettingName": bandwidthSettingName,
263		"managerName":          managerName,
264		"resourceGroupName":    resourceGroupName,
265		"subscriptionId":       client.SubscriptionID,
266	}
267
268	const APIVersion = "2017-06-01"
269	queryParameters := map[string]interface{}{
270		"api-version": APIVersion,
271	}
272
273	preparer := autorest.CreatePreparer(
274		autorest.AsGet(),
275		autorest.WithBaseURL(client.BaseURI),
276		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/bandwidthSettings/{bandwidthSettingName}", pathParameters),
277		autorest.WithQueryParameters(queryParameters))
278	return preparer.Prepare((&http.Request{}).WithContext(ctx))
279}
280
281// GetSender sends the Get request. The method will close the
282// http.Response Body if it receives an error.
283func (client BandwidthSettingsClient) GetSender(req *http.Request) (*http.Response, error) {
284	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
285}
286
287// GetResponder handles the response to the Get request. The method always
288// closes the http.Response Body.
289func (client BandwidthSettingsClient) GetResponder(resp *http.Response) (result BandwidthSetting, err error) {
290	err = autorest.Respond(
291		resp,
292		azure.WithErrorUnlessStatusCode(http.StatusOK),
293		autorest.ByUnmarshallingJSON(&result),
294		autorest.ByClosing())
295	result.Response = autorest.Response{Response: resp}
296	return
297}
298
299// ListByManager retrieves all the bandwidth setting in a manager.
300// Parameters:
301// resourceGroupName - the resource group name
302// managerName - the manager name
303func (client BandwidthSettingsClient) ListByManager(ctx context.Context, resourceGroupName string, managerName string) (result BandwidthSettingList, err error) {
304	if tracing.IsEnabled() {
305		ctx = tracing.StartSpan(ctx, fqdn+"/BandwidthSettingsClient.ListByManager")
306		defer func() {
307			sc := -1
308			if result.Response.Response != nil {
309				sc = result.Response.Response.StatusCode
310			}
311			tracing.EndSpan(ctx, sc, err)
312		}()
313	}
314	if err := validation.Validate([]validation.Validation{
315		{TargetValue: managerName,
316			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
317				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
318		return result, validation.NewError("storsimple.BandwidthSettingsClient", "ListByManager", err.Error())
319	}
320
321	req, err := client.ListByManagerPreparer(ctx, resourceGroupName, managerName)
322	if err != nil {
323		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "ListByManager", nil, "Failure preparing request")
324		return
325	}
326
327	resp, err := client.ListByManagerSender(req)
328	if err != nil {
329		result.Response = autorest.Response{Response: resp}
330		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "ListByManager", resp, "Failure sending request")
331		return
332	}
333
334	result, err = client.ListByManagerResponder(resp)
335	if err != nil {
336		err = autorest.NewErrorWithError(err, "storsimple.BandwidthSettingsClient", "ListByManager", resp, "Failure responding to request")
337		return
338	}
339
340	return
341}
342
343// ListByManagerPreparer prepares the ListByManager request.
344func (client BandwidthSettingsClient) ListByManagerPreparer(ctx context.Context, resourceGroupName string, managerName string) (*http.Request, error) {
345	pathParameters := map[string]interface{}{
346		"managerName":       managerName,
347		"resourceGroupName": resourceGroupName,
348		"subscriptionId":    client.SubscriptionID,
349	}
350
351	const APIVersion = "2017-06-01"
352	queryParameters := map[string]interface{}{
353		"api-version": APIVersion,
354	}
355
356	preparer := autorest.CreatePreparer(
357		autorest.AsGet(),
358		autorest.WithBaseURL(client.BaseURI),
359		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/bandwidthSettings", pathParameters),
360		autorest.WithQueryParameters(queryParameters))
361	return preparer.Prepare((&http.Request{}).WithContext(ctx))
362}
363
364// ListByManagerSender sends the ListByManager request. The method will close the
365// http.Response Body if it receives an error.
366func (client BandwidthSettingsClient) ListByManagerSender(req *http.Request) (*http.Response, error) {
367	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
368}
369
370// ListByManagerResponder handles the response to the ListByManager request. The method always
371// closes the http.Response Body.
372func (client BandwidthSettingsClient) ListByManagerResponder(resp *http.Response) (result BandwidthSettingList, err error) {
373	err = autorest.Respond(
374		resp,
375		azure.WithErrorUnlessStatusCode(http.StatusOK),
376		autorest.ByUnmarshallingJSON(&result),
377		autorest.ByClosing())
378	result.Response = autorest.Response{Response: resp}
379	return
380}
381