Search in sources :

Example 6 with FileInfo

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);
    }
}
Also used : DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) VirtualMachineFileLayoutExFileInfo(com.vmware.vim25.VirtualMachineFileLayoutExFileInfo) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException)

Example 7 with FileInfo

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;
}
Also used : HostDatastoreBrowserMO(com.cloud.hypervisor.vmware.mo.HostDatastoreBrowserMO) HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo) HostDatastoreBrowserSearchSpec(com.vmware.vim25.HostDatastoreBrowserSearchSpec) FileQueryFlags(com.vmware.vim25.FileQueryFlags) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO)

Example 8 with FileInfo

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;
}
Also used : HostDatastoreBrowserSearchResults(com.vmware.vim25.HostDatastoreBrowserSearchResults) FileInfo(com.vmware.vim25.FileInfo)

Example 9 with FileInfo

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;
}
Also used : VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo)

Example 10 with FileInfo

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);
        }
    }
}
Also used : FileInfo(com.intellij.openapi.util.io.win32.FileInfo) File(java.io.File)

Aggregations

VirtualMachineFileInfo (com.vmware.vim25.VirtualMachineFileInfo)11 FileInfo (com.vmware.vim25.FileInfo)6 HostDatastoreBrowserSearchResults (com.vmware.vim25.HostDatastoreBrowserSearchResults)6 FileInfo (com.intellij.openapi.util.io.win32.FileInfo)4 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)3 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)3 CloudException (com.cloud.exception.CloudException)2 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)2 FileAttributes (com.intellij.openapi.util.io.FileAttributes)2 VirtualFileWithId (com.intellij.openapi.vfs.VirtualFileWithId)2 DynamicProperty (com.vmware.vim25.DynamicProperty)2 ObjectContent (com.vmware.vim25.ObjectContent)2 ObjectSpec (com.vmware.vim25.ObjectSpec)2 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)2 PropertySpec (com.vmware.vim25.PropertySpec)2 VirtualLsiLogicController (com.vmware.vim25.VirtualLsiLogicController)2 VirtualMachineVideoCard (com.vmware.vim25.VirtualMachineVideoCard)2 THashMap (gnu.trove.THashMap)2 BufferedReader (java.io.BufferedReader)2 BufferedWriter (java.io.BufferedWriter)2