Search in sources :

Example 76 with ManagedObjectReference

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

the class ClusterMO method findDatastoreByExportPath.

@Override
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.getValue() + ", exportPath: " + exportPath);
    ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "info" });
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            DatastoreInfo dsInfo = (DatastoreInfo) oc.getPropSet().get(0).getVal();
            if (dsInfo != null && dsInfo instanceof NasDatastoreInfo) {
                NasDatastoreInfo info = (NasDatastoreInfo) dsInfo;
                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)) {
                        if (s_logger.isTraceEnabled())
                            s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(successfully)");
                        return oc.getObj();
                    }
                }
            }
        }
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(failed)");
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) DatastoreInfo(com.vmware.vim25.DatastoreInfo) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) URI(java.net.URI)

Example 77 with ManagedObjectReference

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

the class ClusterMO method getRestartPriorityForVM.

private String getRestartPriorityForVM(VirtualMachineMO vmMo) throws Exception {
    if (vmMo == null) {
        s_logger.debug("Failed to get restart priority for VM, invalid VM object reference");
        return null;
    }
    ManagedObjectReference vmMor = vmMo.getMor();
    if (vmMor == null || !vmMor.getType().equals("VirtualMachine")) {
        s_logger.debug("Failed to get restart priority for VM: " + vmMo.getName() + ", invalid VM object reference");
        return null;
    }
    ClusterConfigInfoEx configInfo = getClusterConfigInfo();
    if (configInfo == null) {
        s_logger.debug("Failed to get restart priority for VM: " + vmMo.getName() + ", no cluster config information");
        return null;
    }
    List<ClusterDasVmConfigInfo> dasVmConfig = configInfo.getDasVmConfig();
    for (int dasVmConfigIndex = 0; dasVmConfigIndex < dasVmConfig.size(); dasVmConfigIndex++) {
        ClusterDasVmConfigInfo dasVmConfigInfo = dasVmConfig.get(dasVmConfigIndex);
        if (dasVmConfigInfo != null && dasVmConfigInfo.getKey().getValue().equals(vmMor.getValue())) {
            DasVmPriority dasVmPriority = dasVmConfigInfo.getRestartPriority();
            if (dasVmPriority != null) {
                return dasVmPriority.value();
            } else {
                //VM uses cluster restart priority when DasVmPriority for the VM is null.
                return ClusterDasVmSettingsRestartPriority.CLUSTER_RESTART_PRIORITY.value();
            }
        }
    }
    s_logger.debug("VM: " + vmMo.getName() + " uses default restart priority in the cluster: " + getName());
    return null;
}
Also used : ClusterConfigInfoEx(com.vmware.vim25.ClusterConfigInfoEx) ClusterDasVmConfigInfo(com.vmware.vim25.ClusterDasVmConfigInfo) DasVmPriority(com.vmware.vim25.DasVmPriority) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 78 with ManagedObjectReference

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

the class HostMO method getDatastoreMountsOnHost.

public List<Pair<ManagedObjectReference, String>> getDatastoreMountsOnHost() throws Exception {
    List<Pair<ManagedObjectReference, String>> mounts = new ArrayList<Pair<ManagedObjectReference, String>>();
    ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { String.format("host[\"%s\"].mountInfo.path", _mor.getValue()) });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            Pair<ManagedObjectReference, String> mount = new Pair<ManagedObjectReference, String>(oc.getObj(), oc.getPropSet().get(0).getVal().toString());
            mounts.add(mount);
        }
    }
    return mounts;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) ArrayList(java.util.ArrayList) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 79 with ManagedObjectReference

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

the class HostMO method setRestartPriorityForVM.

@Override
public void setRestartPriorityForVM(VirtualMachineMO vmMo, String priority) throws Exception {
    ManagedObjectReference morParent = getParentMor();
    if (morParent.getType().equals("ClusterComputeResource")) {
        ClusterMO clusterMo = new ClusterMO(_context, morParent);
        clusterMo.setRestartPriorityForVM(vmMo, priority);
    }
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 80 with ManagedObjectReference

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

the class HostMO method getHostFirewallSystemMO.

public HostFirewallSystemMO getHostFirewallSystemMO() throws Exception {
    HostConfigManager configMgr = getHostConfigManager();
    ManagedObjectReference morFirewall = configMgr.getFirewallSystem();
    // only ESX hosts have firewall manager
    if (morFirewall != null)
        return new HostFirewallSystemMO(_context, morFirewall);
    return null;
}
Also used : HostConfigManager(com.vmware.vim25.HostConfigManager) 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