Search in sources :

Example 36 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.

the class VirtualDiskManagerMO method eagerZeroVirtualDisk.

public void eagerZeroVirtualDisk(String name, ManagedObjectReference morDc) throws Exception {
    ManagedObjectReference morTask = _context.getService().eagerZeroVirtualDisk_Task(_mor, name, morDc);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (!result.equals("sucess"))
        throw new Exception("Unable to eager zero virtual disk " + name + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    _context.waitForTaskProgressDone(morTask);
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 37 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method relocate.

public boolean relocate(ManagedObjectReference morTargetHost) throws Exception {
    VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();
    relocateSpec.setHost(morTargetHost);
    ManagedObjectReference morTask = _context.getService().relocateVM_Task(_mor, relocateSpec, null);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (result.equals("sucess")) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware relocateVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
Also used : VirtualMachineRelocateSpec(com.vmware.vim25.VirtualMachineRelocateSpec) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 38 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.

the class VmwareContext method getHostMorByPath.

public ManagedObjectReference getHostMorByPath(String inventoryPath) throws Exception {
    assert (inventoryPath != null);
    String[] tokens;
    if (inventoryPath.startsWith("/"))
        tokens = inventoryPath.substring(1).split("/");
    else
        tokens = inventoryPath.split("/");
    ManagedObjectReference mor = getRootFolder();
    for (int i = 0; i < tokens.length; i++) {
        String token = tokens[i];
        ObjectContent[] ocs;
        if (mor.getType().equalsIgnoreCase("Datacenter")) {
            PropertySpec pSpec = new PropertySpec();
            pSpec.setType("ManagedEntity");
            pSpec.setPathSet(new String[] { "name" });
            TraversalSpec dcHostFolderTraversal = new TraversalSpec();
            dcHostFolderTraversal.setType("Datacenter");
            dcHostFolderTraversal.setPath("hostFolder");
            dcHostFolderTraversal.setName("dcHostFolderTraversal");
            ObjectSpec oSpec = new ObjectSpec();
            oSpec.setObj(mor);
            oSpec.setSkip(Boolean.TRUE);
            oSpec.setSelectSet(new SelectionSpec[] { dcHostFolderTraversal });
            PropertyFilterSpec pfSpec = new PropertyFilterSpec();
            pfSpec.setPropSet(new PropertySpec[] { pSpec });
            pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
            ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
        } else if (mor.getType().equalsIgnoreCase("Folder")) {
            PropertySpec pSpec = new PropertySpec();
            pSpec.setType("ManagedEntity");
            pSpec.setPathSet(new String[] { "name" });
            TraversalSpec folderChildrenTraversal = new TraversalSpec();
            folderChildrenTraversal.setType("Folder");
            folderChildrenTraversal.setPath("childEntity");
            folderChildrenTraversal.setName("folderChildrenTraversal");
            ObjectSpec oSpec = new ObjectSpec();
            oSpec.setObj(mor);
            oSpec.setSkip(Boolean.TRUE);
            oSpec.setSelectSet(new SelectionSpec[] { folderChildrenTraversal });
            PropertyFilterSpec pfSpec = new PropertyFilterSpec();
            pfSpec.setPropSet(new PropertySpec[] { pSpec });
            pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
            ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
        } else if (mor.getType().equalsIgnoreCase("ClusterComputeResource")) {
            PropertySpec pSpec = new PropertySpec();
            pSpec.setType("ManagedEntity");
            pSpec.setPathSet(new String[] { "name" });
            TraversalSpec clusterHostTraversal = new TraversalSpec();
            clusterHostTraversal.setType("ClusterComputeResource");
            clusterHostTraversal.setPath("host");
            clusterHostTraversal.setName("folderChildrenTraversal");
            ObjectSpec oSpec = new ObjectSpec();
            oSpec.setObj(mor);
            oSpec.setSkip(Boolean.TRUE);
            oSpec.setSelectSet(new SelectionSpec[] { clusterHostTraversal });
            PropertyFilterSpec pfSpec = new PropertyFilterSpec();
            pfSpec.setPropSet(new PropertySpec[] { pSpec });
            pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
            ocs = getService().retrieveProperties(getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
        } else {
            s_logger.error("Invalid inventory path, path element can only be datacenter and folder");
            return null;
        }
        if (ocs != null && ocs.length > 0) {
            boolean found = false;
            for (ObjectContent oc : ocs) {
                String name = oc.getPropSet()[0].getVal().toString();
                if (name.equalsIgnoreCase(token) || name.equalsIgnoreCase("host")) {
                    mor = oc.getObj();
                    found = true;
                    if (name.equalsIgnoreCase("host"))
                        i--;
                    break;
                }
            }
            if (!found) {
                s_logger.error("Path element points to an un-existing inventory entity");
                return null;
            }
        } else {
            s_logger.error("Path element points to an un-existing inventory entity");
            return null;
        }
    }
    return mor;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) SelectionSpec(com.vmware.vim25.SelectionSpec) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 39 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.

the class BaseMO method destroy.

public boolean destroy() throws Exception {
    ManagedObjectReference morTask = _context.getService().destroy_Task(_mor);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (result.equals("sucess")) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware destroy_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 40 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project CloudStack-archive by CloudStack-extras.

the class BaseMO method rename.

public boolean rename(String newName) throws Exception {
    ManagedObjectReference morTask = _context.getService().rename_Task(_mor, newName);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (result.equals("sucess")) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware rename_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)236 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)62 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)57 Pair (com.cloud.utils.Pair)49 RemoteException (java.rmi.RemoteException)48 ArrayList (java.util.ArrayList)45 UnsupportedEncodingException (java.io.UnsupportedEncodingException)39 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)35 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)32 IOException (java.io.IOException)31 CloudException (com.cloud.exception.CloudException)30 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)30 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)29 ObjectContent (com.vmware.vim25.ObjectContent)28 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)27 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)25 ConfigurationException (javax.naming.ConfigurationException)24 InternalErrorException (com.cloud.exception.InternalErrorException)23 VirtualDisk (com.vmware.vim25.VirtualDisk)23 ConnectException (java.net.ConnectException)23