use of com.vmware.vim25.FileInfo in project cloudstack by apache.
the class VmwareResource method deleteUnregisteredVmFiles.
private void deleteUnregisteredVmFiles(VirtualMachineFileLayoutEx vmFileLayout, DatacenterMO dcMo, boolean deleteDisks) throws Exception {
s_logger.debug("Deleting files associated with an existing VM that was unregistered");
DatastoreFile vmFolder = null;
try {
List<VirtualMachineFileLayoutExFileInfo> fileInfo = vmFileLayout.getFile();
for (VirtualMachineFileLayoutExFileInfo file : fileInfo) {
DatastoreFile fileInDatastore = new DatastoreFile(file.getName());
// In case of linked clones, VM file layout includes the base disk so don't delete all disk files.
if (file.getType().startsWith("disk") || file.getType().startsWith("digest"))
continue;
else if (file.getType().equals("config"))
vmFolder = new DatastoreFile(fileInDatastore.getDatastoreName(), fileInDatastore.getDir());
DatastoreMO dsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(fileInDatastore.getDatastoreName()));
s_logger.debug("Deleting file: " + file.getName());
dsMo.deleteFile(file.getName(), dcMo.getMor(), true);
}
// Delete files that are present in the VM folder - this will take care of the VM disks as well.
DatastoreMO vmFolderDsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(vmFolder.getDatastoreName()));
String[] files = vmFolderDsMo.listDirContent(vmFolder.getPath());
if (deleteDisks) {
for (String file : files) {
String vmDiskFileFullPath = String.format("%s/%s", vmFolder.getPath(), file);
s_logger.debug("Deleting file: " + vmDiskFileFullPath);
vmFolderDsMo.deleteFile(vmDiskFileFullPath, dcMo.getMor(), true);
}
}
// Delete VM folder
if (deleteDisks || files.length == 0) {
s_logger.debug("Deleting folder: " + vmFolder.getPath());
vmFolderDsMo.deleteFolder(vmFolder.getPath(), dcMo.getMor());
}
} catch (Exception e) {
String message = "Failed to delete files associated with an existing VM that was unregistered due to " + VmwareHelper.getExceptionMessage(e);
s_logger.warn(message, e);
}
}
use of com.vmware.vim25.FileInfo in project cloudstack by apache.
the class VmwareStorageManagerImpl method getVMSnapshotChainSize.
private long getVMSnapshotChainSize(VmwareContext context, VmwareHypervisorHost hyperHost, String fileName, ManagedObjectReference morDs, String exceptFileName) throws Exception {
long size = 0;
DatastoreMO dsMo = new DatastoreMO(context, morDs);
HostDatastoreBrowserMO browserMo = dsMo.getHostDatastoreBrowserMO();
String datastorePath = "[" + dsMo.getName() + "]";
HostDatastoreBrowserSearchSpec searchSpec = new HostDatastoreBrowserSearchSpec();
FileQueryFlags fqf = new FileQueryFlags();
fqf.setFileSize(true);
fqf.setFileOwner(true);
fqf.setModification(true);
searchSpec.setDetails(fqf);
searchSpec.setSearchCaseInsensitive(false);
searchSpec.getMatchPattern().add(fileName);
ArrayList<HostDatastoreBrowserSearchResults> results = browserMo.searchDatastoreSubFolders(datastorePath, searchSpec);
for (HostDatastoreBrowserSearchResults result : results) {
if (result != null) {
List<FileInfo> info = result.getFile();
for (FileInfo fi : info) {
if (exceptFileName != null && fi.getPath().contains(exceptFileName)) {
continue;
} else {
size = size + fi.getFileSize();
}
}
}
}
return size;
}
use of com.vmware.vim25.FileInfo 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;
}
use of com.vmware.vim25.FileInfo in project cloudstack by apache.
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 intellij-community by JetBrains.
the class IdeaWin32PerformanceTest method doTest.
private void doTest(File file) {
String path = file.getPath();
long t1 = System.nanoTime();
File[] children1 = file.listFiles();
long t2 = System.nanoTime();
FileInfo[] children2 = myDriver.listChildren(path);
long t3 = System.nanoTime();
myJavaTotal += (t2 - t1) / 1000;
myIdeaTotal += (t3 - t2) / 1000;
assertNotNull(path, children1);
assertNotNull(path, children2);
assertEquals(path, children1.length, children2.length);
for (File child : children1) {
if (child.isDirectory()) {
doTest(child);
}
}
}
Aggregations