0
# Operations and Monitoring
1
2
Comprehensive monitoring and status tracking for long-running operations including media service operations, asset track operations, and streaming endpoint operations with detailed error reporting and operation result retrieval.
3
4
## Capabilities
5
6
### API Operations Discovery
7
8
Discover available API operations and capabilities within the Media Services management plane.
9
10
```python { .api }
11
def list() -> OperationCollection:
12
"""
13
List all available API operations in Azure Media Services.
14
15
Returns:
16
OperationCollection containing all available management operations
17
"""
18
```
19
20
### Media Service Operation Monitoring
21
22
Monitor long-running media service account operations with status tracking and result retrieval.
23
24
```python { .api }
25
def get(location_name: str, operation_id: str) -> MediaServiceOperationStatus:
26
"""
27
Get the status of a media service operation.
28
29
Parameters:
30
- location_name: Azure region name where operation is running (str)
31
- operation_id: Identifier of the operation to monitor (str)
32
33
Returns:
34
MediaServiceOperationStatus with current operation state and progress
35
"""
36
37
def get(location_name: str, operation_id: str) -> Optional[MediaService]:
38
"""
39
Get the result of a completed media service operation.
40
41
Parameters:
42
- location_name: Azure region name where operation ran (str)
43
- operation_id: Identifier of the completed operation (str)
44
45
Returns:
46
MediaService object if operation completed successfully, None otherwise
47
"""
48
```
49
50
### Asset Track Operation Monitoring
51
52
Monitor long-running asset track operations with specialized status tracking.
53
54
```python { .api }
55
def get(
56
location_name: str,
57
account_name: str,
58
operation_id: str
59
) -> AssetTrackOperationStatus:
60
"""
61
Get the status of an asset track operation.
62
63
Parameters:
64
- location_name: Azure region name where operation is running (str)
65
- account_name: Name of the media service account (str)
66
- operation_id: Identifier of the track operation to monitor (str)
67
68
Returns:
69
AssetTrackOperationStatus with current operation state and details
70
"""
71
72
def get(
73
location_name: str,
74
account_name: str,
75
operation_id: str
76
) -> Optional[AssetTrack]:
77
"""
78
Get the result of a completed asset track operation.
79
80
Parameters:
81
- location_name: Azure region name where operation ran (str)
82
- account_name: Name of the media service account (str)
83
- operation_id: Identifier of the completed operation (str)
84
85
Returns:
86
AssetTrack object if operation completed successfully, None otherwise
87
"""
88
```
89
90
### Async Operation Results
91
92
Retrieve results from asynchronous operations with comprehensive status information.
93
94
```python { .api }
95
def async_operation(
96
resource_group_name: str,
97
account_name: str,
98
operation_id: str
99
) -> AsyncOperationResult:
100
"""
101
Get the result of an asynchronous operation.
102
103
Parameters:
104
- resource_group_name: Name of the resource group (str)
105
- account_name: Name of the media service account (str)
106
- operation_id: Identifier of the async operation (str)
107
108
Returns:
109
AsyncOperationResult with operation status and result data
110
"""
111
```
112
113
### Location Utilities
114
115
Check resource name availability in specific Azure regions.
116
117
```python { .api }
118
def check_name_availability(
119
location_name: str,
120
parameters: CheckNameAvailabilityInput
121
) -> EntityNameAvailabilityCheckOutput:
122
"""
123
Check if a resource name is available in the specified location.
124
125
Parameters:
126
- location_name: Azure region name to check (str)
127
- parameters: Name availability check parameters (CheckNameAvailabilityInput)
128
129
Returns:
130
EntityNameAvailabilityCheckOutput with availability status and reason
131
"""
132
```
133
134
## Data Types
135
136
```python { .api }
137
class OperationCollection:
138
"""Collection of available API operations."""
139
value: List[Operation]
140
141
class Operation:
142
"""Individual API operation definition."""
143
name: str
144
display: OperationDisplay
145
origin: str
146
is_data_action: bool
147
action_type: str
148
149
class OperationDisplay:
150
"""Display information for an API operation."""
151
provider: str
152
resource: str
153
operation: str
154
description: str
155
156
class MediaServiceOperationStatus:
157
"""Status of a media service operation."""
158
name: str
159
id: str
160
start_time: str
161
end_time: str
162
status: str # AsyncOperationStatus enum
163
error: dict
164
165
class AssetTrackOperationStatus:
166
"""Status of an asset track operation."""
167
name: str
168
id: str
169
start_time: str
170
end_time: str
171
status: str # AsyncOperationStatus enum
172
error: dict
173
174
class AsyncOperationResult:
175
"""Result of an asynchronous operation."""
176
name: str
177
status: str # AsyncOperationStatus enum
178
properties: dict
179
error: dict
180
181
class CheckNameAvailabilityInput:
182
"""Parameters for checking name availability."""
183
name: str
184
type: str
185
186
class EntityNameAvailabilityCheckOutput:
187
"""Result of name availability check."""
188
name_available: bool
189
reason: str # NameUnavailabilityReason enum
190
message: str
191
```
192
193
## Usage Examples
194
195
### Monitor Long-Running Operation
196
197
```python
198
from azure.mgmt.media import AzureMediaServices
199
from azure.identity import DefaultAzureCredential
200
import time
201
202
client = AzureMediaServices(
203
credential=DefaultAzureCredential(),
204
subscription_id="your-subscription-id"
205
)
206
207
# Start a long-running operation (e.g., create media service)
208
operation = client.mediaservices.begin_create_or_update(
209
resource_group_name="my-resource-group",
210
account_name="my-media-service",
211
parameters=media_service_config
212
)
213
214
# Get operation ID from the polling URL
215
operation_id = operation.id.split('/')[-1]
216
location = "eastus"
217
218
# Monitor operation status
219
while True:
220
status = client.media_services_operation_statuses.get(
221
location_name=location,
222
operation_id=operation_id
223
)
224
225
print(f"Operation status: {status.status}")
226
print(f"Start time: {status.start_time}")
227
228
if status.status == "Succeeded":
229
print("Operation completed successfully")
230
231
# Get the result
232
result = client.media_services_operation_results.get(
233
location_name=location,
234
operation_id=operation_id
235
)
236
237
if result:
238
print(f"Created media service: {result.name}")
239
break
240
241
elif status.status == "Failed":
242
print("Operation failed")
243
if status.error:
244
print(f"Error: {status.error}")
245
break
246
247
elif status.status == "InProgress":
248
print("Operation still in progress...")
249
time.sleep(10) # Wait 10 seconds before checking again
250
251
else:
252
print(f"Unknown status: {status.status}")
253
break
254
```
255
256
### Check Resource Name Availability
257
258
```python
259
from azure.mgmt.media.models import CheckNameAvailabilityInput
260
261
# Check if media service name is available
262
name_check = CheckNameAvailabilityInput(
263
name="my-new-media-service",
264
type="Microsoft.Media/mediaservices"
265
)
266
267
availability_result = client.locations.check_name_availability(
268
location_name="eastus",
269
parameters=name_check
270
)
271
272
if availability_result.name_available:
273
print("Name is available")
274
else:
275
print(f"Name not available: {availability_result.reason}")
276
print(f"Message: {availability_result.message}")
277
```
278
279
### List Available API Operations
280
281
```python
282
# Discover all available operations
283
operations = client.operations.list()
284
285
print("Available Azure Media Services operations:")
286
for operation in operations.value:
287
print(f"Name: {operation.name}")
288
print(f"Description: {operation.display.description}")
289
print(f"Resource: {operation.display.resource}")
290
print(f"Operation: {operation.display.operation}")
291
print()
292
```
293
294
### Monitor Asset Track Operation
295
296
```python
297
# Example: Create asset track and monitor the operation
298
track_operation = client.tracks.begin_create_or_update(
299
resource_group_name="my-resource-group",
300
account_name="my-media-service",
301
asset_name="my-asset",
302
track_name="subtitle-track",
303
parameters=track_config
304
)
305
306
# Extract operation details for monitoring
307
operation_id = track_operation.id.split('/')[-1]
308
location = "eastus"
309
account_name = "my-media-service"
310
311
# Monitor track operation
312
while True:
313
track_status = client.operation_statuses.get(
314
location_name=location,
315
account_name=account_name,
316
operation_id=operation_id
317
)
318
319
print(f"Track operation status: {track_status.status}")
320
321
if track_status.status == "Succeeded":
322
# Get the completed track
323
track_result = client.operation_results.get(
324
location_name=location,
325
account_name=account_name,
326
operation_id=operation_id
327
)
328
329
if track_result:
330
print(f"Track created: {track_result.name}")
331
break
332
333
elif track_status.status == "Failed":
334
print("Track operation failed")
335
if track_status.error:
336
print(f"Error: {track_status.error}")
337
break
338
339
time.sleep(5)
340
```