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