Search in sources :

Example 1 with Datastore

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

the class ClusterMO method getDatastorePropertiesOnHyperHost.

@Override
public ObjectContent[] getDatastorePropertiesOnHyperHost(String[] propertyPaths) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() on Datastore properties. target MOR: " + _mor.get_value() + ", properties: " + new Gson().toJson(propertyPaths));
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.setPathSet(propertyPaths);
    TraversalSpec cluster2DatastoreTraversal = new TraversalSpec();
    cluster2DatastoreTraversal.setType("ClusterComputeResource");
    cluster2DatastoreTraversal.setPath("datastore");
    cluster2DatastoreTraversal.setName("cluster2DatastoreTraversal");
    ObjectSpec oSpec = new ObjectSpec();
    oSpec.setObj(_mor);
    oSpec.setSkip(Boolean.TRUE);
    oSpec.setSelectSet(new SelectionSpec[] { cluster2DatastoreTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    ObjectContent[] properties = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - retrieveProperties() done");
    return properties;
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectContent(com.vmware.vim25.ObjectContent) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec) Gson(com.google.gson.Gson)

Example 2 with Datastore

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

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.get_value() + ", vmfs: " + vmfsDatastore + ", poolHost: " + poolHostAddress + ", poolHostPort: " + poolHostPort + ", poolPath: " + poolPath + ", poolUuid: " + poolUuid);
    ManagedObjectReference morDs = null;
    ManagedObjectReference morDsFirst = null;
    ManagedObjectReference[] hosts = (ManagedObjectReference[]) _context.getServiceUtil().getDynamicProperty(_mor, "host");
    if (hosts != null && hosts.length > 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.get_value().equals(morDs.get_value()));
        }
    }
    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 : ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 3 with Datastore

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

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.get_value() + ", ovfFilePath: " + ovfFilePath + ", vmName: " + vmName + ", datastore: " + dsMo.getMor().get_value() + ", diskOption: " + diskOption);
    ManagedObjectReference morRp = getHyperHostOwnerResourcePool();
    assert (morRp != null);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - importVmFromOVF(). resource pool: " + morRp.get_value());
    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)

Example 4 with Datastore

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

the class DatacenterMO method getDatastorePropertiesOnDatacenter.

public ObjectContent[] getDatastorePropertiesOnDatacenter(String[] propertyPaths) throws Exception {
    PropertySpec pSpec = new PropertySpec();
    pSpec.setType("Datastore");
    pSpec.setPathSet(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.setSelectSet(new SelectionSpec[] { dc2DatastoreTraversal });
    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
    pfSpec.setPropSet(new PropertySpec[] { pSpec });
    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
    return _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
}
Also used : PropertyFilterSpec(com.vmware.vim25.PropertyFilterSpec) ObjectSpec(com.vmware.vim25.ObjectSpec) PropertySpec(com.vmware.vim25.PropertySpec) TraversalSpec(com.vmware.vim25.TraversalSpec)

Example 5 with Datastore

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

the class DatastoreMO method fileExists.

public boolean fileExists(String fileFullPath) throws Exception {
    DatastoreFile file = new DatastoreFile(fileFullPath);
    DatastoreFile dirFile = new DatastoreFile(file.getDatastoreName(), file.getDir());
    HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
    s_logger.info("Search file " + file.getFileName() + " on " + dirFile.getPath());
    HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(dirFile.getPath(), file.getFileName(), true);
    if (results != null) {
        FileInfo[] info = results.getFile();
        if (info != null && info.length > 0) {
            s_logger.info("File " + fileFullPath + " exists on datastore");
            return true;
        }
    }
    s_logger.info("File " + fileFullPath + " does not exist on datastore");
    return false;
/*		
		String[] fileNames = listDirContent(dirFile.getPath());
		
		String fileName = file.getFileName();
		for(String name : fileNames) {
			if(name.equalsIgnoreCase(fileName))
				return true;
		} 
		
		return false;
*/
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)70 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)29 RemoteException (java.rmi.RemoteException)28 Datastore (com.vmware.vim25.mo.Datastore)27 ArrayList (java.util.ArrayList)26 VirtualDisk (com.vmware.vim25.VirtualDisk)21 UnsupportedEncodingException (java.io.UnsupportedEncodingException)21 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)20 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)19 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)17 TraversalSpec (com.vmware.vim25.TraversalSpec)17 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)17 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)16 ObjectContent (com.vmware.vim25.ObjectContent)16 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)16 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)16 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)16 HostSystem (com.vmware.vim25.mo.HostSystem)16 ObjectSpec (com.vmware.vim25.ObjectSpec)15 PropertySpec (com.vmware.vim25.PropertySpec)15