adding missing Azure facts modules (#54838)
This commit is contained in:
parent
ed1334fbe3
commit
62f4eb7053
4 changed files with 901 additions and 0 deletions
|
@ -0,0 +1,220 @@
|
|||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (c) 2019 Zim Kalinowski, (@zikalino)
|
||||
#
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: azure_rm_devtestlabcustomimage_facts
|
||||
version_added: "2.8"
|
||||
short_description: Get Azure DevTest Lab Custom Image facts.
|
||||
description:
|
||||
- Get facts of Azure Azure DevTest Lab Custom Image.
|
||||
|
||||
options:
|
||||
resource_group:
|
||||
description:
|
||||
- The name of the resource group.
|
||||
required: True
|
||||
lab_name:
|
||||
description:
|
||||
- The name of the lab.
|
||||
required: True
|
||||
name:
|
||||
description:
|
||||
- The name of the custom image.
|
||||
tags:
|
||||
description:
|
||||
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'.
|
||||
|
||||
extends_documentation_fragment:
|
||||
- azure
|
||||
|
||||
author:
|
||||
- "Zim Kalinowski (@zikalino)"
|
||||
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Get instance of Custom Image
|
||||
azure_rm_devtestlabcustomimage_facts:
|
||||
resource_group: myResourceGroup
|
||||
lab_name: myLab
|
||||
name: myImage
|
||||
|
||||
- name: List instances of Custom Image in the lab
|
||||
azure_rm_devtestlabcustomimage_facts:
|
||||
resource_group: myResourceGroup
|
||||
lab_name: myLab
|
||||
name: myImage
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
custom_images:
|
||||
description: A list of dictionaries containing facts for Custom Image.
|
||||
returned: always
|
||||
type: complex
|
||||
contains:
|
||||
id:
|
||||
description:
|
||||
- The identifier of the artifact source.
|
||||
returned: always
|
||||
type: str
|
||||
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.DevTestLab/labs/myLab/cu
|
||||
stomimages/myImage"
|
||||
resource_group:
|
||||
description:
|
||||
- Name of the resource group.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myResourceGroup
|
||||
lab_name:
|
||||
description:
|
||||
- Name of the lab.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myLab
|
||||
name:
|
||||
description:
|
||||
- The name of the image.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myImage
|
||||
managed_shapshot_id:
|
||||
description:
|
||||
- Managed snapshot id.
|
||||
returned: always
|
||||
type: str
|
||||
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourcegroups/myResourceGroup/providers/microsoft.compute/snapshots/myImage"
|
||||
source_vm_id:
|
||||
description:
|
||||
- Source VM id.
|
||||
returned: always
|
||||
type: str
|
||||
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx//resourcegroups/myResourceGroup/providers/microsoft.devtestlab/labs/myLab/v
|
||||
irtualmachines/myLabVm"
|
||||
tags:
|
||||
description:
|
||||
- The tags of the resource.
|
||||
returned: always
|
||||
type: complex
|
||||
sample: "{ 'MyTag': 'MyValue' }"
|
||||
'''
|
||||
|
||||
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
||||
|
||||
try:
|
||||
from msrestazure.azure_exceptions import CloudError
|
||||
from azure.mgmt.devtestlabs import DevTestLabsClient
|
||||
from msrest.serialization import Model
|
||||
except ImportError:
|
||||
# This is handled in azure_rm_common
|
||||
pass
|
||||
|
||||
|
||||
class AzureRMDtlCustomImageFacts(AzureRMModuleBase):
|
||||
def __init__(self):
|
||||
# define user inputs into argument
|
||||
self.module_arg_spec = dict(
|
||||
resource_group=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
lab_name=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
name=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
tags=dict(
|
||||
type='list'
|
||||
)
|
||||
)
|
||||
# store the results of the module operation
|
||||
self.results = dict(
|
||||
changed=False
|
||||
)
|
||||
self.mgmt_client = None
|
||||
self.resource_group = None
|
||||
self.lab_name = None
|
||||
self.name = None
|
||||
self.tags = None
|
||||
super(AzureRMDtlCustomImageFacts, self).__init__(self.module_arg_spec, supports_tags=False)
|
||||
|
||||
def exec_module(self, **kwargs):
|
||||
for key in self.module_arg_spec:
|
||||
setattr(self, key, kwargs[key])
|
||||
self.mgmt_client = self.get_mgmt_svc_client(DevTestLabsClient,
|
||||
base_url=self._cloud_environment.endpoints.resource_manager)
|
||||
|
||||
if self.name:
|
||||
self.results['custom_images'] = self.get()
|
||||
else:
|
||||
self.results['custom_images'] = self.list()
|
||||
return self.results
|
||||
|
||||
def get(self):
|
||||
response = None
|
||||
results = []
|
||||
try:
|
||||
response = self.mgmt_client.custom_images.get(resource_group_name=self.resource_group,
|
||||
lab_name=self.lab_name,
|
||||
name=self.name)
|
||||
self.log("Response : {0}".format(response))
|
||||
except CloudError as e:
|
||||
self.log('Could not get facts for Custom Image.')
|
||||
|
||||
if response and self.has_tags(response.tags, self.tags):
|
||||
results.append(self.format_response(response))
|
||||
|
||||
return results
|
||||
|
||||
def list(self):
|
||||
response = None
|
||||
results = []
|
||||
try:
|
||||
response = self.mgmt_client.custom_images.list(resource_group_name=self.resource_group,
|
||||
lab_name=self.lab_name)
|
||||
self.log("Response : {0}".format(response))
|
||||
except CloudError as e:
|
||||
self.log('Could not get facts for Custom Image.')
|
||||
|
||||
if response is not None:
|
||||
for item in response:
|
||||
if self.has_tags(item.tags, self.tags):
|
||||
results.append(self.format_response(item))
|
||||
|
||||
return results
|
||||
|
||||
def format_response(self, item):
|
||||
d = item.as_dict()
|
||||
d = {
|
||||
'resource_group': self.resource_group,
|
||||
'lab_name': self.lab_name,
|
||||
'name': d.get('name'),
|
||||
'id': d.get('id'),
|
||||
'managed_snapshot_id': d.get('managed_snapshot_id'),
|
||||
'source_vm_id': d.get('vm', {}).get('source_vm_id'),
|
||||
'tags': d.get('tags')
|
||||
}
|
||||
return d
|
||||
|
||||
|
||||
def main():
|
||||
AzureRMDtlCustomImageFacts()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,235 @@
|
|||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (c) 2019 Zim Kalinowski, (@zikalino)
|
||||
#
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: azure_rm_devtestlabenvironment_facts
|
||||
version_added: "2.8"
|
||||
short_description: Get Azure Environment facts.
|
||||
description:
|
||||
- Get facts of Azure Environment.
|
||||
|
||||
options:
|
||||
resource_group:
|
||||
description:
|
||||
- The name of the resource group.
|
||||
required: True
|
||||
lab_name:
|
||||
description:
|
||||
- The name of the lab.
|
||||
required: True
|
||||
user_name:
|
||||
description:
|
||||
- The name of the user profile.
|
||||
required: True
|
||||
name:
|
||||
description:
|
||||
- The name of the environment.
|
||||
tags:
|
||||
description:
|
||||
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'.
|
||||
|
||||
extends_documentation_fragment:
|
||||
- azure
|
||||
|
||||
author:
|
||||
- "Zim Kalinowski (@zikalino)"
|
||||
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Get instance of Environment
|
||||
azure_rm_devtestlabenvironment_facts:
|
||||
resource_group: myResourceGroup
|
||||
lab_name: myLab
|
||||
user_name: myUser
|
||||
name: myEnvironment
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
environments:
|
||||
description: A list of dictionaries containing facts for Environment.
|
||||
returned: always
|
||||
type: complex
|
||||
contains:
|
||||
id:
|
||||
description:
|
||||
- The identifier of the artifact source.
|
||||
returned: always
|
||||
type: str
|
||||
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.DevTestLab/labs/myLab/sc
|
||||
hedules/xxxxxxxx-xxxx-xxxx-xxxxx-xxxxxxxxxxxxx/environments/myEnvironment"
|
||||
resource_group:
|
||||
description:
|
||||
- Name of the resource group.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myResourceGroup
|
||||
lab_name:
|
||||
description:
|
||||
- Name of the lab.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myLab
|
||||
name:
|
||||
description:
|
||||
- The name of the environment.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myEnvironment
|
||||
deployment_template:
|
||||
description:
|
||||
- The identifier of the artifact source.
|
||||
returned: always
|
||||
type: str
|
||||
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/myResourceGroup/providers/microsoft.devtestlab/labs/mylab/art
|
||||
ifactSources/public environment repo/armTemplates/WebApp"
|
||||
resource_group_id:
|
||||
description:
|
||||
- Target resource group id.
|
||||
returned: always
|
||||
type: str
|
||||
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/myLab-myEnvironment-982571"
|
||||
state:
|
||||
description:
|
||||
- Deployment state.
|
||||
returned: always
|
||||
type: str
|
||||
sample: Succeeded
|
||||
tags:
|
||||
description:
|
||||
- The tags of the resource.
|
||||
returned: always
|
||||
type: complex
|
||||
sample: "{ 'MyTag': 'MyValue' }"
|
||||
'''
|
||||
|
||||
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
||||
|
||||
try:
|
||||
from msrestazure.azure_exceptions import CloudError
|
||||
from azure.mgmt.devtestlabs import DevTestLabsClient
|
||||
from msrest.serialization import Model
|
||||
except ImportError:
|
||||
# This is handled in azure_rm_common
|
||||
pass
|
||||
|
||||
|
||||
class AzureRMDtlEnvironmentFacts(AzureRMModuleBase):
|
||||
def __init__(self):
|
||||
# define user inputs into argument
|
||||
self.module_arg_spec = dict(
|
||||
resource_group=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
lab_name=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
user_name=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
name=dict(
|
||||
type='str'
|
||||
),
|
||||
tags=dict(
|
||||
type='list'
|
||||
)
|
||||
)
|
||||
# store the results of the module operation
|
||||
self.results = dict(
|
||||
changed=False
|
||||
)
|
||||
self.mgmt_client = None
|
||||
self.resource_group = None
|
||||
self.lab_name = None
|
||||
self.user_name = None
|
||||
self.name = None
|
||||
self.tags = None
|
||||
super(AzureRMDtlEnvironmentFacts, self).__init__(self.module_arg_spec, supports_tags=False)
|
||||
|
||||
def exec_module(self, **kwargs):
|
||||
for key in self.module_arg_spec:
|
||||
setattr(self, key, kwargs[key])
|
||||
self.mgmt_client = self.get_mgmt_svc_client(DevTestLabsClient,
|
||||
base_url=self._cloud_environment.endpoints.resource_manager)
|
||||
|
||||
if self.name:
|
||||
self.results['environments'] = self.get()
|
||||
else:
|
||||
self.results['environments'] = self.list()
|
||||
|
||||
return self.results
|
||||
|
||||
def get(self):
|
||||
response = None
|
||||
results = []
|
||||
try:
|
||||
response = self.mgmt_client.environments.get(resource_group_name=self.resource_group,
|
||||
lab_name=self.lab_name,
|
||||
user_name=self.user_name,
|
||||
name=self.name)
|
||||
self.log("Response : {0}".format(response))
|
||||
except CloudError as e:
|
||||
self.log('Could not get facts for Environment.')
|
||||
|
||||
if response and self.has_tags(response.tags, self.tags):
|
||||
results.append(self.format_response(response))
|
||||
|
||||
return results
|
||||
|
||||
def list(self):
|
||||
response = None
|
||||
results = []
|
||||
try:
|
||||
response = self.mgmt_client.environments.list(resource_group_name=self.resource_group,
|
||||
lab_name=self.lab_name,
|
||||
user_name=self.user_name)
|
||||
self.log("Response : {0}".format(response))
|
||||
except CloudError as e:
|
||||
self.log('Could not get facts for Environment.')
|
||||
|
||||
if response is not None:
|
||||
for item in response:
|
||||
if self.has_tags(item.tags, self.tags):
|
||||
results.append(self.format_response(item))
|
||||
|
||||
return results
|
||||
|
||||
def format_response(self, item):
|
||||
d = item.as_dict()
|
||||
d = {
|
||||
'resource_group': self.resource_group,
|
||||
'lab_name': self.lab_name,
|
||||
'name': d.get('name'),
|
||||
'user_name': self.user_name,
|
||||
'id': d.get('id', None),
|
||||
'deployment_template': d.get('deployment_properties', {}).get('arm_template_id'),
|
||||
'location': d.get('location'),
|
||||
'provisioning_state': d.get('provisioning_state'),
|
||||
'resource_group_id': d.get('resource_group_id'),
|
||||
'tags': d.get('tags', None)
|
||||
}
|
||||
return d
|
||||
|
||||
|
||||
def main():
|
||||
AzureRMDtlEnvironmentFacts()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,233 @@
|
|||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (c) 2019 Zim Kalinowski, (@zikalino)
|
||||
#
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: azure_rm_devtestlabpolicy_facts
|
||||
version_added: "2.8"
|
||||
short_description: Get Azure DTL Policy facts.
|
||||
description:
|
||||
- Get facts of Azure DTL Policy.
|
||||
|
||||
options:
|
||||
resource_group:
|
||||
description:
|
||||
- The name of the resource group.
|
||||
required: True
|
||||
lab_name:
|
||||
description:
|
||||
- The name of the lab.
|
||||
required: True
|
||||
policy_set_name:
|
||||
description:
|
||||
- The name of the policy set.
|
||||
required: True
|
||||
name:
|
||||
description:
|
||||
- The name of the policy.
|
||||
tags:
|
||||
description:
|
||||
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'.
|
||||
|
||||
extends_documentation_fragment:
|
||||
- azure
|
||||
|
||||
author:
|
||||
- "Zim Kalinowski (@zikalino)"
|
||||
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Get instance of Policy
|
||||
azure_rm_devtestlabpolicy_facts:
|
||||
resource_group: myResourceGroup
|
||||
lab_name: myLab
|
||||
policy_set_name: myPolicySet
|
||||
name: myPolicy
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
policies:
|
||||
description: A list of dictionaries containing facts for Policy.
|
||||
returned: always
|
||||
type: complex
|
||||
contains:
|
||||
id:
|
||||
description:
|
||||
- The identifier of the artifact source.
|
||||
returned: always
|
||||
type: str
|
||||
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.DevTestLab/labs/myLab/po
|
||||
licysets/myPolicySet/policies/myPolicy"
|
||||
resource_group:
|
||||
description:
|
||||
- Name of the resource group.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myResourceGroup
|
||||
lab_name:
|
||||
description:
|
||||
- Name of the lab.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myLab
|
||||
name:
|
||||
description:
|
||||
- The name of the artifact source.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myArtifactSource
|
||||
fact_name:
|
||||
description:
|
||||
- The name of the policy fact.
|
||||
returned: always
|
||||
type: str
|
||||
sample: UserOwnedLabVmCount
|
||||
evaluator_type:
|
||||
description:
|
||||
- Evaluator type for policy fact.
|
||||
returned: always
|
||||
type: str
|
||||
sample: MaxValuePolicy
|
||||
threshold:
|
||||
description:
|
||||
- Fact's threshold.
|
||||
returned: always
|
||||
type: str
|
||||
sample: 5
|
||||
tags:
|
||||
description:
|
||||
- The tags of the resource.
|
||||
returned: always
|
||||
type: complex
|
||||
sample: "{ 'MyTag': 'MyValue' }"
|
||||
'''
|
||||
|
||||
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
||||
|
||||
try:
|
||||
from msrestazure.azure_exceptions import CloudError
|
||||
from azure.mgmt.devtestlabs import DevTestLabsClient
|
||||
from msrest.serialization import Model
|
||||
except ImportError:
|
||||
# This is handled in azure_rm_common
|
||||
pass
|
||||
|
||||
|
||||
class AzureRMDtlPolicyFacts(AzureRMModuleBase):
|
||||
def __init__(self):
|
||||
# define user inputs into argument
|
||||
self.module_arg_spec = dict(
|
||||
resource_group=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
lab_name=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
policy_set_name=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
name=dict(
|
||||
type='str'
|
||||
),
|
||||
tags=dict(
|
||||
type='list'
|
||||
)
|
||||
)
|
||||
# store the results of the module operation
|
||||
self.results = dict(
|
||||
changed=False
|
||||
)
|
||||
self.mgmt_client = None
|
||||
self.resource_group = None
|
||||
self.lab_name = None
|
||||
self.policy_set_name = None
|
||||
self.name = None
|
||||
self.tags = None
|
||||
super(AzureRMDtlPolicyFacts, self).__init__(self.module_arg_spec, supports_tags=False)
|
||||
|
||||
def exec_module(self, **kwargs):
|
||||
for key in self.module_arg_spec:
|
||||
setattr(self, key, kwargs[key])
|
||||
self.mgmt_client = self.get_mgmt_svc_client(DevTestLabsClient,
|
||||
base_url=self._cloud_environment.endpoints.resource_manager)
|
||||
|
||||
if self.name:
|
||||
self.results['policies'] = self.get()
|
||||
else:
|
||||
self.results['policies'] = self.list()
|
||||
|
||||
return self.results
|
||||
|
||||
def get(self):
|
||||
response = None
|
||||
results = []
|
||||
try:
|
||||
response = self.mgmt_client.policies.get(resource_group_name=self.resource_group,
|
||||
lab_name=self.lab_name,
|
||||
policy_set_name=self.policy_set_name,
|
||||
name=self.name)
|
||||
self.log("Response : {0}".format(response))
|
||||
except CloudError as e:
|
||||
self.log('Could not get facts for Policy.')
|
||||
|
||||
if response and self.has_tags(response.tags, self.tags):
|
||||
results.append(self.format_response(response))
|
||||
|
||||
return results
|
||||
|
||||
def list(self):
|
||||
response = None
|
||||
results = []
|
||||
try:
|
||||
response = self.mgmt_client.policies.list(resource_group_name=self.resource_group,
|
||||
lab_name=self.lab_name,
|
||||
policy_set_name=self.policy_set_name)
|
||||
self.log("Response : {0}".format(response))
|
||||
except CloudError as e:
|
||||
self.log('Could not get facts for Policy.')
|
||||
|
||||
if response is not None:
|
||||
for item in response:
|
||||
if self.has_tags(item.tags, self.tags):
|
||||
results.append(self.format_response(item))
|
||||
|
||||
return results
|
||||
|
||||
def format_response(self, item):
|
||||
d = item.as_dict()
|
||||
d = {
|
||||
'resource_group': self.resource_group,
|
||||
'policy_set_name': self.policy_set_name,
|
||||
'name': d.get('name'),
|
||||
'id': d.get('id'),
|
||||
'tags': d.get('tags'),
|
||||
'status': d.get('status'),
|
||||
'threshold': d.get('threshold'),
|
||||
'fact_name': d.get('fact_name'),
|
||||
'evaluator_type': d.get('evaluator_type')
|
||||
}
|
||||
return d
|
||||
|
||||
|
||||
def main():
|
||||
AzureRMDtlPolicyFacts()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,213 @@
|
|||
#!/usr/bin/python
|
||||
#
|
||||
# Copyright (c) 2019 Zim Kalinowski, (@zikalino)
|
||||
#
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'community'}
|
||||
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: azure_rm_devtestlabschedule_facts
|
||||
version_added: "2.8"
|
||||
short_description: Get Azure Schedule facts.
|
||||
description:
|
||||
- Get facts of Azure Schedule.
|
||||
|
||||
options:
|
||||
resource_group:
|
||||
description:
|
||||
- The name of the resource group.
|
||||
required: True
|
||||
lab_name:
|
||||
description:
|
||||
- The name of the lab.
|
||||
required: True
|
||||
name:
|
||||
description:
|
||||
- The name of the schedule.
|
||||
tags:
|
||||
description:
|
||||
- Limit results by providing a list of tags. Format tags as 'key' or 'key:value'.
|
||||
|
||||
extends_documentation_fragment:
|
||||
- azure
|
||||
|
||||
author:
|
||||
- "Zim Kalinowski (@zikalino)"
|
||||
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
- name: Get instance of Schedule
|
||||
azure_rm_devtestlabschedule_facts:
|
||||
resource_group: myResourceGroup
|
||||
lab_name: myLab
|
||||
name: mySchedule
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
schedules:
|
||||
description: A list of dictionaries containing facts for Schedule.
|
||||
returned: always
|
||||
type: complex
|
||||
contains:
|
||||
id:
|
||||
description:
|
||||
- The identifier of the artifact source.
|
||||
returned: always
|
||||
type: str
|
||||
sample: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.DevTestLab/labs/myLab/sc
|
||||
hedules/labvmsshutdown"
|
||||
resource_group:
|
||||
description:
|
||||
- Name of the resource group.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myResourceGroup
|
||||
lab_name:
|
||||
description:
|
||||
- Name of the lab.
|
||||
returned: always
|
||||
type: str
|
||||
sample: myLab
|
||||
name:
|
||||
description:
|
||||
- The name of the environment.
|
||||
returned: always
|
||||
type: str
|
||||
sample: lab_vms_shutdown
|
||||
time:
|
||||
description:
|
||||
- Time of the schedule.
|
||||
returned: always
|
||||
type: str
|
||||
sample: lab_vms_shutdown
|
||||
time_zone_id:
|
||||
description:
|
||||
- Time zone id.
|
||||
returned: always
|
||||
type: str
|
||||
sample: UTC+12
|
||||
tags:
|
||||
description:
|
||||
- The tags of the resource.
|
||||
returned: always
|
||||
type: complex
|
||||
sample: "{ 'MyTag': 'MyValue' }"
|
||||
'''
|
||||
|
||||
from ansible.module_utils.azure_rm_common import AzureRMModuleBase
|
||||
from ansible.module_utils.common.dict_transformations import _camel_to_snake, _snake_to_camel
|
||||
|
||||
try:
|
||||
from msrestazure.azure_exceptions import CloudError
|
||||
from azure.mgmt.devtestlabs import DevTestLabsClient
|
||||
from msrest.serialization import Model
|
||||
except ImportError:
|
||||
# This is handled in azure_rm_common
|
||||
pass
|
||||
|
||||
|
||||
class AzureRMDtlScheduleFacts(AzureRMModuleBase):
|
||||
def __init__(self):
|
||||
# define user inputs into argument
|
||||
self.module_arg_spec = dict(
|
||||
resource_group=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
lab_name=dict(
|
||||
type='str',
|
||||
required=True
|
||||
),
|
||||
name=dict(
|
||||
type='str'
|
||||
),
|
||||
tags=dict(
|
||||
type='list'
|
||||
)
|
||||
)
|
||||
# store the results of the module operation
|
||||
self.results = dict(
|
||||
changed=False
|
||||
)
|
||||
self.mgmt_client = None
|
||||
self.resource_group = None
|
||||
self.lab_name = None
|
||||
self.name = None
|
||||
self.tags = None
|
||||
super(AzureRMDtlScheduleFacts, self).__init__(self.module_arg_spec, supports_tags=False)
|
||||
|
||||
def exec_module(self, **kwargs):
|
||||
for key in self.module_arg_spec:
|
||||
setattr(self, key, kwargs[key])
|
||||
self.mgmt_client = self.get_mgmt_svc_client(DevTestLabsClient,
|
||||
base_url=self._cloud_environment.endpoints.resource_manager)
|
||||
if self.name:
|
||||
self.results['schedules'] = self.get()
|
||||
else:
|
||||
self.results['schedules'] = self.list()
|
||||
|
||||
return self.results
|
||||
|
||||
def get(self):
|
||||
response = None
|
||||
results = []
|
||||
try:
|
||||
response = self.mgmt_client.schedules.get(resource_group_name=self.resource_group,
|
||||
lab_name=self.lab_name,
|
||||
name=_snake_to_camel(self.name))
|
||||
self.log("Response : {0}".format(response))
|
||||
except CloudError as e:
|
||||
self.log('Could not get facts for Schedule.')
|
||||
|
||||
if response and self.has_tags(response.tags, self.tags):
|
||||
results.append(self.format_response(response))
|
||||
|
||||
return results
|
||||
|
||||
def list(self):
|
||||
response = None
|
||||
results = []
|
||||
try:
|
||||
response = self.mgmt_client.schedules.list(resource_group_name=self.resource_group,
|
||||
lab_name=self.lab_name)
|
||||
self.log("Response : {0}".format(response))
|
||||
except CloudError as e:
|
||||
self.log('Could not get facts for Schedule.')
|
||||
|
||||
if response is not None:
|
||||
for item in response:
|
||||
if self.has_tags(item.tags, self.tags):
|
||||
results.append(self.format_response(item))
|
||||
|
||||
return results
|
||||
|
||||
def format_response(self, item):
|
||||
d = item.as_dict()
|
||||
d = {
|
||||
'resource_group': self.resource_group,
|
||||
'lab_name': self.lab_name,
|
||||
'name': _camel_to_snake(d.get('name')),
|
||||
'id': d.get('id', None),
|
||||
'tags': d.get('tags', None),
|
||||
'time': d.get('daily_recurrence', {}).get('time'),
|
||||
'time_zone_id': d.get('time_zone_id')
|
||||
}
|
||||
return d
|
||||
|
||||
|
||||
def main():
|
||||
AzureRMDtlScheduleFacts()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in a new issue