Search in sources :

Example 11 with FileInfo

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

the class VirtualMachineMO method setSnapshotDirectory.

// snapshot directory in format of: /vmfs/volumes/<datastore name>/<path>
@Deprecated
public void setSnapshotDirectory(String snapshotDir) throws Exception {
    VirtualMachineFileInfo fileInfo = getFileInfo();
    Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter();
    String vmxUrl = _context.composeDatastoreBrowseUrl(dcInfo.second(), fileInfo.getVmPathName());
    byte[] vmxContent = _context.getResourceContent(vmxUrl);
    BufferedReader in = null;
    BufferedWriter out = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    boolean replaced = false;
    try {
        in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(vmxContent)));
        out = new BufferedWriter(new OutputStreamWriter(bos));
        String line;
        while ((line = in.readLine()) != null) {
            if (line.startsWith("workingDir")) {
                replaced = true;
                out.write(String.format("workingDir=\"%s\"", snapshotDir));
                out.newLine();
            } else {
                out.write(line);
                out.newLine();
            }
        }
        if (!replaced) {
            out.newLine();
            out.write(String.format("workingDir=\"%s\"", snapshotDir));
            out.newLine();
        }
    } finally {
        if (in != null) {
            in.close();
        }
        if (out != null) {
            out.close();
        }
    }
    _context.uploadResourceContent(vmxUrl, bos.toByteArray());
// It seems that I don't need to do re-registration. VMware has bug in writing the correct snapshot's VMDK path to
// its disk backing info anyway.
// redoRegistration();
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo) BufferedWriter(java.io.BufferedWriter)

Example 12 with FileInfo

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

the class HypervisorHostHelper method createBlankVm.

public static boolean createBlankVm(VmwareHypervisorHost host, String vmName, int cpuCount, int cpuSpeedMHz, int cpuReservedMHz, boolean limitCpuUse, int memoryMB, int memoryReserveMB, String guestOsIdentifier, ManagedObjectReference morDs, boolean snapshotDirToParent) throws Exception {
    if (s_logger.isInfoEnabled())
        s_logger.info("Create blank VM. cpuCount: " + cpuCount + ", cpuSpeed(MHz): " + cpuSpeedMHz + ", mem(Mb): " + memoryMB);
    // VM config basics
    VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec();
    vmConfig.setName(vmName);
    VmwareHelper.setBasicVmConfig(vmConfig, cpuCount, cpuSpeedMHz, cpuReservedMHz, memoryMB, memoryReserveMB, guestOsIdentifier, limitCpuUse);
    // Scsi controller
    VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
    scsiController.setSharedBus(VirtualSCSISharing.noSharing);
    scsiController.setBusNumber(0);
    scsiController.setKey(1);
    VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
    scsiControllerSpec.setDevice(scsiController);
    scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
    VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo();
    DatastoreMO dsMo = new DatastoreMO(host.getContext(), morDs);
    fileInfo.setVmPathName(String.format("[%s]", dsMo.getName()));
    vmConfig.setFiles(fileInfo);
    VirtualMachineVideoCard videoCard = new VirtualMachineVideoCard();
    videoCard.setControllerKey(100);
    videoCard.setUseAutoDetect(true);
    VirtualDeviceConfigSpec videoDeviceSpec = new VirtualDeviceConfigSpec();
    videoDeviceSpec.setDevice(videoCard);
    videoDeviceSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
    vmConfig.setDeviceChange(new VirtualDeviceConfigSpec[] { scsiControllerSpec, videoDeviceSpec });
    if (host.createVm(vmConfig)) {
        VirtualMachineMO vmMo = host.findVmOnHyperHost(vmName);
        assert (vmMo != null);
        int ideControllerKey = -1;
        while (ideControllerKey < 0) {
            ideControllerKey = vmMo.tryGetIDEDeviceControllerKey();
            if (ideControllerKey >= 0)
                break;
            s_logger.info("Waiting for IDE controller be ready in VM: " + vmName);
            Thread.sleep(1000);
        }
        if (snapshotDirToParent) {
            String snapshotDir = String.format("/vmfs/volumes/%s/", dsMo.getName());
            s_logger.info("Switch snapshot working directory to " + snapshotDir + " for " + vmName);
            vmMo.setSnapshotDirectory(snapshotDir);
            // Don't have a good way to test if the VM is really ready for use through normal API after configuration file manipulation,
            // delay 3 seconds
            Thread.sleep(3000);
        }
        s_logger.info("Blank VM: " + vmName + " is ready for use");
        return true;
    }
    return false;
}
Also used : VirtualMachineVideoCard(com.vmware.vim25.VirtualMachineVideoCard) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualMachineFileInfo(com.vmware.vim25.VirtualMachineFileInfo) VirtualLsiLogicController(com.vmware.vim25.VirtualLsiLogicController)

