| 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_online_endpoint_info |
| 11 |
version_added: "3.17.0" |
| 12 |
short_description: List ML Online Endpoint resources |
| 13 |
description: |
| 14 |
- List ML Online Endpoint resources. |
| 15 |
options: |
| 16 |
name: |
| 17 |
description: |
| 18 |
- Name of the Azure ML online endpoint. |
| 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 |
include_auth_keys: |
| 32 |
description: |
| 33 |
- If True then auth_keys will be populated in the return data. |
| 34 |
default: false |
| 35 |
type: bool |
| 36 |
local: |
| 37 |
description: |
| 38 |
- List all local endpoints. |
| 39 |
type: bool |
| 40 |
default: false |
| 41 |
|
| 42 |
extends_documentation_fragment: |
| 43 |
- azure.azcollection.azure |
| 44 |
|
| 45 |
author: |
| 46 |
- Bill Peck (@p3ck) |
| 47 |
''' |
| 48 |
|
| 49 |
EXAMPLES = ''' |
| 50 |
- name: Get Specific ML Online Endpoint by name w/auth_keys |
| 51 |
azure.azcollection.azure_rm_ml_online_endpoint_info: |
| 52 |
name: endpoint-command-xxxxxxxxxx |
| 53 |
include_auth_keys: true |
| 54 |
resource_group: myResourceGroup |
| 55 |
ml_workspace: myMLWorkspace |
| 56 |
|
| 57 |
- name: List Local ML Online Endpoints |
| 58 |
azure.azcollection.azure_rm_ml_online_endpoint_info: |
| 59 |
resource_group: myResourceGroup |
| 60 |
ml_workspace: myMLWorkspace |
| 61 |
local: true |
| 62 |
''' |
| 63 |
|
| 64 |
RETURN = ''' |
| 65 |
ml_online_endpoints: |
| 66 |
description: |
| 67 |
- Online Endpoints that match the query. |
| 68 |
returned: always |
| 69 |
type: dict |
| 70 |
sample: [ |
| 71 |
{ |
| 72 |
"auth_mode": "key", |
| 73 |
"id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/xxxxx-ml-online_endpoint/providers/Microsoft.MachineLearningServices/workspaces/workspace-xxxxxxxxxx/onlineEndpoints/endpoint-command-xxxxxxxxxx", |
| 74 |
"identity": { |
| 75 |
"principal_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 76 |
"tenant_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 77 |
"type": "system_assigned" |
| 78 |
}, |
| 79 |
"auth_keys": { |
| 80 |
"primary_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", |
| 81 |
"secondary_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" |
| 82 |
}, |
| 83 |
"kind": "Managed", |
| 84 |
"location": "eastus", |
| 85 |
"mirror_traffic": {}, |
| 86 |
"name": "endpoint-command-xxxxxxxxxx", |
| 87 |
"openapi_uri": "https://endpoint-command-xxxxxxxxxx.eastus.inference.ml.azure.com/swagger.json", |
| 88 |
"properties": { |
| 89 |
"AzureAsyncOperationUri": "https://management.azure.com/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.MachineLearningServices/locations/eastus/mfeOperationsStatus/oeidp:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx?api-version=2022-02-01-preview", |
| 90 |
"azureml.onlineendpointid": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/xxxxx-ml-online_endpoint/providers/microsoft.machinelearningservices/workspaces/workspace-xxxxxxxxxx/onlineendpoints/endpoint-command-xxxxxxxxxx", |
| 91 |
"createdAt": "2026-04-09T15:04:48.831114+0000", |
| 92 |
"createdBy": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", |
| 93 |
"lastModifiedAt": "2026-04-09T15:04:48.831114+0000" |
| 94 |
}, |
| 95 |
"provisioning_state": "Succeeded", |
| 96 |
"public_network_access": "enabled", |
| 97 |
"scoring_uri": "https://endpoint-command-xxxxxxxxxx.eastus.inference.ml.azure.com/score", |
| 98 |
"tags": {}, |
| 99 |
"traffic": {} |
| 100 |
} |
| 101 |
] |
| 102 |
''' |
| 103 |
|
| 104 |
|
| 105 |
try: |
| 106 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ml import MLClientCommon |
| 107 |
from azure.core.exceptions import ResourceNotFoundError |
| 108 |
except ImportError: |
| 109 |
|
| 110 |
pass |
| 111 |
|
| 112 |
|
| 113 |
class AzureRMMLOnlineEndpointInfo(MLClientCommon): |
| 114 |
def __init__(self): |
| 115 |
|
| 116 |
self.module_arg_spec = dict( |
| 117 |
name=dict( |
| 118 |
type='str', |
| 119 |
required=False, |
| 120 |
), |
| 121 |
include_auth_keys=dict( |
| 122 |
type='bool', |
| 123 |
default=False, |
| 124 |
), |
| 125 |
resource_group=dict( |
| 126 |
type='str', |
| 127 |
required=True, |
| 128 |
), |
| 129 |
ml_workspace=dict( |
| 130 |
type='str', |
| 131 |
required=True, |
| 132 |
), |
| 133 |
local=dict( |
| 134 |
type='bool', |
| 135 |
default=False, |
| 136 |
), |
| 137 |
) |
| 138 |
|
| 139 |
self._client = None |
| 140 |
self.ml_registry = None |
| 141 |
|
| 142 |
self.results = dict( |
| 143 |
ml_online_endpoints=[] |
| 144 |
) |
| 145 |
|
| 146 |
mutually_exclusive = [('include_auth_keys', 'local')] |
| 147 |
|
| 148 |
super(AzureRMMLOnlineEndpointInfo, self).__init__(self.module_arg_spec, |
| 149 |
supports_tags=False, |
| 150 |
supports_check_mode=True, |
| 151 |
facts_module=True, |
| 152 |
mutually_exclusive=mutually_exclusive, |
| 153 |
) |
| 154 |
|
| 155 |
def exec_module(self, **kwargs): |
| 156 |
|
| 157 |
for key in list(self.module_arg_spec.keys()): |
| 158 |
setattr(self, key, kwargs[key]) |
| 159 |
|
| 160 |
if self.name: |
| 161 |
ml_online_endpoints = [self.get(self.name, |
| 162 |
include_auth_keys=self.include_auth_keys, |
| 163 |
local=self.local)] |
| 164 |
else: |
| 165 |
results = self.client.online_endpoints.list(local=self.local) |
| 166 |
ml_online_endpoints = [self.get(x.name, include_auth_keys=self.include_auth_keys, local=self.local) for x in results] |
| 167 |
|
| 168 |
self.results['ml_online_endpoints'] = ml_online_endpoints |
| 169 |
return self.results |
| 170 |
|
| 171 |
def get(self, name, include_auth_keys=False, local=False): |
| 172 |
try: |
| 173 |
result = self.client.online_endpoints.get(name=name, |
| 174 |
local=self.local) |
| 175 |
ml_online_endpoint = self.entity_to_dict(result) |
| 176 |
if include_auth_keys and not local: |
| 177 |
auth_keys = self.client.online_endpoints.get_keys(name=name) |
| 178 |
ml_online_endpoint['auth_keys'] = dict(primary_key=auth_keys.primary_key, |
| 179 |
secondary_key=auth_keys.secondary_key) |
| 180 |
except ResourceNotFoundError: |
| 181 |
ml_online_endpoint = None |
| 182 |
|
| 183 |
return ml_online_endpoint |
| 184 |
|
| 185 |
|
| 186 |
def main(): |
| 187 |
AzureRMMLOnlineEndpointInfo() |
| 188 |
|
| 189 |
|
| 190 |
if __name__ == '__main__': |
| 191 |
main() |