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();
}
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;
}
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;
}
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;
}
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;
}
Aggregations