예제 #1
0
def run(job, logger=None, server=None, **kwargs):

    si = None
    for server in job.server_set.all():
        if not si:
            si = get_vmware_service_instance(server.resource_handler.cast())
        vm = get_vm_by_uuid(si, server.resource_handler_svr_id)

        assert isinstance(vm, pyVmomi.vim.VirtualMachine)

        server.refresh_info()

        server_original_power_status = server.power_status
        set_progress("Performing VM hard reset...")
        task = vm.ResetVM_Task()
        wait_for_tasks(si, [task])

    return "", "", ""
def run(job, logger=None, server=None, **kwargs):

    si = None
    for server in job.server_set.all():
        if not si:
            si = get_vmware_service_instance(server.resource_handler.cast())
        vm = get_vm_by_uuid(si, server.resource_handler_svr_id)

        assert isinstance(vm, pyVmomi.vim.VirtualMachine)

        server.refresh_info()

        server_original_power_status = server.power_status
        set_progress("Performing VM power down...")
        task = vm.PowerOffVM_Task()
        wait_for_tasks(si, [task])

    return "", "", ""
예제 #3
0
def check_task(si, task):
    wait_for_tasks(si, [task], timeout=3600)
    task_info = task.info
    uuid = task_info.result.config.uuid
    return uuid
def run(job, logger=None, server=None, **kwargs):

    si = None
    for server in job.server_set.all():
        if not si:
            si = get_vmware_service_instance(server.resource_handler.cast())
        vm = get_vm_by_uuid(si, server.resource_handler_svr_id)

        assert isinstance(vm, pyVmomi.vim.VirtualMachine)

        if vm.config.version == "vmx-08":
            set_progress("Hardware version already updated. Nothing to do.")
            continue

        server.refresh_info()

        server_original_power_status = server.power_status
        if server_original_power_status != "POWERON":
            set_progress(
                "Server is off. Turning it on to upgrade VMware Tools.")
            # Make sure VM is powered on
            task = vm.PowerOnVM_Task()
            wait_for_tasks(si, [task])

        set_progress("Upgrading VMware Tools")
        # Upgrade VMware tools
        try:
            task = vm.UpgradeTools_Task()
            wait_for_tasks(si, [task])
        except:
            set_progress(
                "Cannot upgrade VM tools. Will still try to upgrade hardware version. "
            )
            pass

        # Power off VM for hw upgrade
        set_progress("Powering off server to upgrade HW version")
        task = vm.PowerOffVM_Task()
        wait_for_tasks(si, [task])

        # Snapshot VM
        set_progress("Creating snapshot")
        #server.resource_handler.cast().create_snapshot(server, "version4hw-{}".format(time.time()), "Pre Hardware Upgrade Snapshot")

        task = vm.CreateSnapshot_Task("version4hw-{}".format(time.time()),
                                      "Pre Hardware Upgrade Snapshot", False,
                                      True)
        wait_for_tasks(si, [task])

        failure_msg = ""

        # Upgrade VM
        try:
            set_progress("Updating HW version")
            task = vm.UpgradeVM_Task(version="vmx-08")
            wait_for_tasks(si, [task])
        except:
            failure_msg = "Failed to upgrade hardware version"
            set_progress(
                "{}. Will now return VM to original power state.".format(
                    failure_msg))
            pass

        if server_original_power_status == "POWERON":
            set_progress("Server was originally on, so power it on again")
            task = vm.PowerOnVM_Task()
            wait_for_tasks(si, [task])

        if failure_msg:
            return "FAILURE", "", failure_msg

        return "", "", ""

    return "", "", ""
def run(job, logger=None, server=None, **kwargs):

    si = None
    for server in job.server_set.all():
        if not si:
            si = get_vmware_service_instance(server.resource_handler.cast())
        vm = get_vm_by_uuid(si, server.resource_handler_svr_id)
    
        assert isinstance(vm, pyVmomi.vim.VirtualMachine)
        
        if vm.config.version == "vmx-08":
            set_progress("Hardware version already updated. Nothing to do.")
            continue
        
        server.refresh_info()

        server_original_power_status = server.power_status
        if server_original_power_status != "POWERON":
            set_progress("Server is off. Turning it on to upgrade VMware Tools.")
            # Make sure VM is powered on
            task = vm.PowerOnVM_Task()
            wait_for_tasks(si, [task])

        set_progress("Upgrading VMware Tools")
        # Upgrade VMware tools
        try:
            task = vm.UpgradeTools_Task()
            wait_for_tasks(si, [task])
        except:
            set_progress("Cannot upgrade VM tools. Will still try to upgrade hardware version. ")
            pass
            
        
        # Power off VM for hw upgrade
        set_progress("Powering off server to upgrade HW version")
        task = vm.PowerOffVM_Task()
        wait_for_tasks(si, [task])

        # Snapshot VM
        set_progress("Creating snapshot")
        #server.resource_handler.cast().create_snapshot(server, "version4hw-{}".format(time.time()), "Pre Hardware Upgrade Snapshot")
        
        task = vm.CreateSnapshot_Task("version4hw-{}".format(time.time()), "Pre Hardware Upgrade Snapshot", False, True)
        wait_for_tasks(si, [task])
        
        failure_msg = ""

        # Upgrade VM
        try:
            set_progress("Updating HW version")
            task = vm.UpgradeVM_Task(version="vmx-08")
            wait_for_tasks(si, [task])
        except:
            failure_msg = "Failed to upgrade hardware version"
            set_progress("{}. Will now return VM to original power state.".format(failure_msg))
            pass
        
        if server_original_power_status == "POWERON":
            set_progress("Server was originally on, so power it on again")
            task = vm.PowerOnVM_Task()
            wait_for_tasks(si, [task])
        
        if failure_msg:
            return "FAILURE","",failure_msg
        
        return "","",""

    return "", "", ""