1package automation 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 "github.com/satori/go.uuid" 27 "net/http" 28) 29 30// JobScheduleClient is the automation Client 31type JobScheduleClient struct { 32 BaseClient 33} 34 35// NewJobScheduleClient creates an instance of the JobScheduleClient client. 36func NewJobScheduleClient(subscriptionID string) JobScheduleClient { 37 return NewJobScheduleClientWithBaseURI(DefaultBaseURI, subscriptionID) 38} 39 40// NewJobScheduleClientWithBaseURI creates an instance of the JobScheduleClient client using a custom endpoint. Use 41// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 42func NewJobScheduleClientWithBaseURI(baseURI string, subscriptionID string) JobScheduleClient { 43 return JobScheduleClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// Create create a job schedule. 47// Parameters: 48// resourceGroupName - name of an Azure Resource group. 49// automationAccountName - the name of the automation account. 50// jobScheduleID - the job schedule name. 51// parameters - the parameters supplied to the create job schedule operation. 52func (client JobScheduleClient) Create(ctx context.Context, resourceGroupName string, automationAccountName string, jobScheduleID uuid.UUID, parameters JobScheduleCreateParameters) (result JobSchedule, err error) { 53 if tracing.IsEnabled() { 54 ctx = tracing.StartSpan(ctx, fqdn+"/JobScheduleClient.Create") 55 defer func() { 56 sc := -1 57 if result.Response.Response != nil { 58 sc = result.Response.Response.StatusCode 59 } 60 tracing.EndSpan(ctx, sc, err) 61 }() 62 } 63 if err := validation.Validate([]validation.Validation{ 64 {TargetValue: resourceGroupName, 65 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 66 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 67 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}, 68 {TargetValue: parameters, 69 Constraints: []validation.Constraint{{Target: "parameters.JobScheduleCreateProperties", Name: validation.Null, Rule: true, 70 Chain: []validation.Constraint{{Target: "parameters.JobScheduleCreateProperties.Schedule", Name: validation.Null, Rule: true, Chain: nil}, 71 {Target: "parameters.JobScheduleCreateProperties.Runbook", Name: validation.Null, Rule: true, Chain: nil}, 72 }}}}}); err != nil { 73 return result, validation.NewError("automation.JobScheduleClient", "Create", err.Error()) 74 } 75 76 req, err := client.CreatePreparer(ctx, resourceGroupName, automationAccountName, jobScheduleID, parameters) 77 if err != nil { 78 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "Create", nil, "Failure preparing request") 79 return 80 } 81 82 resp, err := client.CreateSender(req) 83 if err != nil { 84 result.Response = autorest.Response{Response: resp} 85 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "Create", resp, "Failure sending request") 86 return 87 } 88 89 result, err = client.CreateResponder(resp) 90 if err != nil { 91 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "Create", resp, "Failure responding to request") 92 } 93 94 return 95} 96 97// CreatePreparer prepares the Create request. 98func (client JobScheduleClient) CreatePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, jobScheduleID uuid.UUID, parameters JobScheduleCreateParameters) (*http.Request, error) { 99 pathParameters := map[string]interface{}{ 100 "automationAccountName": autorest.Encode("path", automationAccountName), 101 "jobScheduleId": autorest.Encode("path", jobScheduleID), 102 "resourceGroupName": autorest.Encode("path", resourceGroupName), 103 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 104 } 105 106 const APIVersion = "2015-10-31" 107 queryParameters := map[string]interface{}{ 108 "api-version": APIVersion, 109 } 110 111 preparer := autorest.CreatePreparer( 112 autorest.AsContentType("application/json; charset=utf-8"), 113 autorest.AsPut(), 114 autorest.WithBaseURL(client.BaseURI), 115 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobSchedules/{jobScheduleId}", pathParameters), 116 autorest.WithJSON(parameters), 117 autorest.WithQueryParameters(queryParameters)) 118 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 119} 120 121// CreateSender sends the Create request. The method will close the 122// http.Response Body if it receives an error. 123func (client JobScheduleClient) CreateSender(req *http.Request) (*http.Response, error) { 124 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 125} 126 127// CreateResponder handles the response to the Create request. The method always 128// closes the http.Response Body. 129func (client JobScheduleClient) CreateResponder(resp *http.Response) (result JobSchedule, err error) { 130 err = autorest.Respond( 131 resp, 132 client.ByInspecting(), 133 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 134 autorest.ByUnmarshallingJSON(&result), 135 autorest.ByClosing()) 136 result.Response = autorest.Response{Response: resp} 137 return 138} 139 140// Delete delete the job schedule identified by job schedule name. 141// Parameters: 142// resourceGroupName - name of an Azure Resource group. 143// automationAccountName - the name of the automation account. 144// jobScheduleID - the job schedule name. 145func (client JobScheduleClient) Delete(ctx context.Context, resourceGroupName string, automationAccountName string, jobScheduleID uuid.UUID) (result autorest.Response, err error) { 146 if tracing.IsEnabled() { 147 ctx = tracing.StartSpan(ctx, fqdn+"/JobScheduleClient.Delete") 148 defer func() { 149 sc := -1 150 if result.Response != nil { 151 sc = result.Response.StatusCode 152 } 153 tracing.EndSpan(ctx, sc, err) 154 }() 155 } 156 if err := validation.Validate([]validation.Validation{ 157 {TargetValue: resourceGroupName, 158 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 159 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 160 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 161 return result, validation.NewError("automation.JobScheduleClient", "Delete", err.Error()) 162 } 163 164 req, err := client.DeletePreparer(ctx, resourceGroupName, automationAccountName, jobScheduleID) 165 if err != nil { 166 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "Delete", nil, "Failure preparing request") 167 return 168 } 169 170 resp, err := client.DeleteSender(req) 171 if err != nil { 172 result.Response = resp 173 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "Delete", resp, "Failure sending request") 174 return 175 } 176 177 result, err = client.DeleteResponder(resp) 178 if err != nil { 179 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "Delete", resp, "Failure responding to request") 180 } 181 182 return 183} 184 185// DeletePreparer prepares the Delete request. 186func (client JobScheduleClient) DeletePreparer(ctx context.Context, resourceGroupName string, automationAccountName string, jobScheduleID uuid.UUID) (*http.Request, error) { 187 pathParameters := map[string]interface{}{ 188 "automationAccountName": autorest.Encode("path", automationAccountName), 189 "jobScheduleId": autorest.Encode("path", jobScheduleID), 190 "resourceGroupName": autorest.Encode("path", resourceGroupName), 191 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 192 } 193 194 const APIVersion = "2015-10-31" 195 queryParameters := map[string]interface{}{ 196 "api-version": APIVersion, 197 } 198 199 preparer := autorest.CreatePreparer( 200 autorest.AsDelete(), 201 autorest.WithBaseURL(client.BaseURI), 202 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobSchedules/{jobScheduleId}", pathParameters), 203 autorest.WithQueryParameters(queryParameters)) 204 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 205} 206 207// DeleteSender sends the Delete request. The method will close the 208// http.Response Body if it receives an error. 209func (client JobScheduleClient) DeleteSender(req *http.Request) (*http.Response, error) { 210 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 211} 212 213// DeleteResponder handles the response to the Delete request. The method always 214// closes the http.Response Body. 215func (client JobScheduleClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 216 err = autorest.Respond( 217 resp, 218 client.ByInspecting(), 219 azure.WithErrorUnlessStatusCode(http.StatusOK), 220 autorest.ByClosing()) 221 result.Response = resp 222 return 223} 224 225// Get retrieve the job schedule identified by job schedule name. 226// Parameters: 227// resourceGroupName - name of an Azure Resource group. 228// automationAccountName - the name of the automation account. 229// jobScheduleID - the job schedule name. 230func (client JobScheduleClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, jobScheduleID uuid.UUID) (result JobSchedule, err error) { 231 if tracing.IsEnabled() { 232 ctx = tracing.StartSpan(ctx, fqdn+"/JobScheduleClient.Get") 233 defer func() { 234 sc := -1 235 if result.Response.Response != nil { 236 sc = result.Response.Response.StatusCode 237 } 238 tracing.EndSpan(ctx, sc, err) 239 }() 240 } 241 if err := validation.Validate([]validation.Validation{ 242 {TargetValue: resourceGroupName, 243 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 244 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 245 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 246 return result, validation.NewError("automation.JobScheduleClient", "Get", err.Error()) 247 } 248 249 req, err := client.GetPreparer(ctx, resourceGroupName, automationAccountName, jobScheduleID) 250 if err != nil { 251 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "Get", nil, "Failure preparing request") 252 return 253 } 254 255 resp, err := client.GetSender(req) 256 if err != nil { 257 result.Response = autorest.Response{Response: resp} 258 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "Get", resp, "Failure sending request") 259 return 260 } 261 262 result, err = client.GetResponder(resp) 263 if err != nil { 264 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "Get", resp, "Failure responding to request") 265 } 266 267 return 268} 269 270// GetPreparer prepares the Get request. 271func (client JobScheduleClient) GetPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, jobScheduleID uuid.UUID) (*http.Request, error) { 272 pathParameters := map[string]interface{}{ 273 "automationAccountName": autorest.Encode("path", automationAccountName), 274 "jobScheduleId": autorest.Encode("path", jobScheduleID), 275 "resourceGroupName": autorest.Encode("path", resourceGroupName), 276 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 277 } 278 279 const APIVersion = "2015-10-31" 280 queryParameters := map[string]interface{}{ 281 "api-version": APIVersion, 282 } 283 284 preparer := autorest.CreatePreparer( 285 autorest.AsGet(), 286 autorest.WithBaseURL(client.BaseURI), 287 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobSchedules/{jobScheduleId}", pathParameters), 288 autorest.WithQueryParameters(queryParameters)) 289 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 290} 291 292// GetSender sends the Get request. The method will close the 293// http.Response Body if it receives an error. 294func (client JobScheduleClient) GetSender(req *http.Request) (*http.Response, error) { 295 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 296} 297 298// GetResponder handles the response to the Get request. The method always 299// closes the http.Response Body. 300func (client JobScheduleClient) GetResponder(resp *http.Response) (result JobSchedule, err error) { 301 err = autorest.Respond( 302 resp, 303 client.ByInspecting(), 304 azure.WithErrorUnlessStatusCode(http.StatusOK), 305 autorest.ByUnmarshallingJSON(&result), 306 autorest.ByClosing()) 307 result.Response = autorest.Response{Response: resp} 308 return 309} 310 311// ListByAutomationAccount retrieve a list of job schedules. 312// Parameters: 313// resourceGroupName - name of an Azure Resource group. 314// automationAccountName - the name of the automation account. 315// filter - the filter to apply on the operation. 316func (client JobScheduleClient) ListByAutomationAccount(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (result JobScheduleListResultPage, err error) { 317 if tracing.IsEnabled() { 318 ctx = tracing.StartSpan(ctx, fqdn+"/JobScheduleClient.ListByAutomationAccount") 319 defer func() { 320 sc := -1 321 if result.jslr.Response.Response != nil { 322 sc = result.jslr.Response.Response.StatusCode 323 } 324 tracing.EndSpan(ctx, sc, err) 325 }() 326 } 327 if err := validation.Validate([]validation.Validation{ 328 {TargetValue: resourceGroupName, 329 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 330 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 331 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil { 332 return result, validation.NewError("automation.JobScheduleClient", "ListByAutomationAccount", err.Error()) 333 } 334 335 result.fn = client.listByAutomationAccountNextResults 336 req, err := client.ListByAutomationAccountPreparer(ctx, resourceGroupName, automationAccountName, filter) 337 if err != nil { 338 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "ListByAutomationAccount", nil, "Failure preparing request") 339 return 340 } 341 342 resp, err := client.ListByAutomationAccountSender(req) 343 if err != nil { 344 result.jslr.Response = autorest.Response{Response: resp} 345 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "ListByAutomationAccount", resp, "Failure sending request") 346 return 347 } 348 349 result.jslr, err = client.ListByAutomationAccountResponder(resp) 350 if err != nil { 351 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "ListByAutomationAccount", resp, "Failure responding to request") 352 } 353 354 return 355} 356 357// ListByAutomationAccountPreparer prepares the ListByAutomationAccount request. 358func (client JobScheduleClient) ListByAutomationAccountPreparer(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (*http.Request, error) { 359 pathParameters := map[string]interface{}{ 360 "automationAccountName": autorest.Encode("path", automationAccountName), 361 "resourceGroupName": autorest.Encode("path", resourceGroupName), 362 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 363 } 364 365 const APIVersion = "2015-10-31" 366 queryParameters := map[string]interface{}{ 367 "api-version": APIVersion, 368 } 369 if len(filter) > 0 { 370 queryParameters["$filter"] = autorest.Encode("query", filter) 371 } 372 373 preparer := autorest.CreatePreparer( 374 autorest.AsGet(), 375 autorest.WithBaseURL(client.BaseURI), 376 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobSchedules", pathParameters), 377 autorest.WithQueryParameters(queryParameters)) 378 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 379} 380 381// ListByAutomationAccountSender sends the ListByAutomationAccount request. The method will close the 382// http.Response Body if it receives an error. 383func (client JobScheduleClient) ListByAutomationAccountSender(req *http.Request) (*http.Response, error) { 384 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 385} 386 387// ListByAutomationAccountResponder handles the response to the ListByAutomationAccount request. The method always 388// closes the http.Response Body. 389func (client JobScheduleClient) ListByAutomationAccountResponder(resp *http.Response) (result JobScheduleListResult, err error) { 390 err = autorest.Respond( 391 resp, 392 client.ByInspecting(), 393 azure.WithErrorUnlessStatusCode(http.StatusOK), 394 autorest.ByUnmarshallingJSON(&result), 395 autorest.ByClosing()) 396 result.Response = autorest.Response{Response: resp} 397 return 398} 399 400// listByAutomationAccountNextResults retrieves the next set of results, if any. 401func (client JobScheduleClient) listByAutomationAccountNextResults(ctx context.Context, lastResults JobScheduleListResult) (result JobScheduleListResult, err error) { 402 req, err := lastResults.jobScheduleListResultPreparer(ctx) 403 if err != nil { 404 return result, autorest.NewErrorWithError(err, "automation.JobScheduleClient", "listByAutomationAccountNextResults", nil, "Failure preparing next results request") 405 } 406 if req == nil { 407 return 408 } 409 resp, err := client.ListByAutomationAccountSender(req) 410 if err != nil { 411 result.Response = autorest.Response{Response: resp} 412 return result, autorest.NewErrorWithError(err, "automation.JobScheduleClient", "listByAutomationAccountNextResults", resp, "Failure sending next results request") 413 } 414 result, err = client.ListByAutomationAccountResponder(resp) 415 if err != nil { 416 err = autorest.NewErrorWithError(err, "automation.JobScheduleClient", "listByAutomationAccountNextResults", resp, "Failure responding to next results request") 417 } 418 return 419} 420 421// ListByAutomationAccountComplete enumerates all values, automatically crossing page boundaries as required. 422func (client JobScheduleClient) ListByAutomationAccountComplete(ctx context.Context, resourceGroupName string, automationAccountName string, filter string) (result JobScheduleListResultIterator, err error) { 423 if tracing.IsEnabled() { 424 ctx = tracing.StartSpan(ctx, fqdn+"/JobScheduleClient.ListByAutomationAccount") 425 defer func() { 426 sc := -1 427 if result.Response().Response.Response != nil { 428 sc = result.page.Response().Response.Response.StatusCode 429 } 430 tracing.EndSpan(ctx, sc, err) 431 }() 432 } 433 result.page, err = client.ListByAutomationAccount(ctx, resourceGroupName, automationAccountName, filter) 434 return 435} 436