use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.
the class HostDatastoreSystemMO method findDatastoreByExportPath.
// TODO this is a hacking helper method, when we can pass down storage pool info along with volume
// we should be able to find the datastore by name
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
assert (exportPath != null);
List<ManagedObjectReference> datastores = getDatastores();
if (datastores != null && datastores.size() > 0) {
for (ManagedObjectReference morDatastore : datastores) {
DatastoreMO dsMo = new DatastoreMO(_context, morDatastore);
if (dsMo.getInventoryPath().equals(exportPath))
return morDatastore;
NasDatastoreInfo info = getNasDatastoreInfo(morDatastore);
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))
return morDatastore;
}
}
}
return null;
}
use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.
the class HostDatastoreSystemMO method createVmfsDatastore.
public ManagedObjectReference createVmfsDatastore(String datastoreName, HostScsiDisk hostScsiDisk) throws Exception {
// just grab the first instance of VmfsDatastoreOption
VmfsDatastoreOption vmfsDatastoreOption = _context.getService().queryVmfsDatastoreCreateOptions(_mor, hostScsiDisk.getDevicePath(), 5).get(0);
VmfsDatastoreCreateSpec vmfsDatastoreCreateSpec = (VmfsDatastoreCreateSpec) vmfsDatastoreOption.getSpec();
// set the name of the datastore to be created
vmfsDatastoreCreateSpec.getVmfs().setVolumeName(datastoreName);
return _context.getService().createVmfsDatastore(_mor, vmfsDatastoreCreateSpec);
}
use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.
the class HostDatastoreSystemMO method getDatastorePropertiesOnHostDatastoreSystem.
public List<ObjectContent> getDatastorePropertiesOnHostDatastoreSystem(String[] propertyPaths) throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Datastore");
pSpec.getPathSet().addAll(Arrays.asList(propertyPaths));
TraversalSpec hostDsSys2DatastoreTraversal = new TraversalSpec();
hostDsSys2DatastoreTraversal.setType("HostDatastoreSystem");
hostDsSys2DatastoreTraversal.setPath("datastore");
hostDsSys2DatastoreTraversal.setName("hostDsSys2DatastoreTraversal");
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(hostDsSys2DatastoreTraversal);
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);
}
use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.
the class DatastoreMO method getOwnerDatacenter.
public Pair<DatacenterMO, String> getOwnerDatacenter() throws Exception {
if (_ownerDc != null)
return _ownerDc;
PropertySpec pSpec = new PropertySpec();
pSpec.setType("Datacenter");
pSpec.getPathSet().add("name");
TraversalSpec folderParentTraversal = new TraversalSpec();
folderParentTraversal.setType("Folder");
folderParentTraversal.setPath("parent");
folderParentTraversal.setName("folderParentTraversal");
SelectionSpec sSpec = new SelectionSpec();
sSpec.setName("folderParentTraversal");
folderParentTraversal.getSelectSet().add(sSpec);
TraversalSpec dsParentTraversal = new TraversalSpec();
dsParentTraversal.setType("Datastore");
dsParentTraversal.setPath("parent");
dsParentTraversal.setName("dsParentTraversal");
dsParentTraversal.getSelectSet().add(folderParentTraversal);
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(getMor());
oSpec.setSkip(Boolean.TRUE);
oSpec.getSelectSet().add(dsParentTraversal);
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);
assert (ocs != null && ocs.size() > 0);
assert (ocs.get(0).getObj() != null);
assert (ocs.get(0).getPropSet() != null);
String dcName = ocs.get(0).getPropSet().get(0).getVal().toString();
_ownerDc = new Pair<DatacenterMO, String>(new DatacenterMO(_context, ocs.get(0).getObj()), dcName);
return _ownerDc;
}
use of com.vmware.vim25.mo.Datastore in project cloudstack by apache.
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) {
List<FileInfo> info = results.getFile();
if (info != null && info.size() > 0) {
s_logger.info("File " + fileFullPath + " exists on datastore");
return true;
}
}
s_logger.info("File " + fileFullPath + " does not exist on datastore");
return false;
}
Aggregations