Debian Codegraph @

ansible_collections/azure/azcollection/plugins/modules/azure_rm_ml_job_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_job_info
11 version_added: "3.17.0"
12 short_description: List ML Job resources
13 description:
14 - List ML Job resources.
15 options:
16 name:
17 description:
18 - Name of the Azure ML job.
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 parent_job_name:
32 description:
33 - Name of the parent job. Will list all jobs whose
34 parent_job_name matches the given name.
35 required: false
36 type: str
37 list_type:
38 description:
39 - Specify if you want active, archived or all jobs.
40 type: str
41 choices:
42 - active
43 - archived
44 - all
45
46 extends_documentation_fragment:
47 - azure.azcollection.azure
48
49 author:
50 - Bill Peck (@p3ck)
51 '''
52
53 EXAMPLES = '''
54 - name: List ML Job by name
55 azure.azcollection.azure_rm_ml_job_info:
56 name: jobxxxxxxxxxx
57 resource_group: myResourceGroup
58 ml_workspace: myMLWorkspace
59
60 - name: List Archived ML Jobs
61 azure.azcollection.azure_rm_ml_job_info:
62 resource_group: myResourceGroup
63 ml_workspace: myMLWorkspace
64 list_type: archived
65 '''
66
67 RETURN = '''
68 ml_jobs:
69 description:
70 - Jobs that match the query.
71 returned: always
72 type: dict
73 sample: [
74 {
75 "code": "azureml:/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx-ml-job/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxxxxx/codes/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/versions/1",
76 "command": "python train.py --data_dir ${{inputs.fashion_mnist}} --model_dir ${{outputs.model}}",
77 "compute": "azureml:cluster-cpu",
78 "creation_context": {
79 "created_at": "2026-03-31T17:55:36.317328+00:00",
80 "created_by": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
81 "created_by_type": "Application"
82 },
83 "description": "Trains a simple neural network on the Fashion-MNIST dataset.",
84 "display_name": "jobxxxxxxxxxx",
85 "environment": "azureml:CliV2AnonymousEnvironment:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
86 "environment_variables": {},
87 "experiment_name": "aml_command_cli",
88 "id": "azureml:/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx-ml-job/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxxxxx/jobs/jobxxxxxxxxxx",
89 "inputs": {
90 "fashion_mnist": {
91 "mode": "ro_mount",
92 "path": "azureml:data-fashion-mnist:1",
93 "type": "uri_folder"
94 }
95 },
96 "name": "jobxxxxxxxxxx",
97 "outputs": {
98 "default": {
99 "mode": "rw_mount",
100 "path": "azureml://datastores/workspaceartifactstore/ExperimentRun/dcid.jobxxxxxxxxxx",
101 "type": "uri_folder"
102 },
103 "model": {
104 "mode": "rw_mount",
105 "type": "mlflow_model"
106 }
107 },
108 "parameters": {},
109 "properties": {
110 "ContentSnapshotId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
111 "EndTimeUtc": "2026-03-31 18:18:41",
112 "ProcessInfoFile": "azureml-logs/process_info.json",
113 "ProcessStatusFile": "azureml-logs/process_status.json",
114 "StartTimeUtc": "2026-03-31 18:14:56",
115 "_azureml.ClusterName": "cluster-cpu",
116 "_azureml.ComputeTargetType": "amlctrain"
117 },
118 "queue_settings": {
119 "job_tier": "null"
120 },
121 "resources": {
122 "instance_count": 1,
123 "properties": {},
124 "shm_size": "2g"
125 },
126 "services": {
127 "Studio": {
128 "endpoint": "https://ml.azure.com/runs/jobxxxxxxxxxx?wsid=/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/xxxxx-ml-job/workspaces/workspace-xxxxxxxxxx&tid=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
129 "type": "Studio"
130 },
131 "Tracking": {
132 "endpoint": "azureml://eastus.api.azureml.ms/mlflow/v1.0/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx-ml-job/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxxxxx?",
133 "type": "Tracking"
134 }
135 },
136 "status": "Completed",
137 "tags": {},
138 "type": "command"
139 }
140 ]
141 ''' # NOQA
142
143
144 try:
145 from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ml import MLClientCommon
146 from azure.core.exceptions import ResourceNotFoundError
147 except ImportError:
148 # This is handled in azure_rm_common
149 pass
150
151
152 class AzureRMMLJobInfo(MLClientCommon):
153 def __init__(self):
154
155 self.module_arg_spec = dict(
156 name=dict(
157 type='str',
158 required=False,
159 ),
160 resource_group=dict(
161 type='str',
162 required=True,
163 ),
164 ml_workspace=dict(
165 type='str',
166 required=True,
167 ),
168 parent_job_name=dict(
169 type='str',
170 required=False,
171 ),
172 list_type=dict(
173 type='str',
174 required=False,
175 choices=['archived', 'active', 'all'],
176 ),
177 )
178
179 self._client = None
180 self.ml_registry = None
181
182 self.results = dict(
183 ml_jobs=[]
184 )
185
186 required_one_of = [('name', 'list_type')]
187 mutually_exclusive = [('name', 'list_type'),
188 ('name', 'parent_job_name')]
189
190 super(AzureRMMLJobInfo, self).__init__(self.module_arg_spec,
191 supports_tags=False,
192 supports_check_mode=True,
193 facts_module=True,
194 required_one_of=required_one_of,
195 mutually_exclusive=mutually_exclusive,
196 )
197
198 def exec_module(self, **kwargs):
199
200 for key in list(self.module_arg_spec.keys()):
201 setattr(self, key, kwargs[key])
202
203 if self.name:
204 try:
205 result = self.client.jobs.get(name=self.name)
206 ml_jobs = [self.entity_to_dict(result)]
207 except ResourceNotFoundError:
208 ml_jobs = []
209 else:
210 list_view_type = self.get_list_view_type(self.list_type)
211 results = self.client.jobs.list(parent_job_name=self.parent_job_name,
212 list_view_type=list_view_type)
213 ml_jobs = [self.entity_to_dict(self.client.jobs.get(x.name)) for x in results]
214
215 self.results['ml_jobs'] = ml_jobs
216 return self.results
217
218
219 def main():
220 AzureRMMLJobInfo()
221
222
223 if __name__ == '__main__':
224 main()