Search in sources :

Example 71 with ManagedObjectReference

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

the class DistributedVirtualSwitchMO method updateVMWareDVSwitchGetTask.

public TaskInfo updateVMWareDVSwitchGetTask(ManagedObjectReference dvSwitchMor, VMwareDVSConfigSpec dvsSpec) throws Exception {
    ManagedObjectReference task = _context.getService().reconfigureDvsTask(dvSwitchMor, dvsSpec);
    TaskInfo info = (TaskInfo) (_context.getVimClient().getDynamicProperty(task, "info"));
    _context.getVimClient().waitForTask(task);
    return info;
}
Also used : TaskInfo(com.vmware.vim25.TaskInfo) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 72 with ManagedObjectReference

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

the class DatacenterMO method getDvSwitchMor.

public ManagedObjectReference getDvSwitchMor(ManagedObjectReference dvPortGroupMor) throws Exception {
    String dvPortGroupKey = null;
    ManagedObjectReference dvSwitchMor = null;
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("DistributedVirtualPortgroup");
    pSpec.getPathSet().add("key");
    pSpec.getPathSet().add("config.distributedVirtualSwitch");
    TraversalSpec datacenter2DvPortGroupTraversal = new TraversalSpec();
    datacenter2DvPortGroupTraversal.setType("Datacenter");
    datacenter2DvPortGroupTraversal.setPath("network");
    datacenter2DvPortGroupTraversal.setName("datacenter2DvPortgroupTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(datacenter2DvPortGroupTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    List<ObjectContent> ocs = _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            List<DynamicProperty> props = oc.getPropSet();
            if (props != null) {
                assert (props.size() == 2);
                for (DynamicProperty prop : props) {
                    if (prop.getName().equals("key")) {
                        dvPortGroupKey = (String) prop.getVal();
                    } else {
                        dvSwitchMor = (ManagedObjectReference) prop.getVal();
                    }
                }
                if ((dvPortGroupKey != null) && dvPortGroupKey.equals(dvPortGroupMor.getValue())) {
                    return dvSwitchMor;
                }
            }
        }
    }
    return null;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) DynamicProperty(com.vmware.vim25.DynamicProperty) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 73 with ManagedObjectReference

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

the class DatacenterMO method getAllVmsOnDatacenter.

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

Example 74 with ManagedObjectReference

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

the class DatacenterMO method registerTemplate.

public void registerTemplate(ManagedObjectReference morHost, String datastoreName, String templateName, String templateFileName) throws Exception {
    ManagedObjectReference morFolder = (ManagedObjectReference) _context.getVimClient().getDynamicProperty(_mor, "vmFolder");
    assert (morFolder != null);
    ManagedObjectReference morTask = _context.getService().registerVMTask(morFolder, String.format("[%s] %s/%s", datastoreName, templateName, templateFileName), templateName, true, null, morHost);
    boolean result = _context.getVimClient().waitForTask(morTask);
    if (!result) {
        throw new Exception("Unable to register template due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    } else {
        _context.waitForTaskProgressDone(morTask);
    }
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 75 with ManagedObjectReference

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

the class ClusterMO method createVm.

@Override
public boolean createVm(VirtualMachineConfigSpec vmSpec) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - createVM_Task(). target MOR: " + _mor.getValue() + ", VirtualMachineConfigSpec: " + new Gson().toJson(vmSpec));
    assert (vmSpec != null);
    DatacenterMO dcMo = new DatacenterMO(_context, getHyperHostDatacenter());
    ManagedObjectReference morPool = getHyperHostOwnerResourcePool();
    ManagedObjectReference morTask = _context.getService().createVMTask(dcMo.getVmFolder(), vmSpec, morPool, null);
    boolean result = _context.getVimClient().waitForTask(morTask);
    if (result) {
        _context.waitForTaskProgressDone(morTask);
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - createVM_Task() done(successfully)");
        return true;
    } else {
        s_logger.error("VMware createVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - createVM_Task() done(failed)");
    return false;
}
Also used : Gson(com.google.gson.Gson) 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