Example 13 with FileInfo

use of com.vmware.vim25.FileInfo in project intellij-community by JetBrains.

the class Win32FsCache method getAttributes.

@Nullable
FileAttributes getAttributes(@NotNull VirtualFile file) {
    VirtualFile parent = file.getParent();
    int parentId = parent instanceof VirtualFileWithId ? ((VirtualFileWithId) parent).getId() : -((VirtualFileWithId) file).getId();
    TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap();
    THashMap<String, FileAttributes> nestedMap = map.get(parentId);
    String name = file.getName();
    FileAttributes attributes = nestedMap != null ? nestedMap.get(name) : null;
    if (attributes == null) {
        if (nestedMap != null && !(nestedMap instanceof IncompleteChildrenMap)) {
            // our info from parent doesn't mention the child in this refresh session
            return null;
        }
        FileInfo info = myKernel.getInfo(file.getPath());
        if (info == null) {
            return null;
        }
        attributes = info.toFileAttributes();
        if (nestedMap == null) {
            nestedMap = new IncompleteChildrenMap<>(FileUtil.PATH_HASHING_STRATEGY);
            map.put(parentId, nestedMap);
        }
        nestedMap.put(name, attributes);
    }
    return attributes;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) THashMap(gnu.trove.THashMap) FileInfo(com.intellij.openapi.util.io.win32.FileInfo) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) FileAttributes(com.intellij.openapi.util.io.FileAttributes) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with FileInfo

use of com.vmware.vim25.FileInfo in project intellij-community by JetBrains.

the class Win32FsCache method list.

@NotNull
String[] list(@NotNull VirtualFile file) {
    String path = file.getPath();
    FileInfo[] fileInfo = myKernel.listChildren(path);
    if (fileInfo == null || fileInfo.length == 0) {
        return ArrayUtil.EMPTY_STRING_ARRAY;
    }
    String[] names = new String[fileInfo.length];
    TIntObjectHashMap<THashMap<String, FileAttributes>> map = getMap();
    int parentId = ((VirtualFileWithId) file).getId();
    THashMap<String, FileAttributes> nestedMap = map.get(parentId);
    if (nestedMap == null) {
        nestedMap = new THashMap<>(fileInfo.length, FileUtil.PATH_HASHING_STRATEGY);
        map.put(parentId, nestedMap);
    }
    for (int i = 0, length = fileInfo.length; i < length; i++) {
        FileInfo info = fileInfo[i];
        String name = info.getName();
        nestedMap.put(name, info.toFileAttributes());
        names[i] = name;
    }
    return names;
}
Also used : FileInfo(com.intellij.openapi.util.io.win32.FileInfo) THashMap(gnu.trove.THashMap) VirtualFileWithId(com.intellij.openapi.vfs.VirtualFileWithId) FileAttributes(com.intellij.openapi.util.io.FileAttributes) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with FileInfo

use of com.vmware.vim25.FileInfo in project intellij-community by JetBrains.

the class FileAttributesReadingTest method getAttributes.

@NotNull
private static FileAttributes getAttributes(@NotNull final File file, final boolean checkList) {
    final FileAttributes attributes = FileSystemUtil.getAttributes(file);
    assertNotNull(attributes);
    if (SystemInfo.isWindows && checkList) {
        final String parent = file.getParent();
        if (parent != null) {
            final FileInfo[] infos = IdeaWin32.getInstance().listChildren(parent);
            assertNotNull(infos);
            for (FileInfo info : infos) {
                if (file.getName().equals(info.getName())) {
                    assertEquals(attributes, info.toFileAttributes());
                    return attributes;
                }
            }
            fail(file + " not listed");
        }
    }
    return attributes;
}
Also used : FileInfo(com.intellij.openapi.util.io.win32.FileInfo) NotNull(org.jetbrains.annotations.NotNull)

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