| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
DOCUMENTATION = ''' |
| 9 |
--- |
| 10 |
module: azure_rm_ml_workspace_info |
| 11 |
version_added: "3.15.0" |
| 12 |
short_description: List ML Workspaces |
| 13 |
description: |
| 14 |
- List ML Workspaces. |
| 15 |
options: |
| 16 |
name: |
| 17 |
description: |
| 18 |
- Retrieve details about a specific ml workspace. |
| 19 |
type: str |
| 20 |
required: false |
| 21 |
filtered_kinds: |
| 22 |
description: |
| 23 |
- List only the specified kinds of ml workspaces. |
| 24 |
required: false |
| 25 |
type: list |
| 26 |
elements: str |
| 27 |
default: [] |
| 28 |
choices: |
| 29 |
- default |
| 30 |
- hub |
| 31 |
- project |
| 32 |
resource_group: |
| 33 |
description: |
| 34 |
- Name of a resource group to limit ml workspaces from. |
| 35 |
If not specified the subscription will be searched. |
| 36 |
required: false |
| 37 |
type: str |
| 38 |
|
| 39 |
extends_documentation_fragment: |
| 40 |
- azure.azcollection.azure |
| 41 |
|
| 42 |
author: |
| 43 |
- Bill Peck (@p3ck) |
| 44 |
''' |
| 45 |
|
| 46 |
EXAMPLES = ''' |
| 47 |
- name: Get info on a specific ml workspaces |
| 48 |
azure.azcollection.azure_rm_ml_workspace_info: |
| 49 |
name: my_workspace |
| 50 |
resource_group: test_ml_workspace |
| 51 |
register: result |
| 52 |
|
| 53 |
- name: List all ml workspaces in subscription |
| 54 |
azure.azcollection.azure_rm_ml_workspace_info: |
| 55 |
register: results |
| 56 |
|
| 57 |
- name: List all hub workspaces in resource group |
| 58 |
azure.azcollection.azure_rm_ml_workspace_info: |
| 59 |
resource_group: test_ml_workspace |
| 60 |
filtered_kinds: |
| 61 |
- hub |
| 62 |
register: results |
| 63 |
''' |
| 64 |
|
| 65 |
RETURN = ''' |
| 66 |
ml_workspaces: |
| 67 |
description: |
| 68 |
- List of ML Workspaces. |
| 69 |
returned: always |
| 70 |
type: dict |
| 71 |
sample: [ |
| 72 |
{ |
| 73 |
"allow_roleassignment_on_rg": true, |
| 74 |
"application_insights": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/test-ml-workspace/providers/Microsoft.insights/components/workspacinsightsxxxxxxxx", |
| 75 |
"description": "Workspace Integration Tests", |
| 76 |
"discovery_url": "https://westus3.api.azureml.ms/discovery", |
| 77 |
"display_name": "workspace-xxxxxxx-xxx", |
| 78 |
"enable_data_isolation": false, |
| 79 |
"hbi_workspace": false, |
| 80 |
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/test-ml-workspace/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxx-xxx", |
| 81 |
"identity": { |
| 82 |
"principal_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 83 |
"tenant_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 84 |
"type": "system_assigned" |
| 85 |
}, |
| 86 |
"key_vault": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/test-ml-workspace/providers/Microsoft.Keyvault/vaults/workspackeyvaultxxxxxxxx", |
| 87 |
"location": "westus3", |
| 88 |
"managed_network": { |
| 89 |
"firewall_sku": "standard", |
| 90 |
"isolation_mode": "allow_only_approved_outbound", |
| 91 |
"network_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 92 |
"outbound_rules": [ |
| 93 |
{ |
| 94 |
"category": "user_defined", |
| 95 |
"destination": "microsoft.com", |
| 96 |
"name": "microsoft", |
| 97 |
"status": "Inactive", |
| 98 |
"type": "fqdn" |
| 99 |
}, |
| 100 |
{ |
| 101 |
"category": "user_defined", |
| 102 |
"destination": { |
| 103 |
"address_prefixes": [ |
| 104 |
"168.63.129.16", |
| 105 |
"10.0.0.0/24" |
| 106 |
], |
| 107 |
"port_ranges": "80, 8080-8089", |
| 108 |
"protocol": "TCP", |
| 109 |
"service_tag": "sometag" |
| 110 |
}, |
| 111 |
"name": "servicetag-w-prefixes", |
| 112 |
"status": "Inactive", |
| 113 |
"type": "service_tag" |
| 114 |
}, |
| 115 |
{ |
| 116 |
"category": "required", |
| 117 |
"destination": { |
| 118 |
"address_prefixes": [], |
| 119 |
"port_ranges": "443", |
| 120 |
"protocol": "TCP", |
| 121 |
"service_tag": "AzureMonitor" |
| 122 |
}, |
| 123 |
"name": "__SYS_ST_AzureMonitor_TCP", |
| 124 |
"status": "Inactive", |
| 125 |
"type": "service_tag" |
| 126 |
}, |
| 127 |
{ |
| 128 |
"category": "required", |
| 129 |
"destination": { |
| 130 |
"address_prefixes": [], |
| 131 |
"port_ranges": "443", |
| 132 |
"protocol": "TCP", |
| 133 |
"service_tag": "AzureResourceManager" |
| 134 |
}, |
| 135 |
"name": "__SYS_ST_AzureResourceManager_TCP", |
| 136 |
"status": "Inactive", |
| 137 |
"type": "service_tag" |
| 138 |
}, |
| 139 |
{ |
| 140 |
"category": "required", |
| 141 |
"destination": { |
| 142 |
"service_resource_id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/test-ml-workspace/providers/Microsoft.Storage/storageAccounts/workspacstoragexxxxxxxxx", |
| 143 |
"spark_enabled": true, |
| 144 |
"subresource_target": "file" |
| 145 |
}, |
| 146 |
"name": "__SYS_PE_workspacstoragexxxxxxxxx_file_xxxxxxxx", |
| 147 |
"status": "Inactive", |
| 148 |
"type": "private_endpoint" |
| 149 |
}, |
| 150 |
{ |
| 151 |
"category": "required", |
| 152 |
"destination": { |
| 153 |
"address_prefixes": [], |
| 154 |
"port_ranges": "443", |
| 155 |
"protocol": "TCP", |
| 156 |
"service_tag": "MicrosoftContainerRegistry.westus3" |
| 157 |
}, |
| 158 |
"name": "__SYS_ST_MicrosoftContainerRegistry.westus3_TCP", |
| 159 |
"status": "Inactive", |
| 160 |
"type": "service_tag" |
| 161 |
}, |
| 162 |
{ |
| 163 |
"category": "required", |
| 164 |
"destination": { |
| 165 |
"address_prefixes": [], |
| 166 |
"port_ranges": "*", |
| 167 |
"protocol": "*", |
| 168 |
"service_tag": "VirtualNetwork" |
| 169 |
}, |
| 170 |
"name": "__SYS_ST_VirtualNetwork", |
| 171 |
"status": "Inactive", |
| 172 |
"type": "service_tag" |
| 173 |
}, |
| 174 |
{ |
| 175 |
"category": "required", |
| 176 |
"destination": { |
| 177 |
"address_prefixes": [], |
| 178 |
"port_ranges": "443", |
| 179 |
"protocol": "TCP", |
| 180 |
"service_tag": "BatchNodeManagement" |
| 181 |
}, |
| 182 |
"name": "__SYS_ST_BatchNodeManagement_TCP", |
| 183 |
"status": "Inactive", |
| 184 |
"type": "service_tag" |
| 185 |
}, |
| 186 |
{ |
| 187 |
"category": "required", |
| 188 |
"destination": { |
| 189 |
"address_prefixes": [], |
| 190 |
"port_ranges": "80, 443", |
| 191 |
"protocol": "TCP", |
| 192 |
"service_tag": "AzureActiveDirectory" |
| 193 |
}, |
| 194 |
"name": "__SYS_ST_AzureActiveDirectory_TCP", |
| 195 |
"status": "Inactive", |
| 196 |
"type": "service_tag" |
| 197 |
}, |
| 198 |
{ |
| 199 |
"category": "required", |
| 200 |
"destination": { |
| 201 |
"service_resource_id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/test-ml-workspace/providers/Microsoft.Storage/storageAccounts/workspacstoragexxxxxxxxx", |
| 202 |
"spark_enabled": true, |
| 203 |
"subresource_target": "blob" |
| 204 |
}, |
| 205 |
"name": "__SYS_PE_workspacstoragexxxxxxxxx_blob_xxxxxxxx", |
| 206 |
"status": "Inactive", |
| 207 |
"type": "private_endpoint" |
| 208 |
}, |
| 209 |
{ |
| 210 |
"category": "required", |
| 211 |
"destination": { |
| 212 |
"service_resource_id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/test-ml-workspace/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxx-xxx", |
| 213 |
"spark_enabled": true, |
| 214 |
"subresource_target": "amlworkspace" |
| 215 |
}, |
| 216 |
"name": "__SYS_PE_workspace-xxxxxxx-xxx_amlworkspace_xxxxxxxx", |
| 217 |
"status": "Inactive", |
| 218 |
"type": "private_endpoint" |
| 219 |
}, |
| 220 |
{ |
| 221 |
"category": "required", |
| 222 |
"destination": { |
| 223 |
"address_prefixes": [], |
| 224 |
"port_ranges": "*", |
| 225 |
"protocol": "*", |
| 226 |
"service_tag": "AzureFrontDoor.FirstParty" |
| 227 |
}, |
| 228 |
"name": "__SYS_ST_AzureFrontDoor.FirstParty", |
| 229 |
"status": "Inactive", |
| 230 |
"type": "service_tag" |
| 231 |
}, |
| 232 |
{ |
| 233 |
"category": "required", |
| 234 |
"destination": { |
| 235 |
"address_prefixes": [], |
| 236 |
"port_ranges": "443", |
| 237 |
"protocol": "TCP", |
| 238 |
"service_tag": "AzureMachineLearning" |
| 239 |
}, |
| 240 |
"name": "__SYS_ST_AzureMachineLearning_TCP", |
| 241 |
"status": "Inactive", |
| 242 |
"type": "service_tag" |
| 243 |
}, |
| 244 |
{ |
| 245 |
"category": "required", |
| 246 |
"destination": { |
| 247 |
"service_resource_id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/test-ml-workspace/providers/Microsoft.Keyvault/vaults/workspackeyvaultxxxxxxxx", |
| 248 |
"spark_enabled": true, |
| 249 |
"subresource_target": "vault" |
| 250 |
}, |
| 251 |
"name": "__SYS_PE_workspackeyvault2aa0c6bf_vault_xxxxxxxx", |
| 252 |
"status": "Inactive", |
| 253 |
"type": "private_endpoint" |
| 254 |
}, |
| 255 |
{ |
| 256 |
"category": "required", |
| 257 |
"destination": { |
| 258 |
"address_prefixes": [], |
| 259 |
"port_ranges": "5831", |
| 260 |
"protocol": "UDP", |
| 261 |
"service_tag": "AzureMachineLearning" |
| 262 |
}, |
| 263 |
"name": "__SYS_ST_AzureMachineLearning_UDP", |
| 264 |
"status": "Inactive", |
| 265 |
"type": "service_tag" |
| 266 |
} |
| 267 |
], |
| 268 |
"status": { |
| 269 |
"spark_ready": false, |
| 270 |
"status": "Inactive" |
| 271 |
} |
| 272 |
}, |
| 273 |
"mlflow_tracking_uri": "azureml://westus3.api.azureml.ms/mlflow/v1.0/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/test-ml-workspace/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxx-xxx", |
| 274 |
"name": "workspace-xxxxxxx-xxx", |
| 275 |
"network_acls": { |
| 276 |
"default_action": "Allow", |
| 277 |
"ip_rules": [] |
| 278 |
}, |
| 279 |
"provision_network_now": false, |
| 280 |
"public_network_access": "Disabled", |
| 281 |
"resource_group": "test-ml-workspace", |
| 282 |
"serverless_compute": { |
| 283 |
"no_public_ip": false |
| 284 |
}, |
| 285 |
"storage_account": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/test-ml-workspace/providers/Microsoft.Storage/storageAccounts/workspacstoragefxxxxxxxx", |
| 286 |
"system_datastores_auth_mode": "accesskey", |
| 287 |
"tags": {} |
| 288 |
} |
| 289 |
] |
| 290 |
''' |
| 291 |
|
| 292 |
|
| 293 |
try: |
| 294 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ml import MLClientCommon |
| 295 |
from azure.core.exceptions import ResourceNotFoundError |
| 296 |
from azure.ai.ml.constants._common import Scope |
| 297 |
except ImportError: |
| 298 |
|
| 299 |
pass |
| 300 |
|
| 301 |
|
| 302 |
class AzureRMMLWorkspaceInfo(MLClientCommon): |
| 303 |
|
| 304 |
def __init__(self): |
| 305 |
|
| 306 |
self.module_arg_spec = dict( |
| 307 |
name=dict( |
| 308 |
type='str', |
| 309 |
required=False |
| 310 |
), |
| 311 |
filtered_kinds=dict( |
| 312 |
type='list', |
| 313 |
required=False, |
| 314 |
default=[], |
| 315 |
elements='str', |
| 316 |
choices=['default', |
| 317 |
'hub', |
| 318 |
'project'] |
| 319 |
), |
| 320 |
resource_group=dict( |
| 321 |
type='str', |
| 322 |
required=False |
| 323 |
), |
| 324 |
) |
| 325 |
|
| 326 |
self._client = None |
| 327 |
self.ml_workspace = None |
| 328 |
self.ml_registry = None |
| 329 |
|
| 330 |
required_by = {'name': 'resource_group'} |
| 331 |
|
| 332 |
self.results = dict( |
| 333 |
ml_workspaces=[] |
| 334 |
) |
| 335 |
|
| 336 |
super(AzureRMMLWorkspaceInfo, self).__init__(self.module_arg_spec, |
| 337 |
supports_tags=False, |
| 338 |
supports_check_mode=True, |
| 339 |
required_by=required_by, |
| 340 |
facts_module=True, |
| 341 |
) |
| 342 |
|
| 343 |
def exec_module(self, **kwargs): |
| 344 |
|
| 345 |
for key in self.module_arg_spec: |
| 346 |
setattr(self, key, kwargs[key]) |
| 347 |
|
| 348 |
if self.name: |
| 349 |
try: |
| 350 |
result = self.client.workspaces.get(self.name) |
| 351 |
ml_workspaces = [self.entity_to_dict(result)] |
| 352 |
except ResourceNotFoundError: |
| 353 |
ml_workspaces = [] |
| 354 |
else: |
| 355 |
scope = Scope.RESOURCE_GROUP if self.resource_group else Scope.SUBSCRIPTION |
| 356 |
results = self.client.workspaces.list(scope=scope, |
| 357 |
filtered_kinds=','.join(self.filtered_kinds)) |
| 358 |
ml_workspaces = list(map(self.entity_to_dict, results)) |
| 359 |
|
| 360 |
self.results['ml_workspaces'] = ml_workspaces |
| 361 |
|
| 362 |
return self.results |
| 363 |
|
| 364 |
|
| 365 |
def main(): |
| 366 |
AzureRMMLWorkspaceInfo() |
| 367 |
|
| 368 |
|
| 369 |
if __name__ == '__main__': |
| 370 |
main() |