Search in sources :

Example 46 with Datastore

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

the class HostDatastoreBrowserMO method searchDatastoreSubFolders.

public HostDatastoreBrowserSearchResults searchDatastoreSubFolders(String datastorePath, HostDatastoreBrowserSearchSpec searchSpec) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - searchDatastoreSubFolders(). target mor: " + _mor.get_value() + ", file datastore path: " + datastorePath);
    try {
        ManagedObjectReference morTask = _context.getService().searchDatastoreSubFolders_Task(_mor, datastorePath, searchSpec);
        String result = _context.getServiceUtil().waitForTask(morTask);
        if (result.equals("sucess")) {
            _context.waitForTaskProgressDone(morTask);
            return (HostDatastoreBrowserSearchResults) _context.getServiceUtil().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 : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 47 with Datastore

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

the class VirtualMachineMO method detachDisk.

// vmdkDatastorePath: [datastore name] vmdkFilePath
public List<Pair<String, ManagedObjectReference>> detachDisk(String vmdkDatastorePath, boolean deleteBackingFile) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: " + vmdkDatastorePath + ", deleteBacking: " + deleteBackingFile);
    // Note: if VM has been taken snapshot, original backing file will be renamed, therefore, when we try to find the matching
    // VirtualDisk, we only perform prefix matching
    Pair<VirtualDisk, String> deviceInfo = getDiskDevice(vmdkDatastorePath, false);
    if (deviceInfo == null) {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - detachDisk() done (failed)");
        throw new Exception("No such disk device: " + vmdkDatastorePath);
    }
    List<Pair<String, ManagedObjectReference>> chain = getDiskDatastorePathChain(deviceInfo.first(), true);
    VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
    VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(deviceInfo.first());
    if (deleteBackingFile) {
        deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.destroy);
    }
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);
    deviceConfigSpecArray[0] = deviceConfigSpec;
    reConfigSpec.setDeviceChange(deviceConfigSpecArray);
    ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (!result.equals("sucess")) {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - detachDisk() done (failed)");
        throw new Exception("Failed to detach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    _context.waitForTaskProgressDone(morTask);
    // VMware does not update snapshot references to the detached disk, we have to work around it
    SnapshotDescriptor snapshotDescriptor = null;
    try {
        snapshotDescriptor = getSnapshotDescriptor();
    } catch (Exception e) {
        s_logger.info("Unable to retrieve snapshot descriptor, will skip updating snapshot reference");
    }
    if (snapshotDescriptor != null) {
        for (Pair<String, ManagedObjectReference> pair : chain) {
            DatastoreFile dsFile = new DatastoreFile(pair.first());
            snapshotDescriptor.removeDiskReferenceFromSnapshot(dsFile.getFileName());
        }
        Pair<DatacenterMO, String> dcPair = getOwnerDatacenter();
        String dsPath = getSnapshotDescriptorDatastorePath();
        assert (dsPath != null);
        String url = getContext().composeDatastoreBrowseUrl(dcPair.second(), dsPath);
        getContext().uploadResourceContent(url, snapshotDescriptor.getVmsdContent());
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachDisk() done (successfully)");
    return chain;
}
Also used : VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDisk(com.vmware.vim25.VirtualDisk) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) Pair(com.cloud.utils.Pair) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 48 with Datastore

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

the class ClusterMO method findDatastore.

@Override
public ManagedObjectReference findDatastore(String poolUuid) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastore(). target MOR: " + _mor.getValue() + ", poolUuid: " + poolUuid);
    CustomFieldsManagerMO cfmMo = new CustomFieldsManagerMO(_context, _context.getServiceContent().getCustomFieldsManager());
    int key = cfmMo.getCustomFieldKey("Datastore", CustomFieldConstants.CLOUD_UUID);
    assert (key != 0);
    ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "name", String.format("value[%d]", key) });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            if (oc.getPropSet().get(0).getVal().equals(poolUuid))
                return oc.getObj();
            if (oc.getPropSet().size() > 1) {
                DynamicProperty prop = oc.getPropSet().get(1);
                if (prop != null && prop.getVal() != null) {
                    if (prop.getVal() instanceof CustomFieldStringValue) {
                        String val = ((CustomFieldStringValue) prop.getVal()).getValue();
                        if (val.equalsIgnoreCase(poolUuid)) {
                            if (s_logger.isTraceEnabled())
                                s_logger.trace("vCenter API trace - findDatastore() done(successfully)");
                            return oc.getObj();
                        }
                    }
                }
            }
        }
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastore() done(failed)");
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DynamicProperty(com.vmware.vim25.DynamicProperty) CustomFieldStringValue(com.vmware.vim25.CustomFieldStringValue)

Example 49 with Datastore

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

the class DatacenterMO method getDatastorePropertiesOnDatacenter.

public List<ObjectContent> getDatastorePropertiesOnDatacenter(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
    TraversalSpec dc2DatastoreTraversal = new TraversalSpec();
    dc2DatastoreTraversal.setType("Datacenter");
    dc2DatastoreTraversal.setPath("datastore");
    dc2DatastoreTraversal.setName("dc2DatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.getSelectSet().add(dc2DatastoreTraversal);
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.getPropSet().add(pSpec);
    pfSpec.getObjectSet().add(oSpec);
    List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
    pfSpecArr.add(pfSpec);
    return _context.getService().retrieveProperties(_context.getPropertyCollector(), pfSpecArr);
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) ArrayList(java.util.ArrayList)

Example 50 with Datastore

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

the class ClusterMO method importVmFromOVF.

@Override
public void importVmFromOVF(String ovfFilePath, String vmName, DatastoreMO dsMo, String diskOption) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - importVmFromOVF(). target MOR: " + _mor.getValue() + ", ovfFilePath: " + ovfFilePath + ", vmName: " + vmName + ", datastore: " + dsMo.getMor().getValue() + ", diskOption: " + diskOption);
    ManagedObjectReference morRp = getHyperHostOwnerResourcePool();
    assert (morRp != null);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - importVmFromOVF(). resource pool: " + morRp.getValue());
    HypervisorHostHelper.importVmFromOVF(this, ovfFilePath, vmName, dsMo, diskOption, morRp, null);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - importVmFromOVF() done");
}
Also used : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

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