@@ -0,0 +1,1826 @@
+import time%0D%0Aimport pyVmomi%0D%0Aimport datetime%0D%0Afrom common.methods import set_progress%0D%0Afrom resourcehandlers.vmware.pyvmomi_wrapper import get_vm_by_uuid%0D%0Afrom resourcehandlers.vmware.models import VsphereResourceHandler%0D%0Afrom resourcehandlers.vmware.vmware_41 import TechnologyWrapper%0D%0A%0D%0A%0D%0Adef get_vmware_service_instance(vcenter_rh):%0D%0A    %22%22%22%0D%0A    :return: the pyvmomi service instance object that represents a connection to vCenter,%0D%0A    and which can be used for making API calls.%0D%0A    %22%22%22%0D%0A    assert isinstance(vcenter_rh, VsphereResourceHandler)%0D%0A    vcenter_rh.init()%0D%0A    wc = vcenter_rh.resource_technology.work_class%0D%0A    assert isinstance(wc, TechnologyWrapper)%0D%0A    return wc._get_connection()%0D%0A%0D%0A%0D%0Adef run(job, logger=None, **kwargs):%0D%0A    server = job.server_set.first()%0D%0A    rh = server.resource_handler.cast()%0D%0A    owner = job.owner%0D%0A%0D%0A    # Connect to RH%0D%0A    si = get_vmware_service_instance(rh)%0D%0A    vm = get_vm_by_uuid(si, server.resource_handler_svr_id)%0D%0A    assert isinstance(vm, pyVmomi.vim.VirtualMachine)%0D%0A%0D%0A    # Set the new VM annotation%0D%0A    set_progress(%22Updating new virtual machine annotation%22)%0D%0A    cur_date = datetime.datetime.now()%0D%0A    annotation = str('%7B%7B append_annotation %7D%7D')%0D%0A    annotation = server.notes + annotation%0D%0A    assert isinstance(vm, pyVmomi.vim.VirtualMachine)%0D%0A    configSpec = pyVmomi.vim.vm.ConfigSpec()%0D%0A    configSpec.annotation = annotation%0D%0A    vm.ReconfigVM_Task(configSpec)%0D%0A%0D%0A    set_progress(%22Updating server info from VMware%22)%0D%0A    time.sleep(15)%0D%0A    server.refresh_info()%0D%0A%0D%0A    return %22%22, %22%22, %22%22%0D%0A%0D%0A%0D%0Aif __name__ == '__main__':%0D%0A    import os%0D%0A    import sys%0D%0A%0D%0A    localpath = os.path.join('var', 'opt', 'cloudbolt')%0D%0A    sys.path.append(localpath)%0D%0A    os.environ%5B'DJANGO_SETTINGS_MODULE'%5D = 'settings'%0D%0A    job_id = sys.argv%5B1%5D%0D%0A    print run(job=job_id)

update server notes/annotation for vmware vms