1package databoxedge 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/tracing" 14 "net/http" 15) 16 17// AddonsClient is the client for the Addons methods of the Databoxedge service. 18type AddonsClient struct { 19 BaseClient 20} 21 22// NewAddonsClient creates an instance of the AddonsClient client. 23func NewAddonsClient(subscriptionID string) AddonsClient { 24 return NewAddonsClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewAddonsClientWithBaseURI creates an instance of the AddonsClient client using a custom endpoint. Use this when 28// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 29func NewAddonsClientWithBaseURI(baseURI string, subscriptionID string) AddonsClient { 30 return AddonsClient{NewWithBaseURI(baseURI, subscriptionID)} 31} 32 33// CreateOrUpdate create or update a addon. 34// Parameters: 35// deviceName - the device name. 36// roleName - the role name. 37// addonName - the addon name. 38// addon - the addon properties. 39// resourceGroupName - the resource group name. 40func (client AddonsClient) CreateOrUpdate(ctx context.Context, deviceName string, roleName string, addonName string, addon BasicAddon, resourceGroupName string) (result AddonsCreateOrUpdateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/AddonsClient.CreateOrUpdate") 43 defer func() { 44 sc := -1 45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 46 sc = result.FutureAPI.Response().StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 req, err := client.CreateOrUpdatePreparer(ctx, deviceName, roleName, addonName, addon, resourceGroupName) 52 if err != nil { 53 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "CreateOrUpdate", nil, "Failure preparing request") 54 return 55 } 56 57 result, err = client.CreateOrUpdateSender(req) 58 if err != nil { 59 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "CreateOrUpdate", nil, "Failure sending request") 60 return 61 } 62 63 return 64} 65 66// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 67func (client AddonsClient) CreateOrUpdatePreparer(ctx context.Context, deviceName string, roleName string, addonName string, addon BasicAddon, resourceGroupName string) (*http.Request, error) { 68 pathParameters := map[string]interface{}{ 69 "addonName": autorest.Encode("path", addonName), 70 "deviceName": autorest.Encode("path", deviceName), 71 "resourceGroupName": autorest.Encode("path", resourceGroupName), 72 "roleName": autorest.Encode("path", roleName), 73 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 74 } 75 76 const APIVersion = "2020-12-01" 77 queryParameters := map[string]interface{}{ 78 "api-version": APIVersion, 79 } 80 81 preparer := autorest.CreatePreparer( 82 autorest.AsContentType("application/json; charset=utf-8"), 83 autorest.AsPut(), 84 autorest.WithBaseURL(client.BaseURI), 85 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/roles/{roleName}/addons/{addonName}", pathParameters), 86 autorest.WithJSON(addon), 87 autorest.WithQueryParameters(queryParameters)) 88 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 89} 90 91// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 92// http.Response Body if it receives an error. 93func (client AddonsClient) CreateOrUpdateSender(req *http.Request) (future AddonsCreateOrUpdateFuture, err error) { 94 var resp *http.Response 95 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 96 if err != nil { 97 return 98 } 99 var azf azure.Future 100 azf, err = azure.NewFutureFromResponse(resp) 101 future.FutureAPI = &azf 102 future.Result = future.result 103 return 104} 105 106// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 107// closes the http.Response Body. 108func (client AddonsClient) CreateOrUpdateResponder(resp *http.Response) (result AddonModel, err error) { 109 err = autorest.Respond( 110 resp, 111 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 112 autorest.ByUnmarshallingJSON(&result), 113 autorest.ByClosing()) 114 result.Response = autorest.Response{Response: resp} 115 return 116} 117 118// Delete deletes the addon on the device. 119// Parameters: 120// deviceName - the device name. 121// roleName - the role name. 122// addonName - the addon name. 123// resourceGroupName - the resource group name. 124func (client AddonsClient) Delete(ctx context.Context, deviceName string, roleName string, addonName string, resourceGroupName string) (result AddonsDeleteFuture, err error) { 125 if tracing.IsEnabled() { 126 ctx = tracing.StartSpan(ctx, fqdn+"/AddonsClient.Delete") 127 defer func() { 128 sc := -1 129 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 130 sc = result.FutureAPI.Response().StatusCode 131 } 132 tracing.EndSpan(ctx, sc, err) 133 }() 134 } 135 req, err := client.DeletePreparer(ctx, deviceName, roleName, addonName, resourceGroupName) 136 if err != nil { 137 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "Delete", nil, "Failure preparing request") 138 return 139 } 140 141 result, err = client.DeleteSender(req) 142 if err != nil { 143 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "Delete", nil, "Failure sending request") 144 return 145 } 146 147 return 148} 149 150// DeletePreparer prepares the Delete request. 151func (client AddonsClient) DeletePreparer(ctx context.Context, deviceName string, roleName string, addonName string, resourceGroupName string) (*http.Request, error) { 152 pathParameters := map[string]interface{}{ 153 "addonName": autorest.Encode("path", addonName), 154 "deviceName": autorest.Encode("path", deviceName), 155 "resourceGroupName": autorest.Encode("path", resourceGroupName), 156 "roleName": autorest.Encode("path", roleName), 157 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 158 } 159 160 const APIVersion = "2020-12-01" 161 queryParameters := map[string]interface{}{ 162 "api-version": APIVersion, 163 } 164 165 preparer := autorest.CreatePreparer( 166 autorest.AsDelete(), 167 autorest.WithBaseURL(client.BaseURI), 168 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/roles/{roleName}/addons/{addonName}", pathParameters), 169 autorest.WithQueryParameters(queryParameters)) 170 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 171} 172 173// DeleteSender sends the Delete request. The method will close the 174// http.Response Body if it receives an error. 175func (client AddonsClient) DeleteSender(req *http.Request) (future AddonsDeleteFuture, err error) { 176 var resp *http.Response 177 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 178 if err != nil { 179 return 180 } 181 var azf azure.Future 182 azf, err = azure.NewFutureFromResponse(resp) 183 future.FutureAPI = &azf 184 future.Result = future.result 185 return 186} 187 188// DeleteResponder handles the response to the Delete request. The method always 189// closes the http.Response Body. 190func (client AddonsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 191 err = autorest.Respond( 192 resp, 193 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 194 autorest.ByClosing()) 195 result.Response = resp 196 return 197} 198 199// Get gets a specific addon by name. 200// Parameters: 201// deviceName - the device name. 202// roleName - the role name. 203// addonName - the addon name. 204// resourceGroupName - the resource group name. 205func (client AddonsClient) Get(ctx context.Context, deviceName string, roleName string, addonName string, resourceGroupName string) (result AddonModel, err error) { 206 if tracing.IsEnabled() { 207 ctx = tracing.StartSpan(ctx, fqdn+"/AddonsClient.Get") 208 defer func() { 209 sc := -1 210 if result.Response.Response != nil { 211 sc = result.Response.Response.StatusCode 212 } 213 tracing.EndSpan(ctx, sc, err) 214 }() 215 } 216 req, err := client.GetPreparer(ctx, deviceName, roleName, addonName, resourceGroupName) 217 if err != nil { 218 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "Get", nil, "Failure preparing request") 219 return 220 } 221 222 resp, err := client.GetSender(req) 223 if err != nil { 224 result.Response = autorest.Response{Response: resp} 225 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "Get", resp, "Failure sending request") 226 return 227 } 228 229 result, err = client.GetResponder(resp) 230 if err != nil { 231 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "Get", resp, "Failure responding to request") 232 return 233 } 234 235 return 236} 237 238// GetPreparer prepares the Get request. 239func (client AddonsClient) GetPreparer(ctx context.Context, deviceName string, roleName string, addonName string, resourceGroupName string) (*http.Request, error) { 240 pathParameters := map[string]interface{}{ 241 "addonName": autorest.Encode("path", addonName), 242 "deviceName": autorest.Encode("path", deviceName), 243 "resourceGroupName": autorest.Encode("path", resourceGroupName), 244 "roleName": autorest.Encode("path", roleName), 245 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 246 } 247 248 const APIVersion = "2020-12-01" 249 queryParameters := map[string]interface{}{ 250 "api-version": APIVersion, 251 } 252 253 preparer := autorest.CreatePreparer( 254 autorest.AsGet(), 255 autorest.WithBaseURL(client.BaseURI), 256 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/roles/{roleName}/addons/{addonName}", pathParameters), 257 autorest.WithQueryParameters(queryParameters)) 258 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 259} 260 261// GetSender sends the Get request. The method will close the 262// http.Response Body if it receives an error. 263func (client AddonsClient) GetSender(req *http.Request) (*http.Response, error) { 264 return client.Send(req, 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 AddonsClient) GetResponder(resp *http.Response) (result AddonModel, err error) { 270 err = autorest.Respond( 271 resp, 272 azure.WithErrorUnlessStatusCode(http.StatusOK), 273 autorest.ByUnmarshallingJSON(&result), 274 autorest.ByClosing()) 275 result.Response = autorest.Response{Response: resp} 276 return 277} 278 279// ListByRole lists all the addons configured in the role. 280// Parameters: 281// deviceName - the device name. 282// roleName - the role name. 283// resourceGroupName - the resource group name. 284func (client AddonsClient) ListByRole(ctx context.Context, deviceName string, roleName string, resourceGroupName string) (result AddonListPage, err error) { 285 if tracing.IsEnabled() { 286 ctx = tracing.StartSpan(ctx, fqdn+"/AddonsClient.ListByRole") 287 defer func() { 288 sc := -1 289 if result.al.Response.Response != nil { 290 sc = result.al.Response.Response.StatusCode 291 } 292 tracing.EndSpan(ctx, sc, err) 293 }() 294 } 295 result.fn = client.listByRoleNextResults 296 req, err := client.ListByRolePreparer(ctx, deviceName, roleName, resourceGroupName) 297 if err != nil { 298 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "ListByRole", nil, "Failure preparing request") 299 return 300 } 301 302 resp, err := client.ListByRoleSender(req) 303 if err != nil { 304 result.al.Response = autorest.Response{Response: resp} 305 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "ListByRole", resp, "Failure sending request") 306 return 307 } 308 309 result.al, err = client.ListByRoleResponder(resp) 310 if err != nil { 311 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "ListByRole", resp, "Failure responding to request") 312 return 313 } 314 if result.al.hasNextLink() && result.al.IsEmpty() { 315 err = result.NextWithContext(ctx) 316 return 317 } 318 319 return 320} 321 322// ListByRolePreparer prepares the ListByRole request. 323func (client AddonsClient) ListByRolePreparer(ctx context.Context, deviceName string, roleName string, resourceGroupName string) (*http.Request, error) { 324 pathParameters := map[string]interface{}{ 325 "deviceName": autorest.Encode("path", deviceName), 326 "resourceGroupName": autorest.Encode("path", resourceGroupName), 327 "roleName": autorest.Encode("path", roleName), 328 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 329 } 330 331 const APIVersion = "2020-12-01" 332 queryParameters := map[string]interface{}{ 333 "api-version": APIVersion, 334 } 335 336 preparer := autorest.CreatePreparer( 337 autorest.AsGet(), 338 autorest.WithBaseURL(client.BaseURI), 339 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DataBoxEdge/dataBoxEdgeDevices/{deviceName}/roles/{roleName}/addons", pathParameters), 340 autorest.WithQueryParameters(queryParameters)) 341 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 342} 343 344// ListByRoleSender sends the ListByRole request. The method will close the 345// http.Response Body if it receives an error. 346func (client AddonsClient) ListByRoleSender(req *http.Request) (*http.Response, error) { 347 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 348} 349 350// ListByRoleResponder handles the response to the ListByRole request. The method always 351// closes the http.Response Body. 352func (client AddonsClient) ListByRoleResponder(resp *http.Response) (result AddonList, err error) { 353 err = autorest.Respond( 354 resp, 355 azure.WithErrorUnlessStatusCode(http.StatusOK), 356 autorest.ByUnmarshallingJSON(&result), 357 autorest.ByClosing()) 358 result.Response = autorest.Response{Response: resp} 359 return 360} 361 362// listByRoleNextResults retrieves the next set of results, if any. 363func (client AddonsClient) listByRoleNextResults(ctx context.Context, lastResults AddonList) (result AddonList, err error) { 364 req, err := lastResults.addonListPreparer(ctx) 365 if err != nil { 366 return result, autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "listByRoleNextResults", nil, "Failure preparing next results request") 367 } 368 if req == nil { 369 return 370 } 371 resp, err := client.ListByRoleSender(req) 372 if err != nil { 373 result.Response = autorest.Response{Response: resp} 374 return result, autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "listByRoleNextResults", resp, "Failure sending next results request") 375 } 376 result, err = client.ListByRoleResponder(resp) 377 if err != nil { 378 err = autorest.NewErrorWithError(err, "databoxedge.AddonsClient", "listByRoleNextResults", resp, "Failure responding to next results request") 379 } 380 return 381} 382 383// ListByRoleComplete enumerates all values, automatically crossing page boundaries as required. 384func (client AddonsClient) ListByRoleComplete(ctx context.Context, deviceName string, roleName string, resourceGroupName string) (result AddonListIterator, err error) { 385 if tracing.IsEnabled() { 386 ctx = tracing.StartSpan(ctx, fqdn+"/AddonsClient.ListByRole") 387 defer func() { 388 sc := -1 389 if result.Response().Response.Response != nil { 390 sc = result.page.Response().Response.Response.StatusCode 391 } 392 tracing.EndSpan(ctx, sc, err) 393 }() 394 } 395 result.page, err = client.ListByRole(ctx, deviceName, roleName, resourceGroupName) 396 return 397} 398