/
job_client.go
600 lines (574 loc) · 27.7 KB
/
job_client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
//go:build go1.18
// +build go1.18
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
package armautomation
import (
"context"
"errors"
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"net/http"
"net/url"
"strings"
)
// JobClient contains the methods for the Job group.
// Don't use this type directly, use NewJobClient() instead.
type JobClient struct {
internal *arm.Client
subscriptionID string
}
// NewJobClient creates a new instance of JobClient with the specified values.
// - subscriptionID - Gets subscription credentials which uniquely identify Microsoft Azure subscription. The subscription ID
// forms part of the URI for every service call.
// - credential - used to authorize requests. Usually a credential from azidentity.
// - options - pass nil to accept the default values.
func NewJobClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*JobClient, error) {
cl, err := arm.NewClient(moduleName, moduleVersion, credential, options)
if err != nil {
return nil, err
}
client := &JobClient{
subscriptionID: subscriptionID,
internal: cl,
}
return client, nil
}
// Create - Create a job of the runbook.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2019-06-01
// - resourceGroupName - Name of an Azure Resource group.
// - automationAccountName - The name of the automation account.
// - jobName - The job name.
// - parameters - The parameters supplied to the create job operation.
// - options - JobClientCreateOptions contains the optional parameters for the JobClient.Create method.
func (client *JobClient) Create(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, parameters JobCreateParameters, options *JobClientCreateOptions) (JobClientCreateResponse, error) {
var err error
const operationName = "JobClient.Create"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.createCreateRequest(ctx, resourceGroupName, automationAccountName, jobName, parameters, options)
if err != nil {
return JobClientCreateResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return JobClientCreateResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusCreated) {
err = runtime.NewResponseError(httpResp)
return JobClientCreateResponse{}, err
}
resp, err := client.createHandleResponse(httpResp)
return resp, err
}
// createCreateRequest creates the Create request.
func (client *JobClient) createCreateRequest(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, parameters JobCreateParameters, options *JobClientCreateOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}"
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if automationAccountName == "" {
return nil, errors.New("parameter automationAccountName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{automationAccountName}", url.PathEscape(automationAccountName))
if jobName == "" {
return nil, errors.New("parameter jobName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{jobName}", url.PathEscape(jobName))
req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2019-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
if options != nil && options.ClientRequestID != nil {
req.Raw().Header["clientRequestId"] = []string{*options.ClientRequestID}
}
req.Raw().Header["Accept"] = []string{"application/json"}
if err := runtime.MarshalAsJSON(req, parameters); err != nil {
return nil, err
}
return req, nil
}
// createHandleResponse handles the Create response.
func (client *JobClient) createHandleResponse(resp *http.Response) (JobClientCreateResponse, error) {
result := JobClientCreateResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.Job); err != nil {
return JobClientCreateResponse{}, err
}
return result, nil
}
// Get - Retrieve the job identified by job name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2019-06-01
// - resourceGroupName - Name of an Azure Resource group.
// - automationAccountName - The name of the automation account.
// - jobName - The job name.
// - options - JobClientGetOptions contains the optional parameters for the JobClient.Get method.
func (client *JobClient) Get(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientGetOptions) (JobClientGetResponse, error) {
var err error
const operationName = "JobClient.Get"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.getCreateRequest(ctx, resourceGroupName, automationAccountName, jobName, options)
if err != nil {
return JobClientGetResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return JobClientGetResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return JobClientGetResponse{}, err
}
resp, err := client.getHandleResponse(httpResp)
return resp, err
}
// getCreateRequest creates the Get request.
func (client *JobClient) getCreateRequest(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientGetOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}"
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if automationAccountName == "" {
return nil, errors.New("parameter automationAccountName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{automationAccountName}", url.PathEscape(automationAccountName))
if jobName == "" {
return nil, errors.New("parameter jobName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{jobName}", url.PathEscape(jobName))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2019-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
if options != nil && options.ClientRequestID != nil {
req.Raw().Header["clientRequestId"] = []string{*options.ClientRequestID}
}
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// getHandleResponse handles the Get response.
func (client *JobClient) getHandleResponse(resp *http.Response) (JobClientGetResponse, error) {
result := JobClientGetResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.Job); err != nil {
return JobClientGetResponse{}, err
}
return result, nil
}
// GetOutput - Retrieve the job output identified by job name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2019-06-01
// - resourceGroupName - Name of an Azure Resource group.
// - automationAccountName - The name of the automation account.
// - jobName - The name of the job to be created.
// - options - JobClientGetOutputOptions contains the optional parameters for the JobClient.GetOutput method.
func (client *JobClient) GetOutput(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientGetOutputOptions) (JobClientGetOutputResponse, error) {
var err error
const operationName = "JobClient.GetOutput"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.getOutputCreateRequest(ctx, resourceGroupName, automationAccountName, jobName, options)
if err != nil {
return JobClientGetOutputResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return JobClientGetOutputResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return JobClientGetOutputResponse{}, err
}
resp, err := client.getOutputHandleResponse(httpResp)
return resp, err
}
// getOutputCreateRequest creates the GetOutput request.
func (client *JobClient) getOutputCreateRequest(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientGetOutputOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}/output"
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if automationAccountName == "" {
return nil, errors.New("parameter automationAccountName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{automationAccountName}", url.PathEscape(automationAccountName))
if jobName == "" {
return nil, errors.New("parameter jobName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{jobName}", url.PathEscape(jobName))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2019-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
if options != nil && options.ClientRequestID != nil {
req.Raw().Header["clientRequestId"] = []string{*options.ClientRequestID}
}
req.Raw().Header["Accept"] = []string{"text/plain"}
return req, nil
}
// getOutputHandleResponse handles the GetOutput response.
func (client *JobClient) getOutputHandleResponse(resp *http.Response) (JobClientGetOutputResponse, error) {
result := JobClientGetOutputResponse{}
body, err := runtime.Payload(resp)
if err != nil {
return JobClientGetOutputResponse{}, err
}
txt := string(body)
result.Value = &txt
return result, nil
}
// GetRunbookContent - Retrieve the runbook content of the job identified by job name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2019-06-01
// - resourceGroupName - Name of an Azure Resource group.
// - automationAccountName - The name of the automation account.
// - jobName - The job name.
// - options - JobClientGetRunbookContentOptions contains the optional parameters for the JobClient.GetRunbookContent method.
func (client *JobClient) GetRunbookContent(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientGetRunbookContentOptions) (JobClientGetRunbookContentResponse, error) {
var err error
const operationName = "JobClient.GetRunbookContent"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.getRunbookContentCreateRequest(ctx, resourceGroupName, automationAccountName, jobName, options)
if err != nil {
return JobClientGetRunbookContentResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return JobClientGetRunbookContentResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return JobClientGetRunbookContentResponse{}, err
}
resp, err := client.getRunbookContentHandleResponse(httpResp)
return resp, err
}
// getRunbookContentCreateRequest creates the GetRunbookContent request.
func (client *JobClient) getRunbookContentCreateRequest(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientGetRunbookContentOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}/runbookContent"
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if automationAccountName == "" {
return nil, errors.New("parameter automationAccountName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{automationAccountName}", url.PathEscape(automationAccountName))
if jobName == "" {
return nil, errors.New("parameter jobName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{jobName}", url.PathEscape(jobName))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2019-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
if options != nil && options.ClientRequestID != nil {
req.Raw().Header["clientRequestId"] = []string{*options.ClientRequestID}
}
req.Raw().Header["Accept"] = []string{"text/powershell"}
return req, nil
}
// getRunbookContentHandleResponse handles the GetRunbookContent response.
func (client *JobClient) getRunbookContentHandleResponse(resp *http.Response) (JobClientGetRunbookContentResponse, error) {
result := JobClientGetRunbookContentResponse{}
body, err := runtime.Payload(resp)
if err != nil {
return JobClientGetRunbookContentResponse{}, err
}
txt := string(body)
result.Value = &txt
return result, nil
}
// NewListByAutomationAccountPager - Retrieve a list of jobs.
//
// Generated from API version 2019-06-01
// - resourceGroupName - Name of an Azure Resource group.
// - automationAccountName - The name of the automation account.
// - options - JobClientListByAutomationAccountOptions contains the optional parameters for the JobClient.NewListByAutomationAccountPager
// method.
func (client *JobClient) NewListByAutomationAccountPager(resourceGroupName string, automationAccountName string, options *JobClientListByAutomationAccountOptions) *runtime.Pager[JobClientListByAutomationAccountResponse] {
return runtime.NewPager(runtime.PagingHandler[JobClientListByAutomationAccountResponse]{
More: func(page JobClientListByAutomationAccountResponse) bool {
return page.NextLink != nil && len(*page.NextLink) > 0
},
Fetcher: func(ctx context.Context, page *JobClientListByAutomationAccountResponse) (JobClientListByAutomationAccountResponse, error) {
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "JobClient.NewListByAutomationAccountPager")
nextLink := ""
if page != nil {
nextLink = *page.NextLink
}
resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) {
return client.listByAutomationAccountCreateRequest(ctx, resourceGroupName, automationAccountName, options)
}, nil)
if err != nil {
return JobClientListByAutomationAccountResponse{}, err
}
return client.listByAutomationAccountHandleResponse(resp)
},
Tracer: client.internal.Tracer(),
})
}
// listByAutomationAccountCreateRequest creates the ListByAutomationAccount request.
func (client *JobClient) listByAutomationAccountCreateRequest(ctx context.Context, resourceGroupName string, automationAccountName string, options *JobClientListByAutomationAccountOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs"
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if automationAccountName == "" {
return nil, errors.New("parameter automationAccountName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{automationAccountName}", url.PathEscape(automationAccountName))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
if options != nil && options.Filter != nil {
reqQP.Set("$filter", *options.Filter)
}
reqQP.Set("api-version", "2019-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
if options != nil && options.ClientRequestID != nil {
req.Raw().Header["clientRequestId"] = []string{*options.ClientRequestID}
}
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// listByAutomationAccountHandleResponse handles the ListByAutomationAccount response.
func (client *JobClient) listByAutomationAccountHandleResponse(resp *http.Response) (JobClientListByAutomationAccountResponse, error) {
result := JobClientListByAutomationAccountResponse{}
if err := runtime.UnmarshalAsJSON(resp, &result.JobListResultV2); err != nil {
return JobClientListByAutomationAccountResponse{}, err
}
return result, nil
}
// Resume - Resume the job identified by jobName.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2019-06-01
// - resourceGroupName - Name of an Azure Resource group.
// - automationAccountName - The name of the automation account.
// - jobName - The job name.
// - options - JobClientResumeOptions contains the optional parameters for the JobClient.Resume method.
func (client *JobClient) Resume(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientResumeOptions) (JobClientResumeResponse, error) {
var err error
const operationName = "JobClient.Resume"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.resumeCreateRequest(ctx, resourceGroupName, automationAccountName, jobName, options)
if err != nil {
return JobClientResumeResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return JobClientResumeResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return JobClientResumeResponse{}, err
}
return JobClientResumeResponse{}, nil
}
// resumeCreateRequest creates the Resume request.
func (client *JobClient) resumeCreateRequest(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientResumeOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}/resume"
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if automationAccountName == "" {
return nil, errors.New("parameter automationAccountName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{automationAccountName}", url.PathEscape(automationAccountName))
if jobName == "" {
return nil, errors.New("parameter jobName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{jobName}", url.PathEscape(jobName))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2019-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
if options != nil && options.ClientRequestID != nil {
req.Raw().Header["clientRequestId"] = []string{*options.ClientRequestID}
}
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// Stop - Stop the job identified by jobName.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2019-06-01
// - resourceGroupName - Name of an Azure Resource group.
// - automationAccountName - The name of the automation account.
// - jobName - The job name.
// - options - JobClientStopOptions contains the optional parameters for the JobClient.Stop method.
func (client *JobClient) Stop(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientStopOptions) (JobClientStopResponse, error) {
var err error
const operationName = "JobClient.Stop"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.stopCreateRequest(ctx, resourceGroupName, automationAccountName, jobName, options)
if err != nil {
return JobClientStopResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return JobClientStopResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return JobClientStopResponse{}, err
}
return JobClientStopResponse{}, nil
}
// stopCreateRequest creates the Stop request.
func (client *JobClient) stopCreateRequest(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientStopOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}/stop"
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if automationAccountName == "" {
return nil, errors.New("parameter automationAccountName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{automationAccountName}", url.PathEscape(automationAccountName))
if jobName == "" {
return nil, errors.New("parameter jobName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{jobName}", url.PathEscape(jobName))
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2019-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
if options != nil && options.ClientRequestID != nil {
req.Raw().Header["clientRequestId"] = []string{*options.ClientRequestID}
}
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}
// Suspend - Suspend the job identified by job name.
// If the operation fails it returns an *azcore.ResponseError type.
//
// Generated from API version 2019-06-01
// - resourceGroupName - Name of an Azure Resource group.
// - automationAccountName - The name of the automation account.
// - jobName - The job name.
// - options - JobClientSuspendOptions contains the optional parameters for the JobClient.Suspend method.
func (client *JobClient) Suspend(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientSuspendOptions) (JobClientSuspendResponse, error) {
var err error
const operationName = "JobClient.Suspend"
ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName)
ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil)
defer func() { endSpan(err) }()
req, err := client.suspendCreateRequest(ctx, resourceGroupName, automationAccountName, jobName, options)
if err != nil {
return JobClientSuspendResponse{}, err
}
httpResp, err := client.internal.Pipeline().Do(req)
if err != nil {
return JobClientSuspendResponse{}, err
}
if !runtime.HasStatusCode(httpResp, http.StatusOK) {
err = runtime.NewResponseError(httpResp)
return JobClientSuspendResponse{}, err
}
return JobClientSuspendResponse{}, nil
}
// suspendCreateRequest creates the Suspend request.
func (client *JobClient) suspendCreateRequest(ctx context.Context, resourceGroupName string, automationAccountName string, jobName string, options *JobClientSuspendOptions) (*policy.Request, error) {
urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobName}/suspend"
if client.subscriptionID == "" {
return nil, errors.New("parameter client.subscriptionID cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID))
if resourceGroupName == "" {
return nil, errors.New("parameter resourceGroupName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName))
if automationAccountName == "" {
return nil, errors.New("parameter automationAccountName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{automationAccountName}", url.PathEscape(automationAccountName))
if jobName == "" {
return nil, errors.New("parameter jobName cannot be empty")
}
urlPath = strings.ReplaceAll(urlPath, "{jobName}", url.PathEscape(jobName))
req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath))
if err != nil {
return nil, err
}
reqQP := req.Raw().URL.Query()
reqQP.Set("api-version", "2019-06-01")
req.Raw().URL.RawQuery = reqQP.Encode()
if options != nil && options.ClientRequestID != nil {
req.Raw().Header["clientRequestId"] = []string{*options.ClientRequestID}
}
req.Raw().Header["Accept"] = []string{"application/json"}
return req, nil
}