use of com.vmware.vim25.FileInfo 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;
*/
}
use of com.vmware.vim25.FileInfo in project CloudStack-archive by CloudStack-extras.
the class DatastoreMO method folderExists.
public boolean folderExists(String folderParentDatastorePath, String folderName) throws Exception {
HostDatastoreBrowserMO browserMo = getHostDatastoreBrowserMO();
HostDatastoreBrowserSearchResults results = browserMo.searchDatastore(folderParentDatastorePath, folderName, true);
if (results != null) {
FileInfo[] info = results.getFile();
if (info != null && info.length > 0) {
s_logger.info("Folder " + folderName + " exists on datastore");
return true;
}
}
s_logger.info("Folder " + folderName + " does not exist on datastore");
return false;
}
use of com.vmware.vim25.FileInfo in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getVmxHttpAccessUrl.
public String getVmxHttpAccessUrl() throws Exception {
Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
VirtualMachineFileInfo fileInfo = getFileInfo();
String vmxFilePath = fileInfo.getVmPathName();
String[] vmxPathTokens = vmxFilePath.split("\\[|\\]|/");
StringBuffer sb = new StringBuffer("https://" + _context.getServerAddress() + "/folder/");
sb.append(URLEncoder.encode(vmxPathTokens[2].trim()));
sb.append("/");
sb.append(URLEncoder.encode(vmxPathTokens[3].trim()));
sb.append("?dcPath=");
sb.append(URLEncoder.encode(dcInfo.second()));
sb.append("&dsName=");
sb.append(URLEncoder.encode(vmxPathTokens[1].trim()));
return sb.toString();
}
use of com.vmware.vim25.FileInfo in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getHttpAccessPathInfo.
/**
* Retrieve path info to access VM files via vSphere web interface
* @return [0] vm-name, [1] data-center-name, [2] datastore-name
* @throws Exception
*/
public String[] getHttpAccessPathInfo() throws Exception {
String[] pathInfo = new String[3];
Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
VirtualMachineFileInfo fileInfo = getFileInfo();
String vmxFilePath = fileInfo.getVmPathName();
String[] vmxPathTokens = vmxFilePath.split("\\[|\\]|/");
assert (vmxPathTokens.length == 4);
// vSphere vm name
pathInfo[1] = vmxPathTokens[1].trim();
// vSphere datacenter name
pathInfo[2] = dcInfo.second();
// vSphere datastore name
pathInfo[3] = vmxPathTokens[0].trim();
return pathInfo;
}
use of com.vmware.vim25.FileInfo in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getSnapshotDescriptorDatastorePath.
public String getSnapshotDescriptorDatastorePath() throws Exception {
PropertySpec pSpec = new PropertySpec();
pSpec.setType("VirtualMachine");
pSpec.setPathSet(new String[] { "name", "config.files" });
ObjectSpec oSpec = new ObjectSpec();
oSpec.setObj(_mor);
oSpec.setSkip(Boolean.FALSE);
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
pfSpec.setPropSet(new PropertySpec[] { pSpec });
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
ObjectContent[] ocs = _context.getService().retrieveProperties(_context.getServiceContent().getPropertyCollector(), new PropertyFilterSpec[] { pfSpec });
assert (ocs != null);
String vmName = null;
VirtualMachineFileInfo fileInfo = null;
assert (ocs.length == 1);
for (ObjectContent oc : ocs) {
DynamicProperty[] props = oc.getPropSet();
if (props != null) {
assert (props.length == 2);
for (DynamicProperty prop : props) {
if (prop.getName().equals("name")) {
vmName = prop.getVal().toString();
} else {
fileInfo = (VirtualMachineFileInfo) prop.getVal();
}
}
}
}
assert (vmName != null);
assert (fileInfo != null);
// .vmsd file exists at the same directory of .vmx file
DatastoreFile vmxFile = new DatastoreFile(fileInfo.getVmPathName());
return vmxFile.getCompanionPath(vmName + ".vmsd");
}
Aggregations