0
# Operation Management
1
2
Monitor operation status, cancel running operations, and retrieve detailed error information for troubleshooting failed operations. These capabilities provide comprehensive lifecycle management for all submitted operations.
3
4
## Capabilities
5
6
### Get Operation Status
7
8
Retrieve current status information for operations using their operation IDs, including execution state and progress details.
9
10
```python { .api }
11
def virtual_machines_get_operation_status(
12
self,
13
locationparameter: str,
14
request_body: Union[GetOperationStatusRequest, JSON, IO[bytes]],
15
**kwargs: Any
16
) -> GetOperationStatusResponse:
17
"""
18
Get status information for operations by operation IDs.
19
20
Parameters:
21
- locationparameter: Azure region where operations are executing (required)
22
- request_body: Request containing operation IDs to query (required)
23
24
Returns:
25
Response containing status information for each requested operation
26
"""
27
```
28
29
**Usage Example:**
30
31
```python
32
from azure.mgmt.computeschedule.models import GetOperationStatusRequest
33
34
# Query status for multiple operations
35
request = GetOperationStatusRequest(
36
operation_ids=[
37
"op-12345678-abcd-1234-efgh-123456789012",
38
"op-87654321-dcba-4321-hgfe-210987654321"
39
]
40
)
41
42
response = client.scheduled_actions.virtual_machines_get_operation_status(
43
locationparameter="eastus",
44
request_body=request
45
)
46
47
# Check status of each operation
48
for operation in response.results:
49
print(f"Operation {operation.operation_id}: {operation.state}")
50
if operation.state == "SUCCEEDED":
51
print(f" Completed at: {operation.completion_time}")
52
elif operation.state == "FAILED":
53
print(f" Failed with error: {operation.error_message}")
54
elif operation.state == "EXECUTING":
55
print(f" Progress: {operation.progress_percentage}%")
56
```
57
58
### Cancel Operations
59
60
Cancel running or pending operations before they complete execution.
61
62
```python { .api }
63
def virtual_machines_cancel_operations(
64
self,
65
locationparameter: str,
66
request_body: Union[CancelOperationsRequest, JSON, IO[bytes]],
67
**kwargs: Any
68
) -> CancelOperationsResponse:
69
"""
70
Cancel running operations using operation IDs.
71
72
Parameters:
73
- locationparameter: Azure region where operations are executing (required)
74
- request_body: Request containing operation IDs to cancel (required)
75
76
Returns:
77
Response indicating cancellation status for each operation
78
"""
79
```
80
81
**Usage Example:**
82
83
```python
84
from azure.mgmt.computeschedule.models import CancelOperationsRequest
85
86
# Cancel multiple operations
87
request = CancelOperationsRequest(
88
operation_ids=[
89
"op-12345678-abcd-1234-efgh-123456789012",
90
"op-87654321-dcba-4321-hgfe-210987654321"
91
]
92
)
93
94
response = client.scheduled_actions.virtual_machines_cancel_operations(
95
locationparameter="eastus",
96
request_body=request
97
)
98
99
# Check cancellation results
100
for result in response.results:
101
if result.cancelled:
102
print(f"Operation {result.operation_id} cancelled successfully")
103
else:
104
print(f"Operation {result.operation_id} could not be cancelled: {result.reason}")
105
```
106
107
### Get Operation Errors
108
109
Retrieve detailed error information for failed operations to aid in troubleshooting and debugging.
110
111
```python { .api }
112
def virtual_machines_get_operation_errors(
113
self,
114
locationparameter: str,
115
request_body: Union[GetOperationErrorsRequest, JSON, IO[bytes]],
116
**kwargs: Any
117
) -> GetOperationErrorsResponse:
118
"""
119
Get detailed error information for operations by operation IDs.
120
121
Parameters:
122
- locationparameter: Azure region where operations executed (required)
123
- request_body: Request containing operation IDs to query errors (required)
124
125
Returns:
126
Response containing detailed error information for each operation
127
"""
128
```
129
130
**Usage Example:**
131
132
```python
133
from azure.mgmt.computeschedule.models import GetOperationErrorsRequest
134
135
# Get error details for failed operations
136
request = GetOperationErrorsRequest(
137
operation_ids=[
138
"op-failed-1234-abcd-1234-efgh-123456789012",
139
"op-failed-5678-dcba-4321-hgfe-210987654321"
140
]
141
)
142
143
response = client.scheduled_actions.virtual_machines_get_operation_errors(
144
locationparameter="eastus",
145
request_body=request
146
)
147
148
# Process error information
149
for error_result in response.results:
150
print(f"Operation {error_result.operation_id} errors:")
151
for error in error_result.errors:
152
print(f" Error Code: {error.error_code}")
153
print(f" Error Message: {error.error_message}")
154
print(f" Target Resource: {error.target_resource}")
155
if error.additional_info:
156
print(f" Additional Info: {error.additional_info}")
157
```
158
159
### List Available Operations
160
161
Retrieve the list of available operations supported by the ComputeSchedule provider.
162
163
```python { .api }
164
def list(self, **kwargs: Any) -> ItemPaged[Operation]:
165
"""
166
List all available operations for the ComputeSchedule provider.
167
168
Returns:
169
Paginated list of Operation objects describing available operations
170
"""
171
```
172
173
**Usage Example:**
174
175
```python
176
# List all available provider operations
177
operations = client.operations.list()
178
179
print("Available ComputeSchedule operations:")
180
for operation in operations:
181
print(f" {operation.name}: {operation.display.description}")
182
print(f" Provider: {operation.display.provider}")
183
print(f" Resource: {operation.display.resource}")
184
print(f" Operation: {operation.display.operation}")
185
```
186
187
## Operation Status Monitoring
188
189
### Operation States
190
191
Operations progress through several states during their lifecycle:
192
193
- **UNKNOWN**: Default/uninitialized state
194
- **PENDING_SCHEDULING**: Operation submitted, awaiting scheduling
195
- **SCHEDULED**: Operation scheduled for future execution
196
- **PENDING_EXECUTION**: Scheduled time reached, awaiting execution start
197
- **EXECUTING**: Operation currently in progress
198
- **SUCCEEDED**: Operation completed successfully
199
- **FAILED**: Operation failed with errors
200
- **CANCELLED**: Operation cancelled before completion
201
202
### Status Polling Pattern
203
204
Monitor operation progress with polling:
205
206
```python
207
import time
208
from azure.mgmt.computeschedule.models import GetOperationStatusRequest, OperationState
209
210
def wait_for_operation_completion(client, location, operation_id, timeout_minutes=30):
211
"""Wait for operation to complete with status polling."""
212
213
request = GetOperationStatusRequest(operation_ids=[operation_id])
214
timeout_seconds = timeout_minutes * 60
215
start_time = time.time()
216
217
while time.time() - start_time < timeout_seconds:
218
response = client.scheduled_actions.virtual_machines_get_operation_status(
219
locationparameter=location,
220
request_body=request
221
)
222
223
if response.results:
224
status = response.results[0]
225
print(f"Operation {operation_id} status: {status.state}")
226
227
if status.state in [OperationState.SUCCEEDED, OperationState.FAILED, OperationState.CANCELLED]:
228
return status
229
230
time.sleep(30) # Poll every 30 seconds
231
232
raise TimeoutError(f"Operation {operation_id} did not complete within {timeout_minutes} minutes")
233
234
# Usage
235
try:
236
final_status = wait_for_operation_completion(client, "eastus", operation_id)
237
if final_status.state == OperationState.SUCCEEDED:
238
print("Operation completed successfully!")
239
else:
240
print(f"Operation ended with status: {final_status.state}")
241
except TimeoutError as e:
242
print(f"Timeout: {e}")
243
```
244
245
### Batch Operation Management
246
247
Handle multiple operations efficiently:
248
249
```python
250
from azure.mgmt.computeschedule.models import (
251
GetOperationStatusRequest,
252
CancelOperationsRequest,
253
OperationState
254
)
255
256
def manage_batch_operations(client, location, operation_ids):
257
"""Monitor and manage multiple operations."""
258
259
# Get status for all operations
260
status_request = GetOperationStatusRequest(operation_ids=operation_ids)
261
status_response = client.scheduled_actions.virtual_machines_get_operation_status(
262
locationparameter=location,
263
request_body=status_request
264
)
265
266
# Separate operations by status
267
running_ops = []
268
failed_ops = []
269
completed_ops = []
270
271
for op_status in status_response.results:
272
if op_status.state in [OperationState.EXECUTING, OperationState.PENDING_EXECUTION]:
273
running_ops.append(op_status.operation_id)
274
elif op_status.state == OperationState.FAILED:
275
failed_ops.append(op_status.operation_id)
276
elif op_status.state == OperationState.SUCCEEDED:
277
completed_ops.append(op_status.operation_id)
278
279
print(f"Running: {len(running_ops)}, Failed: {len(failed_ops)}, Completed: {len(completed_ops)}")
280
281
# Cancel all running operations if needed
282
if running_ops:
283
cancel_request = CancelOperationsRequest(operation_ids=running_ops)
284
cancel_response = client.scheduled_actions.virtual_machines_cancel_operations(
285
locationparameter=location,
286
request_body=cancel_request
287
)
288
print(f"Cancelled {sum(1 for r in cancel_response.results if r.cancelled)} operations")
289
290
return {
291
'running': running_ops,
292
'failed': failed_ops,
293
'completed': completed_ops
294
}
295
```
296
297
### Error Analysis
298
299
Analyze operation failures:
300
301
```python
302
from azure.mgmt.computeschedule.models import GetOperationErrorsRequest
303
304
def analyze_operation_failures(client, location, failed_operation_ids):
305
"""Analyze detailed error information for failed operations."""
306
307
if not failed_operation_ids:
308
return
309
310
error_request = GetOperationErrorsRequest(operation_ids=failed_operation_ids)
311
error_response = client.scheduled_actions.virtual_machines_get_operation_errors(
312
locationparameter=location,
313
request_body=error_request
314
)
315
316
error_summary = {}
317
318
for op_errors in error_response.results:
319
op_id = op_errors.operation_id
320
error_summary[op_id] = []
321
322
for error in op_errors.errors:
323
error_info = {
324
'code': error.error_code,
325
'message': error.error_message,
326
'target': error.target_resource,
327
'additional_info': error.additional_info
328
}
329
error_summary[op_id].append(error_info)
330
331
# Print error summary
332
for op_id, errors in error_summary.items():
333
print(f"\nOperation {op_id} failures:")
334
for i, error in enumerate(errors, 1):
335
print(f" Error {i}:")
336
print(f" Code: {error['code']}")
337
print(f" Message: {error['message']}")
338
if error['target']:
339
print(f" Target: {error['target']}")
340
341
return error_summary
342
```