Search in sources :

Example 51 with Datastore

use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.

the class ClusterMO method mountDatastore.

@Override
public ManagedObjectReference mountDatastore(boolean vmfsDatastore, String poolHostAddress, int poolHostPort, String poolPath, String poolUuid) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - mountDatastore(). target MOR: " + _mor.getValue() + ", vmfs: " + vmfsDatastore + ", poolHost: " + poolHostAddress + ", poolHostPort: " + poolHostPort + ", poolPath: " + poolPath + ", poolUuid: " + poolUuid);
    ManagedObjectReference morDs = null;
    ManagedObjectReference morDsFirst = null;
    List<ManagedObjectReference> hosts = _context.getVimClient().getDynamicProperty(_mor, "host");
    if (hosts != null && hosts.size() > 0) {
        for (ManagedObjectReference morHost : hosts) {
            HostMO hostMo = new HostMO(_context, morHost);
            morDs = hostMo.mountDatastore(vmfsDatastore, poolHostAddress, poolHostPort, poolPath, poolUuid);
            if (morDsFirst == null)
                morDsFirst = morDs;
            // assume datastore is in scope of datacenter
            assert (morDsFirst.getValue().equals(morDs.getValue()));
        }
    }
    if (morDs == null) {
        String msg = "Failed to mount datastore in all hosts within the cluster";
        s_logger.error(msg);
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - mountDatastore() done(failed)");
        throw new Exception(msg);
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - mountDatastore() done(successfully)");
    return morDs;
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 52 with Datastore

use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.

the class VirtualMachineMO method attachIso.

// isoDatastorePath: [datastore name] isoFilePath
public void attachIso(String isoDatastorePath, ManagedObjectReference morDs, boolean connect, boolean connectAtBoot) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - attachIso(). target MOR: " + _mor.getValue() + ", isoDatastorePath: " + isoDatastorePath + ", datastore: " + morDs.getValue() + ", connect: " + connect + ", connectAtBoot: " + connectAtBoot);
    assert (isoDatastorePath != null);
    assert (morDs != null);
    boolean newCdRom = false;
    VirtualCdrom cdRom = (VirtualCdrom) getIsoDevice();
    if (cdRom == null) {
        newCdRom = true;
        cdRom = new VirtualCdrom();
        cdRom.setControllerKey(getIDEDeviceControllerKey());
        int deviceNumber = getNextIDEDeviceNumber();
        cdRom.setUnitNumber(deviceNumber);
        cdRom.setKey(-deviceNumber);
    }
    VirtualDeviceConnectInfo cInfo = new VirtualDeviceConnectInfo();
    cInfo.setConnected(connect);
    cInfo.setStartConnected(connectAtBoot);
    cdRom.setConnectable(cInfo);
    VirtualCdromIsoBackingInfo backingInfo = new VirtualCdromIsoBackingInfo();
    backingInfo.setFileName(isoDatastorePath);
    backingInfo.setDatastore(morDs);
    cdRom.setBacking(backingInfo);
    VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
    //VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(cdRom);
    if (newCdRom) {
        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
    } else {
        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
    }
    //deviceConfigSpecArray[0] = deviceConfigSpec;
    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
    boolean result = _context.getVimClient().waitForTask(morTask);
    if (!result) {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - detachIso() done(failed)");
        throw new Exception("Failed to attach ISO due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    _context.waitForTaskProgressDone(morTask);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachIso() done(successfully)");
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualCdromIsoBackingInfo(com.vmware.vim25.VirtualCdromIsoBackingInfo) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualCdrom(com.vmware.vim25.VirtualCdrom) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 53 with Datastore

use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.

the class VmwareStorageProcessor method prepareManagedDatastore.

private ManagedObjectReference prepareManagedDatastore(VmwareContext context, VmwareHypervisorHost hyperHost, String diskUuid, String iScsiName, String storageHost, int storagePort, String chapInitiatorUsername, String chapInitiatorSecret, String chapTargetUsername, String chapTargetSecret) throws Exception {
    if (storagePort == DEFAULT_NFS_PORT) {
        s_logger.info("creating the NFS datastore with the following configuration - storageHost: " + storageHost + ", storagePort: " + storagePort + ", exportpath: " + iScsiName + "and diskUuid : " + diskUuid);
        ManagedObjectReference morCluster = hyperHost.getHyperHostCluster();
        ClusterMO cluster = new ClusterMO(context, morCluster);
        List<Pair<ManagedObjectReference, String>> lstHosts = cluster.getClusterHosts();
        HostMO host = new HostMO(context, lstHosts.get(0).first());
        HostDatastoreSystemMO hostDatastoreSystem = host.getHostDatastoreSystemMO();
        return hostDatastoreSystem.createNfsDatastore(storageHost, storagePort, iScsiName, diskUuid);
    } else {
        return getVmfsDatastore(context, hyperHost, VmwareResource.getDatastoreName(iScsiName), storageHost, storagePort, trimIqn(iScsiName), chapInitiatorUsername, chapInitiatorSecret, chapTargetUsername, chapTargetSecret);
    }
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) HostDatastoreSystemMO(com.cloud.hypervisor.vmware.mo.HostDatastoreSystemMO) ClusterMO(com.cloud.hypervisor.vmware.mo.ClusterMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 54 with Datastore

use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.

the class VirtualMachineMO method changeDatastore.

public boolean changeDatastore(VirtualMachineRelocateSpec relocateSpec) throws Exception {
    ManagedObjectReference morTask = _context.getVimClient().getService().relocateVMTask(_mor, relocateSpec, VirtualMachineMovePriority.DEFAULT_PRIORITY);
    boolean result = _context.getVimClient().waitForTask(morTask);
    if (result) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware RelocateVM_Task to change datastore failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
Also used : ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 55 with Datastore

use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.

the class VirtualMachineMO method getOwnerDatastore.

public Pair<DatastoreMO, String> getOwnerDatastore(String dsFullPath) throws Exception {
    String dsName = DatastoreFile.getDatastoreNameFromPath(dsFullPath);
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().add("name");
    TraversalSpec vmDatastoreTraversal = new TraversalSpec();
    vmDatastoreTraversal.setType("VirtualMachine");
    vmDatastoreTraversal.setPath("datastore");
    vmDatastoreTraversal.setName("vmDatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(vmDatastoreTraversal);
    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) {
            DynamicProperty prop = oc.getPropSet().get(0);
            if (prop.getVal().toString().equals(dsName)) {
                return new Pair<DatastoreMO, String>(new DatastoreMO(_context, oc.getObj()), dsName);
            }
        }
    }
    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) Pair(com.cloud.utils.Pair)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)39 RemoteException (java.rmi.RemoteException)15 ArrayList (java.util.ArrayList)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)14 VirtualDisk (com.vmware.vim25.VirtualDisk)14 TraversalSpec (com.vmware.vim25.TraversalSpec)13 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)12 ObjectContent (com.vmware.vim25.ObjectContent)12 ObjectSpec (com.vmware.vim25.ObjectSpec)12 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)12 PropertySpec (com.vmware.vim25.PropertySpec)12 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)11 Pair (com.cloud.utils.Pair)10 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)10 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)10 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)10 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)9 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)9 DataStoreTO (com.cloud.agent.api.to.DataStoreTO)8