1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Virtual machine facts - retrieving instance view (#45128)

This commit is contained in:
Zim Kalinowski 2018-09-04 11:25:01 +08:00 committed by Yunge Zhu
parent 9bd702ef37
commit 1f8635fbd9
5 changed files with 26 additions and 4 deletions

View file

@ -207,7 +207,7 @@ AZURE_PKG_VERSIONS = {
},
'ComputeManagementClient': {
'package_name': 'compute',
'expected_version': '2.1.0'
'expected_version': '3.0.0'
},
'ContainerInstanceManagementClient': {
'package_name': 'containerinstance',

View file

@ -181,6 +181,11 @@ vms:
- Virtual machine size.
type: str
sample: Standard_D4
power_state:
description:
- Power state of the virtual machine.
type: str
sample: running
'''
try:
@ -286,10 +291,25 @@ class AzureRMVirtualMachineFacts(AzureRMModuleBase):
'''
result = self.serialize_obj(vm, AZURE_OBJECT_CLASS, enum_modules=AZURE_ENUM_MODULES)
resource_group = re.sub('\\/.*', '', re.sub('.*resourceGroups\\/', '', result['id']))
instance = None
power_state = None
try:
instance = self.compute_client.virtual_machines.instance_view(resource_group, vm.name)
instance = self.serialize_obj(instance, AZURE_OBJECT_CLASS, enum_modules=AZURE_ENUM_MODULES)
except Exception as exc:
self.fail("Error getting virtual machine {0} instance view - {1}".format(vm.name, str(exc)))
for index in range(len(instance['statuses'])):
code = instance['statuses'][index]['code'].split('/')
if code[0] == 'PowerState':
power_state = code[1]
new_result = {}
new_result['power_state'] = power_state
new_result['id'] = vm.id
new_result['resource_group'] = re.sub('\\/.*', '', re.sub('.*resourceGroups\\/', '', result['id']))
new_result['resource_group'] = resource_group
new_result['name'] = vm.name
new_result['state'] = 'present'
new_result['location'] = vm.location

View file

@ -4,7 +4,7 @@ azure-cli-core==2.0.35
azure-cli-nspkg==3.0.2
azure-common==1.1.11
azure-mgmt-batch==4.1.0
azure-mgmt-compute==2.1.0
azure-mgmt-compute==3.0.0
azure-mgmt-containerinstance==0.4.0
azure-mgmt-containerregistry==2.0.0
azure-mgmt-containerservice==3.0.1

View file

@ -352,6 +352,8 @@
- results.vms[0].name == "{{ vm_name2 }}"
- results.vms[0].location == 'eastus'
- results.vms[0].admin_username == 'adminuser'
- results.vms[0].resource_group == "{{ resource_group }}"
- results.vms[0].power_state != None
- name: Should be idempotent with a dual NICs
azure_rm_virtualmachine:

View file

@ -4,7 +4,7 @@ azure-cli-core==2.0.35
azure-cli-nspkg==3.0.2
azure-common==1.1.11
azure-mgmt-batch==4.1.0
azure-mgmt-compute==2.1.0
azure-mgmt-compute==3.0.0
azure-mgmt-containerinstance==0.4.0
azure-mgmt-containerregistry==2.0.0
azure-mgmt-containerservice==3.0.1