mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #2 from rmgoodberlet/vmware-cloud-driver
Adding vm_tools_upgrade() to be able to upgrade vmware tools on a specified vm.
This commit is contained in:
commit
a59417d6d2
@ -1566,3 +1566,73 @@ def create_cluster(kwargs=None, call=None):
|
||||
return {cluster_name: 'created'}
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def vm_tools_upgrade(vm_name, reboot=False, call=None):
|
||||
'''
|
||||
To check status and upgrade VMware Tools on a VM using vm name.
|
||||
Default is ``reboot=False`` which attempts to suppress the reboot
|
||||
on Windows VMs. Use ``reboot=True`` to override.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt-cloud -a vm_tools_upgrade vmname
|
||||
salt-cloud -a vm_tools_upgrade vmname reboot=True
|
||||
'''
|
||||
if call != 'action':
|
||||
raise SaltCloudSystemExit(
|
||||
'The start action must be called with -a or --action.'
|
||||
)
|
||||
|
||||
vm = _get_mor_by_property(vim.VirtualMachine, vm_name)
|
||||
|
||||
# Check if VM is powered on and vmware tools is up to date.
|
||||
if vm.summary.runtime.powerState == "poweredOn":
|
||||
if vm.guest.toolsStatus == "toolsOk":
|
||||
ret = 'VMware tools is up to date.'
|
||||
log.info('VM {0} {1}'.format(vm_name, ret))
|
||||
return ret
|
||||
|
||||
# If vmware tools is out of date, check major OS family.
|
||||
# Upgrade tools on Linux guests.
|
||||
elif vm.guest.toolsStatus == "toolsOld":
|
||||
if vm.guest.guestFamily == "linuxGuest":
|
||||
try:
|
||||
log.info('Upgrading VMware tools on {0}'.format(vm_name))
|
||||
task = vm.UpgradeTools()
|
||||
_wait_for_task(task, vm_name, "Upgrade tools", 5, "info")
|
||||
except Exception as exc:
|
||||
log.error('Could not upgrade VMware tools on VM {0}: {1}'.format(vm_name, exc))
|
||||
return 'failed to upgrade VMware tools'
|
||||
|
||||
# If Windows, check if reboot is true.
|
||||
elif vm.guest.guestFamily == "windowsGuest":
|
||||
if reboot:
|
||||
try:
|
||||
log.info('Upgrading VMware tools on {0}'.format(vm_name))
|
||||
task = vm.UpgradeTools()
|
||||
_wait_for_task(task, vm_name, "Upgrade tools", 5, "info")
|
||||
except Exception as exc:
|
||||
log.error('Could not upgrade VMware tools on VM {0}: {1}'.format(vm_name, exc))
|
||||
return 'failed to upgrade VMware tools'
|
||||
|
||||
# If reboot is false, upgrade tools while supressing the reboot.
|
||||
else:
|
||||
try:
|
||||
log.info('Upgrading VMware tools on {0}'.format(vm_name))
|
||||
task = vm.UpgradeTools('/S /v"/qn REBOOT=R"')
|
||||
_wait_for_task(task, vm_name, "Upgrade tools", 5, "info")
|
||||
except Exception as exc:
|
||||
log.error('Could not upgrade VMware tools on VM {0}: {1}'.format(vm_name, exc))
|
||||
return 'failed to upgrade VMware tools'
|
||||
|
||||
return 'VMware tools upgraded'
|
||||
|
||||
# If vm is powered off, exit.
|
||||
elif vm.summary.runtime.powerState == "poweredOff":
|
||||
ret = 'Tools cannot be upgraded on powered off VMs.'
|
||||
log.info('VM {0} {1}'.format(vm_name, ret))
|
||||
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user