Search in sources :

Example 61 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.

the class VmwareHelper method findSnapshotInTree.

public static ManagedObjectReference findSnapshotInTree(List<VirtualMachineSnapshotTree> snapTree, String findName) {
    assert (findName != null);
    ManagedObjectReference snapMor = null;
    if (snapTree == null)
        return snapMor;
    for (int i = 0; i < snapTree.size() && snapMor == null; i++) {
        VirtualMachineSnapshotTree node = snapTree.get(i);
        if (node.getName().equals(findName)) {
            snapMor = node.getSnapshot();
        } else {
            List<VirtualMachineSnapshotTree> childTree = node.getChildSnapshotList();
            snapMor = findSnapshotInTree(childTree, findName);
        }
    }
    return snapMor;
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) VirtualMachineSnapshotTree(com.vmware.vim25.VirtualMachineSnapshotTree)

Example 62 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.

the class ClusterMO method getClusterHosts.

public List<Pair<ManagedObjectReference, String>> getClusterHosts() throws Exception {
    List<Pair<ManagedObjectReference, String>> hosts = new ArrayList<Pair<ManagedObjectReference, String>>();
    ObjectContent[] ocs = getHostPropertiesOnCluster(new String[] { "name" });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            ManagedObjectReference morHost = oc.getObj();
            String name = (String) oc.getPropSet().get(0).getVal();
            hosts.add(new Pair<ManagedObjectReference, String>(morHost, name));
        }
    }
    return hosts;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) ArrayList(java.util.ArrayList) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 63 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.

the class ClusterMO method getHyperHostResourceSummary.

@Override
public VmwareHypervisorHostResourceSummary getHyperHostResourceSummary() throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - getHyperHostResourceSummary(). target MOR: " + _mor.getValue());
    VmwareHypervisorHostResourceSummary summary = new VmwareHypervisorHostResourceSummary();
    ComputeResourceSummary vmwareSummary = (ComputeResourceSummary) _context.getVimClient().getDynamicProperty(_mor, "summary");
    // TODO, need to use traversal to optimize retrieve of
    int cpuNumInCpuThreads = 1;
    List<ManagedObjectReference> hosts = _context.getVimClient().getDynamicProperty(_mor, "host");
    if (hosts != null && hosts.size() > 0) {
        for (ManagedObjectReference morHost : hosts) {
            HostMO hostMo = new HostMO(_context, morHost);
            HostHardwareSummary hardwareSummary = hostMo.getHostHardwareSummary();
            if (hardwareSummary.getNumCpuCores() * hardwareSummary.getNumCpuThreads() > cpuNumInCpuThreads)
                cpuNumInCpuThreads = hardwareSummary.getNumCpuCores() * hardwareSummary.getNumCpuThreads();
        }
    }
    summary.setCpuCount(cpuNumInCpuThreads);
    summary.setCpuSpeed(vmwareSummary.getTotalCpu());
    summary.setMemoryBytes(vmwareSummary.getTotalMemory());
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - getHyperHostResourceSummary() done");
    return summary;
}
Also used : HostHardwareSummary(com.vmware.vim25.HostHardwareSummary) ComputeResourceSummary(com.vmware.vim25.ComputeResourceSummary) ClusterComputeResourceSummary(com.vmware.vim25.ClusterComputeResourceSummary) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 64 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.

the class HostDatastoreBrowserMO method searchDatastoreSubFolders.

@SuppressWarnings("unchecked")
public ArrayList<HostDatastoreBrowserSearchResults> searchDatastoreSubFolders(String datastorePath, HostDatastoreBrowserSearchSpec searchSpec) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - searchDatastoreSubFolders(). target mor: " + _mor.getValue() + ", file datastore path: " + datastorePath);
    try {
        ManagedObjectReference morTask = _context.getService().searchDatastoreSubFoldersTask(_mor, datastorePath, searchSpec);
        boolean result = _context.getVimClient().waitForTask(morTask);
        if (result) {
            _context.waitForTaskProgressDone(morTask);
            return (ArrayList<HostDatastoreBrowserSearchResults>) _context.getVimClient().getDynamicProperty(morTask, "info.result");
        } else {
            s_logger.error("VMware searchDaastoreSubFolders_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
        }
    } finally {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - searchDatastore() done");
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 65 with ManagedObjectReference

use of com.vmware.vim25.ManagedObjectReference in project cloudstack by apache.

the class HostDatastoreSystemMO method findDatastoreByExportPath.

// TODO this is a hacking helper method, when we can pass down storage pool info along with volume
// we should be able to find the datastore by name
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
    assert (exportPath != null);
    List<ManagedObjectReference> datastores = getDatastores();
    if (datastores != null && datastores.size() > 0) {
        for (ManagedObjectReference morDatastore : datastores) {
            DatastoreMO dsMo = new DatastoreMO(_context, morDatastore);
            if (dsMo.getInventoryPath().equals(exportPath))
                return morDatastore;
            NasDatastoreInfo info = getNasDatastoreInfo(morDatastore);
            if (info != null) {
                String vmwareUrl = info.getUrl();
                if (vmwareUrl.charAt(vmwareUrl.length() - 1) == '/')
                    vmwareUrl = vmwareUrl.substring(0, vmwareUrl.length() - 1);
                URI uri = new URI(vmwareUrl);
                if (uri.getPath().equals("/" + exportPath))
                    return morDatastore;
            }
        }
    }
    return null;
}
Also used : NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) URI(java.net.URI) 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