Remove differences from output. Make options declarative.
This commit is contained in:
parent
ae30540ca2
commit
f09b7b02d6
1 changed files with 27 additions and 32 deletions
|
@ -47,30 +47,30 @@ options:
|
||||||
description:
|
description:
|
||||||
- Assert the state of the virtual machine.
|
- Assert the state of the virtual machine.
|
||||||
- State 'present' will check that the machine exists with the requested configuration. If the configuration
|
- State 'present' will check that the machine exists with the requested configuration. If the configuration
|
||||||
of the existing machine does not match, the machine will be updated. Use options start, stop,
|
of the existing machine does not match, the machine will be updated. Use options started, stopped,
|
||||||
deallocate and restart to change the machine's power state.
|
deallocated and restarted to change the machine's power state.
|
||||||
- State 'absent' will remove the virtual machine.
|
- State 'absent' will remove the virtual machine.
|
||||||
default: present
|
default: present
|
||||||
required: false
|
required: false
|
||||||
choices:
|
choices:
|
||||||
- absent
|
- absent
|
||||||
- present
|
- present
|
||||||
start:
|
started:
|
||||||
description:
|
description:
|
||||||
- Use with state 'present' to start the machine.
|
- Use with state 'present' to start the machine.
|
||||||
default: true
|
default: true
|
||||||
required: false
|
required: false
|
||||||
stop:
|
stopped:
|
||||||
description:
|
description:
|
||||||
- Use with state 'present' to stop the machine.
|
- Use with state 'present' to stop the machine.
|
||||||
default: false
|
default: false
|
||||||
required: false
|
required: false
|
||||||
deallocate:
|
deallocated:
|
||||||
description:
|
description:
|
||||||
- Use with state 'present' to put the VM in a deallocated state.
|
- Use with state 'present' to put the VM in a deallocated state.
|
||||||
default: false
|
default: false
|
||||||
required: false
|
required: false
|
||||||
restart:
|
restarted:
|
||||||
description:
|
description:
|
||||||
- Use with state 'present' to restart a running VM.
|
- Use with state 'present' to restart a running VM.
|
||||||
default: false
|
default: false
|
||||||
|
@ -283,13 +283,13 @@ EXAMPLES = '''
|
||||||
azure_rm_virtualmachine:
|
azure_rm_virtualmachine:
|
||||||
resource_group: Testing
|
resource_group: Testing
|
||||||
name: testvm002
|
name: testvm002
|
||||||
stop: yes
|
stopped: yes
|
||||||
|
|
||||||
- name: Deallocate
|
- name: Deallocate
|
||||||
azure_rm_virtualmachine:
|
azure_rm_virtualmachine:
|
||||||
resource_group: Testing
|
resource_group: Testing
|
||||||
name: testvm002
|
name: testvm002
|
||||||
deallocate: yes
|
deallocated: yes
|
||||||
|
|
||||||
- name: Power On
|
- name: Power On
|
||||||
azure_rm_virtualmachine:
|
azure_rm_virtualmachine:
|
||||||
|
@ -300,7 +300,7 @@ EXAMPLES = '''
|
||||||
azure_rm_virtualmachine:
|
azure_rm_virtualmachine:
|
||||||
resource_group:
|
resource_group:
|
||||||
name: testvm002
|
name: testvm002
|
||||||
restart: yes
|
restarted: yes
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -312,11 +312,6 @@ actions:
|
||||||
sample: [
|
sample: [
|
||||||
"Powered on virtual machine testvm10"
|
"Powered on virtual machine testvm10"
|
||||||
]
|
]
|
||||||
differences:
|
|
||||||
description: List of differences between the requested configuration and actual VM configuration.
|
|
||||||
returned: always
|
|
||||||
type: list
|
|
||||||
sample: []
|
|
||||||
powerstate:
|
powerstate:
|
||||||
description: Indicates if the state is running, stopped, deallocated
|
description: Indicates if the state is running, stopped, deallocated
|
||||||
returned: always
|
returned: always
|
||||||
|
@ -517,10 +512,10 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
delete_public_ips=dict(type='bool', default=True),
|
delete_public_ips=dict(type='bool', default=True),
|
||||||
virtual_network_name=dict(type='str', aliases=['virtual_network']),
|
virtual_network_name=dict(type='str', aliases=['virtual_network']),
|
||||||
subnet_name=dict(type='str', aliases=['subnet']),
|
subnet_name=dict(type='str', aliases=['subnet']),
|
||||||
deallocate=dict(type='bool', default=False),
|
deallocated=dict(type='bool', default=False),
|
||||||
restart=dict(type='bool', default=False),
|
restarted=dict(type='bool', default=False),
|
||||||
start=dict(type='bool', default=True),
|
started=dict(type='bool', default=True),
|
||||||
stop=dict(type='bool', default=False),
|
stopped=dict(type='bool', default=False),
|
||||||
)
|
)
|
||||||
|
|
||||||
for key in VirtualMachineSizeTypes:
|
for key in VirtualMachineSizeTypes:
|
||||||
|
@ -552,15 +547,15 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
self.open_ports = None
|
self.open_ports = None
|
||||||
self.virtual_network_name = None
|
self.virtual_network_name = None
|
||||||
self.subnet_name = None
|
self.subnet_name = None
|
||||||
self.deallocate = None
|
self.deallocated = None
|
||||||
self.restart = None
|
self.restarted = None
|
||||||
self.start = None
|
self.started = None
|
||||||
self.stop = None
|
self.stopped = None
|
||||||
|
self.differences = None
|
||||||
|
|
||||||
self.results = dict(
|
self.results = dict(
|
||||||
changed=False,
|
changed=False,
|
||||||
actions=[],
|
actions=[],
|
||||||
differences=None,
|
|
||||||
powerstate_change=None,
|
powerstate_change=None,
|
||||||
state=dict()
|
state=dict()
|
||||||
)
|
)
|
||||||
|
@ -671,27 +666,27 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
changed = True
|
changed = True
|
||||||
vm_dict['properties']['osProfile']['computerName'] = self.short_hostname
|
vm_dict['properties']['osProfile']['computerName'] = self.short_hostname
|
||||||
|
|
||||||
self.results['differences'] = differences
|
if self.started and vm_dict['powerstate'] != 'running':
|
||||||
|
|
||||||
if self.start and vm_dict['powerstate'] != 'running':
|
|
||||||
self.log("CHANGED: virtual machine {0} not running and requested state 'running'".format(self.name))
|
self.log("CHANGED: virtual machine {0} not running and requested state 'running'".format(self.name))
|
||||||
changed = True
|
changed = True
|
||||||
powerstate_change = 'poweron'
|
powerstate_change = 'poweron'
|
||||||
elif self.state == 'present' and vm_dict['powerstate'] == 'running' and self.restart:
|
elif self.state == 'present' and vm_dict['powerstate'] == 'running' and self.restarted:
|
||||||
self.log("CHANGED: virtual machine {0} {1} and requested state 'restarted'"
|
self.log("CHANGED: virtual machine {0} {1} and requested state 'restarted'"
|
||||||
.format(self.name, vm_dict['powerstate']))
|
.format(self.name, vm_dict['powerstate']))
|
||||||
changed = True
|
changed = True
|
||||||
powerstate_change = 'restarted'
|
powerstate_change = 'restarted'
|
||||||
elif self.state == 'present' and self.deallocate and vm_dict['powerstate'] != 'deallocated':
|
elif self.state == 'present' and self.deallocated and vm_dict['powerstate'] != 'deallocated':
|
||||||
self.log("CHANGED: virtual machine {0} {1} and requested state 'deallocated'"
|
self.log("CHANGED: virtual machine {0} {1} and requested state 'deallocated'"
|
||||||
.format(self.name, vm_dict['powerstate']))
|
.format(self.name, vm_dict['powerstate']))
|
||||||
changed = True
|
changed = True
|
||||||
powerstate_change = 'deallocated'
|
powerstate_change = 'deallocated'
|
||||||
elif self.stop and vm_dict['powerstate'] == 'running':
|
elif self.stopped and vm_dict['powerstate'] == 'running':
|
||||||
self.log("CHANGED: virtual machine {0} running and requested state 'stopped'".format(self.name))
|
self.log("CHANGED: virtual machine {0} running and requested state 'stopped'".format(self.name))
|
||||||
changed = True
|
changed = True
|
||||||
powerstate_change = 'poweroff'
|
powerstate_change = 'poweroff'
|
||||||
|
|
||||||
|
self.differences = differences
|
||||||
|
|
||||||
elif self.state == 'absent':
|
elif self.state == 'absent':
|
||||||
self.log("CHANGED: virtual machine {0} exists and requested state is 'absent'".format(self.name))
|
self.log("CHANGED: virtual machine {0} exists and requested state is 'absent'".format(self.name))
|
||||||
results = dict()
|
results = dict()
|
||||||
|
@ -699,8 +694,8 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
|
|
||||||
except CloudError:
|
except CloudError:
|
||||||
self.log('Virtual machine {0} does not exist'.format(self.name))
|
self.log('Virtual machine {0} does not exist'.format(self.name))
|
||||||
if self.state in ('present', 'started', 'stopped'):
|
if self.state == 'present':
|
||||||
self.log("CHANGED: virtual machine does not exist but state in ('present','started','stopped')" \
|
self.log("CHANGED: virtual machine does not exist but state is present." \
|
||||||
.format(self.name))
|
.format(self.name))
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
@ -797,7 +792,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
self.log(self.serialize_obj(vm_resource, 'VirtualMachine'), pretty_print=True)
|
self.log(self.serialize_obj(vm_resource, 'VirtualMachine'), pretty_print=True)
|
||||||
self.results['state'] = self.create_or_update_vm(vm_resource)
|
self.results['state'] = self.create_or_update_vm(vm_resource)
|
||||||
|
|
||||||
elif self.results['differences'] and len(self.results['differences']) > 0:
|
elif self.differences and len(self.differences) > 0:
|
||||||
# Update the VM based on detected config differences
|
# Update the VM based on detected config differences
|
||||||
|
|
||||||
self.log("Update virtual machine {0}".format(self.name))
|
self.log("Update virtual machine {0}".format(self.name))
|
||||||
|
|
Loading…
Reference in a new issue