| 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_data_info |
| 11 |
version_added: "3.16.0" |
| 12 |
short_description: List ML Data resources |
| 13 |
description: |
| 14 |
- List ML Data resources. |
| 15 |
options: |
| 16 |
name: |
| 17 |
description: |
| 18 |
- Name of the data asset. If provided, all the data versions |
| 19 |
under this name will be returned. |
| 20 |
type: str |
| 21 |
required: false |
| 22 |
resource_group: |
| 23 |
description: |
| 24 |
- Name of resource group. |
| 25 |
required: false |
| 26 |
type: str |
| 27 |
ml_workspace: |
| 28 |
description: |
| 29 |
- Name of the Azure ML workspace. |
| 30 |
required: false |
| 31 |
type: str |
| 32 |
ml_registry: |
| 33 |
description: |
| 34 |
- If provided, the command will target the registry |
| 35 |
instead of a workspace. Hence resource group and |
| 36 |
workspace won't be required. Must be provided if |
| 37 |
ml_workspace and resource_group are not provided. |
| 38 |
required: false |
| 39 |
type: str |
| 40 |
version: |
| 41 |
description: |
| 42 |
- Version of the data asset. Must be provided, if label |
| 43 |
is not provided. Mutually exclusive with label. |
| 44 |
required: false |
| 45 |
type: str |
| 46 |
label: |
| 47 |
description: |
| 48 |
- Label of the data asset. Must be provided, if version |
| 49 |
is not provided. Mutually exclusive with version. |
| 50 |
required: false |
| 51 |
type: str |
| 52 |
list_type: |
| 53 |
description: |
| 54 |
- Specify if you want active, archived or all datasets. |
| 55 |
type: str |
| 56 |
choices: |
| 57 |
- active |
| 58 |
- archived |
| 59 |
- all |
| 60 |
|
| 61 |
extends_documentation_fragment: |
| 62 |
- azure.azcollection.azure |
| 63 |
|
| 64 |
author: |
| 65 |
- Bill Peck (@p3ck) |
| 66 |
''' |
| 67 |
|
| 68 |
EXAMPLES = ''' |
| 69 |
- name: List ML Data |
| 70 |
azure.azcollection.azure_rm_ml_data_info: |
| 71 |
name: MyData |
| 72 |
resource_group: myResourceGroup |
| 73 |
ml_workspace: myMLWorkspace |
| 74 |
|
| 75 |
- name: List ML Data |
| 76 |
azure.azcollection.azure_rm_ml_data_info: |
| 77 |
resource_group: myResourceGroup |
| 78 |
ml_workspace: myMLWorkspace |
| 79 |
list_type: archived |
| 80 |
''' |
| 81 |
|
| 82 |
RETURN = ''' |
| 83 |
ml_data_assets: |
| 84 |
description: |
| 85 |
- Data that was just created or updated. |
| 86 |
returned: always |
| 87 |
type: dict |
| 88 |
sample: [ |
| 89 |
{ |
| 90 |
"creation_context": |
| 91 |
{ |
| 92 |
"created_at": "2026-03-05T20:28:42.120932+00:00", |
| 93 |
"created_by": "ca413070-9a06-4e0a-8bb8-c167d29fa09e", |
| 94 |
"created_by_type": "Application", |
| 95 |
"last_modified_at": "2026-03-05T20:28:57.237566+00:00", |
| 96 |
"last_modified_by": "ca413070-9a06-4e0a-8bb8-c167d29fa09e", |
| 97 |
"last_modified_by_type": "Application", |
| 98 |
}, |
| 99 |
"description": "Data asset created from local folder.", |
| 100 |
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx-ml-data/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxx-xxx/data/data-xxxxxxx-xxx/versions/2", |
| 101 |
"name": "data-xxxxxxx-xxx", |
| 102 |
"path": "azureml://subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/xxxxx-ml-data/workspaces/workspace-xxxxxxx-xxx/datastores/workspaceblobstore/paths/LocalUpload/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/data/", |
| 103 |
"properties": {}, |
| 104 |
"tags": {}, |
| 105 |
"type": "uri_folder", |
| 106 |
"version": "2", |
| 107 |
}, |
| 108 |
] |
| 109 |
''' |
| 110 |
|
| 111 |
|
| 112 |
try: |
| 113 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ml import MLClientCommon |
| 114 |
from azure.core.exceptions import ResourceNotFoundError |
| 115 |
except ImportError: |
| 116 |
|
| 117 |
pass |
| 118 |
|
| 119 |
|
| 120 |
class AzureRMMLDataInfo(MLClientCommon): |
| 121 |
def __init__(self): |
| 122 |
|
| 123 |
self.module_arg_spec = dict( |
| 124 |
name=dict( |
| 125 |
type='str', |
| 126 |
required=False, |
| 127 |
), |
| 128 |
resource_group=dict( |
| 129 |
type='str', |
| 130 |
required=False, |
| 131 |
), |
| 132 |
ml_workspace=dict( |
| 133 |
type='str', |
| 134 |
required=False, |
| 135 |
), |
| 136 |
ml_registry=dict( |
| 137 |
type='str', |
| 138 |
), |
| 139 |
version=dict( |
| 140 |
type='str', |
| 141 |
), |
| 142 |
label=dict( |
| 143 |
type='str', |
| 144 |
), |
| 145 |
list_type=dict( |
| 146 |
type='str', |
| 147 |
choices=['archived', 'active', 'all'], |
| 148 |
), |
| 149 |
) |
| 150 |
|
| 151 |
self._client = None |
| 152 |
self.ml_data = None |
| 153 |
|
| 154 |
self.results = dict( |
| 155 |
ml_data_assets=[] |
| 156 |
) |
| 157 |
|
| 158 |
required_one_of = [('ml_workspace', 'ml_registry')] |
| 159 |
mutually_exclusive = [('version', 'label'), |
| 160 |
('ml_workspace', 'ml_registry'), |
| 161 |
('name', 'list_type')] |
| 162 |
required_together = [('ml_workspace', 'resource_group')] |
| 163 |
|
| 164 |
super(AzureRMMLDataInfo, self).__init__(self.module_arg_spec, |
| 165 |
supports_tags=False, |
| 166 |
supports_check_mode=True, |
| 167 |
required_one_of=required_one_of, |
| 168 |
mutually_exclusive=mutually_exclusive, |
| 169 |
required_together=required_together, |
| 170 |
facts_module=True, |
| 171 |
) |
| 172 |
|
| 173 |
def exec_module(self, **kwargs): |
| 174 |
|
| 175 |
for key in list(self.module_arg_spec.keys()): |
| 176 |
setattr(self, key, kwargs[key]) |
| 177 |
|
| 178 |
if self.name: |
| 179 |
label = self.label |
| 180 |
if not self.version and not label: |
| 181 |
label = 'latest' |
| 182 |
try: |
| 183 |
result = self.client.data.get(name=self.name, |
| 184 |
version=self.version, |
| 185 |
label=label) |
| 186 |
ml_data_assets = [self.entity_to_dict(result)] |
| 187 |
except ResourceNotFoundError: |
| 188 |
ml_data_assets = [] |
| 189 |
else: |
| 190 |
list_view_type = self.get_list_view_type(self.list_type) |
| 191 |
results = self.client.data.list(list_view_type=list_view_type) |
| 192 |
|
| 193 |
ml_data_assets = [self.entity_to_dict(self.client.data.get(name=x.name, version=x.latest_version)) for x in results] |
| 194 |
|
| 195 |
self.results['ml_data_assets'] = ml_data_assets |
| 196 |
return self.results |
| 197 |
|
| 198 |
|
| 199 |
def main(): |
| 200 |
AzureRMMLDataInfo() |
| 201 |
|
| 202 |
|
| 203 |
if __name__ == '__main__': |
| 204 |
main() |