1package dtl 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// EnvironmentsClient is the the DevTest Labs Client. 30type EnvironmentsClient struct { 31 BaseClient 32} 33 34// NewEnvironmentsClient creates an instance of the EnvironmentsClient client. 35func NewEnvironmentsClient(subscriptionID string) EnvironmentsClient { 36 return NewEnvironmentsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewEnvironmentsClientWithBaseURI creates an instance of the EnvironmentsClient client. 40func NewEnvironmentsClientWithBaseURI(baseURI string, subscriptionID string) EnvironmentsClient { 41 return EnvironmentsClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// CreateOrUpdate create or replace an existing environment. This operation can take a while to complete. 45// Parameters: 46// resourceGroupName - the name of the resource group. 47// labName - the name of the lab. 48// userName - the name of the user profile. 49// name - the name of the environment. 50// dtlEnvironment - an environment, which is essentially an ARM template deployment. 51func (client EnvironmentsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, userName string, name string, dtlEnvironment Environment) (result EnvironmentsCreateOrUpdateFuture, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/EnvironmentsClient.CreateOrUpdate") 54 defer func() { 55 sc := -1 56 if result.Response() != nil { 57 sc = result.Response().StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: dtlEnvironment, 64 Constraints: []validation.Constraint{{Target: "dtlEnvironment.EnvironmentProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 65 return result, validation.NewError("dtl.EnvironmentsClient", "CreateOrUpdate", err.Error()) 66 } 67 68 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, userName, name, dtlEnvironment) 69 if err != nil { 70 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "CreateOrUpdate", nil, "Failure preparing request") 71 return 72 } 73 74 result, err = client.CreateOrUpdateSender(req) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "CreateOrUpdate", result.Response(), "Failure sending request") 77 return 78 } 79 80 return 81} 82 83// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 84func (client EnvironmentsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, userName string, name string, dtlEnvironment Environment) (*http.Request, error) { 85 pathParameters := map[string]interface{}{ 86 "labName": autorest.Encode("path", labName), 87 "name": autorest.Encode("path", name), 88 "resourceGroupName": autorest.Encode("path", resourceGroupName), 89 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 90 "userName": autorest.Encode("path", userName), 91 } 92 93 const APIVersion = "2016-05-15" 94 queryParameters := map[string]interface{}{ 95 "api-version": APIVersion, 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsContentType("application/json; charset=utf-8"), 100 autorest.AsPut(), 101 autorest.WithBaseURL(client.BaseURI), 102 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}", pathParameters), 103 autorest.WithJSON(dtlEnvironment), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 109// http.Response Body if it receives an error. 110func (client EnvironmentsClient) CreateOrUpdateSender(req *http.Request) (future EnvironmentsCreateOrUpdateFuture, err error) { 111 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 112 var resp *http.Response 113 resp, err = autorest.SendWithSender(client, req, sd...) 114 if err != nil { 115 return 116 } 117 future.Future, err = azure.NewFutureFromResponse(resp) 118 return 119} 120 121// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 122// closes the http.Response Body. 123func (client EnvironmentsClient) CreateOrUpdateResponder(resp *http.Response) (result Environment, err error) { 124 err = autorest.Respond( 125 resp, 126 client.ByInspecting(), 127 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 128 autorest.ByUnmarshallingJSON(&result), 129 autorest.ByClosing()) 130 result.Response = autorest.Response{Response: resp} 131 return 132} 133 134// Delete delete environment. This operation can take a while to complete. 135// Parameters: 136// resourceGroupName - the name of the resource group. 137// labName - the name of the lab. 138// userName - the name of the user profile. 139// name - the name of the environment. 140func (client EnvironmentsClient) Delete(ctx context.Context, resourceGroupName string, labName string, userName string, name string) (result EnvironmentsDeleteFuture, err error) { 141 if tracing.IsEnabled() { 142 ctx = tracing.StartSpan(ctx, fqdn+"/EnvironmentsClient.Delete") 143 defer func() { 144 sc := -1 145 if result.Response() != nil { 146 sc = result.Response().StatusCode 147 } 148 tracing.EndSpan(ctx, sc, err) 149 }() 150 } 151 req, err := client.DeletePreparer(ctx, resourceGroupName, labName, userName, name) 152 if err != nil { 153 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "Delete", nil, "Failure preparing request") 154 return 155 } 156 157 result, err = client.DeleteSender(req) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "Delete", result.Response(), "Failure sending request") 160 return 161 } 162 163 return 164} 165 166// DeletePreparer prepares the Delete request. 167func (client EnvironmentsClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, userName string, name string) (*http.Request, error) { 168 pathParameters := map[string]interface{}{ 169 "labName": autorest.Encode("path", labName), 170 "name": autorest.Encode("path", name), 171 "resourceGroupName": autorest.Encode("path", resourceGroupName), 172 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 173 "userName": autorest.Encode("path", userName), 174 } 175 176 const APIVersion = "2016-05-15" 177 queryParameters := map[string]interface{}{ 178 "api-version": APIVersion, 179 } 180 181 preparer := autorest.CreatePreparer( 182 autorest.AsDelete(), 183 autorest.WithBaseURL(client.BaseURI), 184 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}", pathParameters), 185 autorest.WithQueryParameters(queryParameters)) 186 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 187} 188 189// DeleteSender sends the Delete request. The method will close the 190// http.Response Body if it receives an error. 191func (client EnvironmentsClient) DeleteSender(req *http.Request) (future EnvironmentsDeleteFuture, err error) { 192 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 193 var resp *http.Response 194 resp, err = autorest.SendWithSender(client, req, sd...) 195 if err != nil { 196 return 197 } 198 future.Future, err = azure.NewFutureFromResponse(resp) 199 return 200} 201 202// DeleteResponder handles the response to the Delete request. The method always 203// closes the http.Response Body. 204func (client EnvironmentsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 205 err = autorest.Respond( 206 resp, 207 client.ByInspecting(), 208 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 209 autorest.ByClosing()) 210 result.Response = resp 211 return 212} 213 214// Get get environment. 215// Parameters: 216// resourceGroupName - the name of the resource group. 217// labName - the name of the lab. 218// userName - the name of the user profile. 219// name - the name of the environment. 220// expand - specify the $expand query. Example: 'properties($select=deploymentProperties)' 221func (client EnvironmentsClient) Get(ctx context.Context, resourceGroupName string, labName string, userName string, name string, expand string) (result Environment, err error) { 222 if tracing.IsEnabled() { 223 ctx = tracing.StartSpan(ctx, fqdn+"/EnvironmentsClient.Get") 224 defer func() { 225 sc := -1 226 if result.Response.Response != nil { 227 sc = result.Response.Response.StatusCode 228 } 229 tracing.EndSpan(ctx, sc, err) 230 }() 231 } 232 req, err := client.GetPreparer(ctx, resourceGroupName, labName, userName, name, expand) 233 if err != nil { 234 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "Get", nil, "Failure preparing request") 235 return 236 } 237 238 resp, err := client.GetSender(req) 239 if err != nil { 240 result.Response = autorest.Response{Response: resp} 241 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "Get", resp, "Failure sending request") 242 return 243 } 244 245 result, err = client.GetResponder(resp) 246 if err != nil { 247 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "Get", resp, "Failure responding to request") 248 } 249 250 return 251} 252 253// GetPreparer prepares the Get request. 254func (client EnvironmentsClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, userName string, name string, expand string) (*http.Request, error) { 255 pathParameters := map[string]interface{}{ 256 "labName": autorest.Encode("path", labName), 257 "name": autorest.Encode("path", name), 258 "resourceGroupName": autorest.Encode("path", resourceGroupName), 259 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 260 "userName": autorest.Encode("path", userName), 261 } 262 263 const APIVersion = "2016-05-15" 264 queryParameters := map[string]interface{}{ 265 "api-version": APIVersion, 266 } 267 if len(expand) > 0 { 268 queryParameters["$expand"] = autorest.Encode("query", expand) 269 } 270 271 preparer := autorest.CreatePreparer( 272 autorest.AsGet(), 273 autorest.WithBaseURL(client.BaseURI), 274 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments/{name}", pathParameters), 275 autorest.WithQueryParameters(queryParameters)) 276 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 277} 278 279// GetSender sends the Get request. The method will close the 280// http.Response Body if it receives an error. 281func (client EnvironmentsClient) GetSender(req *http.Request) (*http.Response, error) { 282 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 283 return autorest.SendWithSender(client, req, sd...) 284} 285 286// GetResponder handles the response to the Get request. The method always 287// closes the http.Response Body. 288func (client EnvironmentsClient) GetResponder(resp *http.Response) (result Environment, err error) { 289 err = autorest.Respond( 290 resp, 291 client.ByInspecting(), 292 azure.WithErrorUnlessStatusCode(http.StatusOK), 293 autorest.ByUnmarshallingJSON(&result), 294 autorest.ByClosing()) 295 result.Response = autorest.Response{Response: resp} 296 return 297} 298 299// List list environments in a given user profile. 300// Parameters: 301// resourceGroupName - the name of the resource group. 302// labName - the name of the lab. 303// userName - the name of the user profile. 304// expand - specify the $expand query. Example: 'properties($select=deploymentProperties)' 305// filter - the filter to apply to the operation. 306// top - the maximum number of resources to return from the operation. 307// orderby - the ordering expression for the results, using OData notation. 308func (client EnvironmentsClient) List(ctx context.Context, resourceGroupName string, labName string, userName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationDtlEnvironmentPage, err error) { 309 if tracing.IsEnabled() { 310 ctx = tracing.StartSpan(ctx, fqdn+"/EnvironmentsClient.List") 311 defer func() { 312 sc := -1 313 if result.rwcde.Response.Response != nil { 314 sc = result.rwcde.Response.Response.StatusCode 315 } 316 tracing.EndSpan(ctx, sc, err) 317 }() 318 } 319 result.fn = client.listNextResults 320 req, err := client.ListPreparer(ctx, resourceGroupName, labName, userName, expand, filter, top, orderby) 321 if err != nil { 322 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "List", nil, "Failure preparing request") 323 return 324 } 325 326 resp, err := client.ListSender(req) 327 if err != nil { 328 result.rwcde.Response = autorest.Response{Response: resp} 329 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "List", resp, "Failure sending request") 330 return 331 } 332 333 result.rwcde, err = client.ListResponder(resp) 334 if err != nil { 335 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "List", resp, "Failure responding to request") 336 } 337 338 return 339} 340 341// ListPreparer prepares the List request. 342func (client EnvironmentsClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, userName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) { 343 pathParameters := map[string]interface{}{ 344 "labName": autorest.Encode("path", labName), 345 "resourceGroupName": autorest.Encode("path", resourceGroupName), 346 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 347 "userName": autorest.Encode("path", userName), 348 } 349 350 const APIVersion = "2016-05-15" 351 queryParameters := map[string]interface{}{ 352 "api-version": APIVersion, 353 } 354 if len(expand) > 0 { 355 queryParameters["$expand"] = autorest.Encode("query", expand) 356 } 357 if len(filter) > 0 { 358 queryParameters["$filter"] = autorest.Encode("query", filter) 359 } 360 if top != nil { 361 queryParameters["$top"] = autorest.Encode("query", *top) 362 } 363 if len(orderby) > 0 { 364 queryParameters["$orderby"] = autorest.Encode("query", orderby) 365 } 366 367 preparer := autorest.CreatePreparer( 368 autorest.AsGet(), 369 autorest.WithBaseURL(client.BaseURI), 370 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/users/{userName}/environments", pathParameters), 371 autorest.WithQueryParameters(queryParameters)) 372 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 373} 374 375// ListSender sends the List request. The method will close the 376// http.Response Body if it receives an error. 377func (client EnvironmentsClient) ListSender(req *http.Request) (*http.Response, error) { 378 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 379 return autorest.SendWithSender(client, req, sd...) 380} 381 382// ListResponder handles the response to the List request. The method always 383// closes the http.Response Body. 384func (client EnvironmentsClient) ListResponder(resp *http.Response) (result ResponseWithContinuationDtlEnvironment, err error) { 385 err = autorest.Respond( 386 resp, 387 client.ByInspecting(), 388 azure.WithErrorUnlessStatusCode(http.StatusOK), 389 autorest.ByUnmarshallingJSON(&result), 390 autorest.ByClosing()) 391 result.Response = autorest.Response{Response: resp} 392 return 393} 394 395// listNextResults retrieves the next set of results, if any. 396func (client EnvironmentsClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationDtlEnvironment) (result ResponseWithContinuationDtlEnvironment, err error) { 397 req, err := lastResults.responseWithContinuationDtlEnvironmentPreparer(ctx) 398 if err != nil { 399 return result, autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "listNextResults", nil, "Failure preparing next results request") 400 } 401 if req == nil { 402 return 403 } 404 resp, err := client.ListSender(req) 405 if err != nil { 406 result.Response = autorest.Response{Response: resp} 407 return result, autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "listNextResults", resp, "Failure sending next results request") 408 } 409 result, err = client.ListResponder(resp) 410 if err != nil { 411 err = autorest.NewErrorWithError(err, "dtl.EnvironmentsClient", "listNextResults", resp, "Failure responding to next results request") 412 } 413 return 414} 415 416// ListComplete enumerates all values, automatically crossing page boundaries as required. 417func (client EnvironmentsClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, userName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationDtlEnvironmentIterator, err error) { 418 if tracing.IsEnabled() { 419 ctx = tracing.StartSpan(ctx, fqdn+"/EnvironmentsClient.List") 420 defer func() { 421 sc := -1 422 if result.Response().Response.Response != nil { 423 sc = result.page.Response().Response.Response.StatusCode 424 } 425 tracing.EndSpan(ctx, sc, err) 426 }() 427 } 428 result.page, err = client.List(ctx, resourceGroupName, labName, userName, expand, filter, top, orderby) 429 return 430} 431