Skip to content

Commit

Permalink
Merged changes of Azure modules from Ansible repo (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleazurebot authored and yuwzho committed Apr 18, 2019
1 parent ff8a2b6 commit ebf3494
Show file tree
Hide file tree
Showing 36 changed files with 1,996 additions and 102 deletions.
4 changes: 2 additions & 2 deletions files/sha.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lib/ansible/module_utils/azure_rm_common.py": "8b1b22ddc7dad0d901ecbd96a982e34429bdfdb9",
"lib/ansible/modules/cloud/azure": "44c2061c708ca16cebcfbf4fa60a4c73cb86b630",
"lib/ansible/modules/cloud/azure": "22f666c9620396fb1ff7f4559b91182674e99008",
"packaging/requirements/requirements-azure.txt": "8b1b22ddc7dad0d901ecbd96a982e34429bdfdb9",
"test/integration/targets": "025e9afe58fd2688ed4978f4710c795fcfdfd912"
"test/integration/targets": "dcbfa60413ece9d3e68fa44fa303a79003bbec75"
}
6 changes: 3 additions & 3 deletions library/azure_rm_aks.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
EXAMPLES = '''
- name: Create a managed Azure Container Services (AKS) instance
azure_rm_aks:
name: acctestaks1
name: myAKS
location: eastus
resource_group: myResourceGroup
dns_prefix: akstest
Expand All @@ -222,7 +222,7 @@
- name: Remove a managed Azure Container Services (AKS) instance
azure_rm_aks:
name: acctestaks3
name: myAKS
resource_group: myResourceGroup
state: absent
'''
Expand All @@ -244,7 +244,7 @@
vnet_subnet_id: Null
changed: false
dns_prefix: aks9860bdcd89
id: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/yuwzhoaks/providers/Microsoft.ContainerService/managedClusters/aks9860bdc"
id: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/myResourceGroup/providers/Microsoft.ContainerService/managedClusters/aks9860bdc"
kube_config: "......"
kubernetes_version: 1.11.4
linux_profile:
Expand Down
2 changes: 1 addition & 1 deletion library/azure_rm_appgateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
- name: Create instance of Application Gateway
azure_rm_appgateway:
resource_group: myResourceGroup
name: myappgateway
name: myAppGateway
sku:
name: standard_small
tier: standard
Expand Down
2 changes: 1 addition & 1 deletion library/azure_rm_appserviceplan_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
- name: Get facts for app service plan by name
azure_rm_appserviceplan_facts:
resource_group: myResourceGroup
name: winwebapp1
name: myAppServicePlan
- name: Get azure_rm_appserviceplan_facts for app service plan in resource group
azure_rm_webapp_facts:
Expand Down
6 changes: 3 additions & 3 deletions library/azure_rm_availabilityset.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@
EXAMPLES = '''
- name: Create an availability set with default options
azure_rm_availabilityset:
name: myavailabilityset
name: myAvailabilitySet
location: eastus
resource_group: myResourceGroup
- name: Create an availability set with advanced options
azure_rm_availabilityset:
name: myavailabilityset
name: myAvailabilitySet
location: eastus
resource_group: myResourceGroup
platform_update_domain_count: 5
Expand All @@ -85,7 +85,7 @@
- name: Delete an availability set
azure_rm_availabilityset:
name: myavailabilityset
name: myAvailabilitySet
location: eastus
resource_group: myResourceGroup
state: absent
Expand Down
2 changes: 1 addition & 1 deletion library/azure_rm_availabilityset_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
type: list
example: [{
"location": "eastus2",
"name": "myavailabilityset",
"name": "myAvailabilitySet",
"properties": {
"platformFaultDomainCount": 3,
"platformUpdateDomainCount": 2,
Expand Down
6 changes: 3 additions & 3 deletions library/azure_rm_cdnprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@
- name: Create a CDN profile
azure_rm_cdnprofile:
resource_group: myResourceGroup
name: cdntest
name: myCDN
sku: standard_akamai
tags:
testing: testing
- name: Delete the CDN profile
azure_rm_cdnprofile:
resource_group: myResourceGroup
name: cdntest
name: myCDN
state: absent
'''
RETURN = '''
Expand All @@ -80,7 +80,7 @@
returned: always
type: dict
example:
id: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/cdntest/providers/Microsoft.Cdn/profiles/cdntest
id: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/myResourceGroup/providers/Microsoft.Cdn/profiles/myCDN
'''
from ansible.module_utils.azure_rm_common import AzureRMModuleBase

Expand Down
2 changes: 1 addition & 1 deletion library/azure_rm_cdnprofile_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
description:
- ID of the CDN profile.
type: str
sample: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/myResourceGroup/providers/Microsoft.Cdn/profiles/cdntest
sample: /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/myResourceGroup/providers/Microsoft.Cdn/profiles/myCDN
provisioning_state:
description:
- Provisioning status of the profile.
Expand Down
4 changes: 2 additions & 2 deletions library/azure_rm_containerinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@
- name: Create sample container group
azure_rm_containerinstance:
resource_group: myResourceGroup
name: mynewcontainergroup
name: myContainerInstanceGroup
os_type: linux
ip_address: public
containers:
- name: mycontainer1
- name: myContainer1
image: httpd
memory: 1.5
ports:
Expand Down
2 changes: 1 addition & 1 deletion library/azure_rm_containerinstance_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
- name: Get specific Container Instance facts
azure_rm_containerinstance_facts:
resource_group: myResourceGroup
name: container_group_name
name: myContainer
- name: List Container Instances in a specified resource group name
azure_rm_containerinstance_facts:
Expand Down
4 changes: 2 additions & 2 deletions library/azure_rm_containerregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
EXAMPLES = '''
- name: Create an azure container registry
azure_rm_containerregistry:
name: testacr1
name: myRegistry
location: eastus
resource_group: myResourceGroup
admin_user_enabled: true
Expand All @@ -75,7 +75,7 @@
- name: Remove an azure container registry
azure_rm_containerregistry:
name: testacr2
name: myRegistry
resource_group: myResourceGroup
state: absent
'''
Expand Down
2 changes: 1 addition & 1 deletion library/azure_rm_containerregistry_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
- name: Get instance of Registry
azure_rm_containerregistry_facts:
resource_group: myResourceGroup
name: sampleregistry
name: myRegistry
- name: List instances of Registry
azure_rm_containerregistry_facts:
Expand Down
220 changes: 220 additions & 0 deletions library/azure_rm_devtestlabcustomimage_facts.py
Original file line number Diff line number Diff line change
@@ -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()
Loading

0 comments on commit ebf3494

Please sign in to comment.