reviewable/pr18780/r1
James Tanner 8 years ago
parent 07fb05a852
commit 5d2d0e0045

@ -309,28 +309,25 @@ class PyVmomiHelper(object):
def set_powerstate(self, vm, state, force): def set_powerstate(self, vm, state, force):
""" """
Set the power status for a VM determined by the current and Set the power status for a VM determined by the current and
requested states. force is forceful requested states. force is forceful
""" """
facts = self.gather_facts(vm) facts = self.gather_facts(vm)
expected_state = state.replace('_', '').lower() expected_state = state.replace('_', '').lower()
current_state = facts['hw_power_status'].lower() current_state = facts['hw_power_status'].lower()
result = {} result = {}
# Need Force # Need Force
if not force and current_state not in ['poweredon', 'poweredoff']: if not force and current_state not in ['poweredon', 'poweredoff']:
return "VM is in %s power state. Force is required!" % current_state return "VM is in %s power state. Force is required!" % current_state
# State is already true # State is already true
if current_state == expected_state: if current_state == expected_state:
result['changed'] = False result['changed'] = False
result['failed'] = False result['failed'] = False
else:
else:
task = None task = None
try: try:
if expected_state == 'poweredoff': if expected_state == 'poweredoff':
task = vm.PowerOff() task = vm.PowerOff()
@ -387,9 +384,6 @@ class PyVmomiHelper(object):
mac = device.macAddress mac = device.macAddress
ips = list(device.ipAddress) ips = list(device.ipAddress)
netDict[mac] = ips netDict[mac] = ips
#facts['network'] = {}
#facts['network']['ipaddress_v4'] = None
#facts['network']['ipaddress_v6'] = None
for k,v in netDict.iteritems(): for k,v in netDict.iteritems():
for ipaddress in v: for ipaddress in v:
if ipaddress: if ipaddress:
@ -398,23 +392,21 @@ class PyVmomiHelper(object):
else: else:
facts['ipv4'] = ipaddress facts['ipv4'] = ipaddress
for idx,entry in enumerate(vm.config.hardware.device): for idx,entry in enumerate(vm.config.hardware.device):
if not hasattr(entry, 'macAddress'):
continue
factname = 'hw_eth' + str(idx)
facts[factname] = {
'addresstype': entry.addressType,
'label': entry.deviceInfo.label,
'macaddress': entry.macAddress,
'ipaddresses': netDict.get(entry.macAddress, None),
'macaddress_dash': entry.macAddress.replace(':', '-'),
'summary': entry.deviceInfo.summary,
}
facts['hw_interfaces'].append('eth'+str(idx))
if not hasattr(entry, 'macAddress'):
continue
factname = 'hw_eth' + str(idx)
facts[factname] = {
'addresstype': entry.addressType,
'label': entry.deviceInfo.label,
'macaddress': entry.macAddress,
'ipaddresses': netDict.get(entry.macAddress, None),
'macaddress_dash': entry.macAddress.replace(':', '-'),
'summary': entry.deviceInfo.summary,
}
facts['hw_interfaces'].append('eth'+str(idx))
#import epdb; epdb.st()
return facts return facts

Loading…
Cancel
Save