Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_ml_environment_info.py

raw symbols SCIP
1 #!/usr/bin/python
2 #
3 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
4
5 from __future__ import absolute_import, division, print_function
6 __metaclass__ = type
7
8 DOCUMENTATION = '''
9 ---
10 module: azure_rm_ml_environment_info
11 version_added: "3.16.0"
12 short_description: List ML Environment resources
13 description:
14 - List ML Environment resources.
15 options:
16 name:
17 description:
18 - Name of the Azure ML environment.
19 type: str
20 required: false
21 resource_group:
22 description:
23 - Name of resource group.
24 required: true
25 type: str
26 ml_workspace:
27 description:
28 - Name of the Azure ML workspace.
29 required: true
30 type: str
31 ml_registry:
32 description:
33 - If provided, the command will target the registry
34 instead of a workspace. Hence resource group and
35 workspace won't be required. Must be provided if
36 ml_workspace and resource_group are not provided.
37 required: false
38 type: str
39 version:
40 description:
41 - Version of the data asset. Must be provided, if label
42 is not provided. Mutually exclusive with label.
43 required: false
44 type: str
45 label:
46 description:
47 - Label of the data asset. Must be provided, if version
48 is not provided. Mutually exclusive with version.
49 required: false
50 type: str
51 list_type:
52 description:
53 - Specify if you want active, archived or all datasets.
54 type: str
55 choices:
56 - active
57 - archived
58 - all
59
60 extends_documentation_fragment:
61 - azure.azcollection.azure
62
63 author:
64 - Bill Peck (@p3ck)
65 '''
66
67 EXAMPLES = '''
68 - name: List ML Environment by name
69 azure.azcollection.azure_rm_ml_environment_info:
70 name: MyEnvironment
71 resource_group: myResourceGroup
72 ml_workspace: myMLWorkspace
73
74 - name: List Archived ML Environments
75 azure.azcollection.azure_rm_ml_environment_info:
76 resource_group: myResourceGroup
77 ml_workspace: myMLWorkspace
78 list_type: archived
79 '''
80
81 RETURN = '''
82 ml_environments:
83 description:
84 - Environments that match the query.
85 returned: always
86 type: dict
87 sample: [
88 {
89 "conda_file": {
90 "channels": [
91 "conda-forge"
92 ],
93 "dependencies": [
94 "python=3.8",
95 "pip=20.0.2",
96 {
97 "pip": [
98 "numpy",
99 "pandas",
100 "pyarrow",
101 "scikit-learn",
102 "mlflow",
103 "azureml-mlflow",
104 "responsibleai~=0.17.0",
105 "raiwidgets~=0.17.0",
106 "markupsafe<=2.0.1",
107 "itsdangerous==2.0.1",
108 "azureml-dataset-runtime",
109 "azureml-core"
110 ]
111 }
112 ],
113 "name": "aml-rai-environment"
114 },
115 "creation_context": {
116 "created_at": "2026-03-20T17:34:28.790877+00:00",
117 "created_by": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
118 "created_by_type": "Application",
119 "last_modified_at": "2026-03-20T17:34:28.790877+00:00",
120 "last_modified_by": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
121 "last_modified_by_type": "Application"
122 },
123 "id": "azureml:/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx-ml-environment/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxxxxx/environments/environmentxxxxxxxxxx/versions/2",
124 "image": "mcr.microsoft.com/azureml/openmpi3.1.2-ubuntu18.04:20220303.v1",
125 "name": "environmentxxxxxxxxxx",
126 "os_type": "linux",
127 "tags": {},
128 "version": "2"
129 }
130 ]
131 ''' # NOQA
132
133
134 try:
135 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ml import MLClientCommon
136 from azure.core.exceptions import ResourceNotFoundError
137 except ImportError:
138 # This is handled in azure_rm_common
139 pass
140
141
142 class AzureRMMLEnvironmentInfo(MLClientCommon):
143 def __init__(self):
144
145 self.module_arg_spec = dict(
146 name=dict(
147 type='str',
148 required=False,
149 ),
150 resource_group=dict(
151 type='str',
152 required=True,
153 ),
154 ml_workspace=dict(
155 type='str',
156 required=True,
157 ),
158 ml_registry=dict(
159 type='str',
160 ),
161 version=dict(
162 type='str',
163 ),
164 label=dict(
165 type='str',
166 ),
167 list_type=dict(
168 type='str',
169 choices=['archived', 'active', 'all'],
170 ),
171 )
172
173 self._client = None
174
175 self.results = dict(
176 ml_environments=[]
177 )
178
179 required_one_of = [('ml_workspace', 'ml_registry')]
180 mutually_exclusive = [('version', 'label'),
181 ('ml_workspace', 'ml_registry'),
182 ('name', 'list_type')]
183 required_together = [('ml_workspace', 'resource_group')]
184
185 super(AzureRMMLEnvironmentInfo, self).__init__(self.module_arg_spec,
186 supports_tags=False,
187 supports_check_mode=True,
188 facts_module=True,
189 required_one_of=required_one_of,
190 mutually_exclusive=mutually_exclusive,
191 required_together=required_together
192 )
193
194 def exec_module(self, **kwargs):
195
196 for key in list(self.module_arg_spec.keys()):
197 setattr(self, key, kwargs[key])
198
199 if self.name:
200 try:
201 result = self.client.environments.get(name=self.name,
202 version=self.version,
203 label=self.label)
204 ml_environments = [self.entity_to_dict(result)]
205 except ResourceNotFoundError:
206 ml_environments = []
207 else:
208 list_view_type = self.get_list_view_type(self.list_type)
209 results = self.client.environments.list(name=self.name,
210 list_view_type=list_view_type)
211 ml_environments = [self.entity_to_dict(self.client.environments.get(x.name, version=x.latest_version)) for x in results]
212
213 self.results['ml_environments'] = ml_environments
214 return self.results
215
216
217 def main():
218 AzureRMMLEnvironmentInfo()
219
220
221 if __name__ == '__main__':
222 main()