use of com.vmware.vim25.VirtualDiskFlatVer2BackingInfo in project cloudstack by apache.
the class VirtualMachineMO method detachAllDisksExcept.
public List<String> detachAllDisksExcept(String vmdkBaseName, String deviceBusName) throws Exception {
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
List<String> detachedDiskFiles = new ArrayList<String>();
for (VirtualDevice device : devices) {
if (device instanceof VirtualDisk) {
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo) device.getBacking();
DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName());
String backingBaseName = dsBackingFile.getFileBaseName();
String deviceNumbering = getDeviceBusName(devices, device);
if (backingBaseName.equalsIgnoreCase(vmdkBaseName) || (deviceBusName != null && deviceBusName.equals(deviceNumbering))) {
continue;
} else {
s_logger.info("Detach " + diskBackingInfo.getFileName() + " from " + getName());
detachedDiskFiles.add(diskBackingInfo.getFileName());
deviceConfigSpec.setDevice(device);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
reConfigSpec.getDeviceChange().add(deviceConfigSpec);
}
}
}
if (detachedDiskFiles.size() > 0) {
ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
boolean result = _context.getVimClient().waitForTask(morTask);
if (result) {
_context.waitForTaskProgressDone(morTask);
} else {
s_logger.warn("Unable to reconfigure the VM to detach disks");
throw new Exception("Unable to reconfigure the VM to detach disks");
}
}
return detachedDiskFiles;
}
use of com.vmware.vim25.VirtualDiskFlatVer2BackingInfo in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getAllIndependentDiskDevice.
public VirtualDisk[] getAllIndependentDiskDevice() throws Exception {
List<VirtualDisk> independentDisks = new ArrayList<VirtualDisk>();
VirtualDisk[] allDisks = getAllDiskDevice();
if (allDisks.length > 0) {
for (VirtualDisk disk : allDisks) {
String diskMode = "";
if (disk.getBacking() instanceof VirtualDiskFlatVer1BackingInfo) {
diskMode = ((VirtualDiskFlatVer1BackingInfo) disk.getBacking()).getDiskMode();
} else if (disk.getBacking() instanceof VirtualDiskFlatVer2BackingInfo) {
diskMode = ((VirtualDiskFlatVer2BackingInfo) disk.getBacking()).getDiskMode();
} else if (disk.getBacking() instanceof VirtualDiskRawDiskMappingVer1BackingInfo) {
diskMode = ((VirtualDiskRawDiskMappingVer1BackingInfo) disk.getBacking()).getDiskMode();
} else if (disk.getBacking() instanceof VirtualDiskSparseVer1BackingInfo) {
diskMode = ((VirtualDiskSparseVer1BackingInfo) disk.getBacking()).getDiskMode();
} else if (disk.getBacking() instanceof VirtualDiskSparseVer2BackingInfo) {
diskMode = ((VirtualDiskSparseVer2BackingInfo) disk.getBacking()).getDiskMode();
}
if (diskMode.indexOf("independent") != -1) {
independentDisks.add(disk);
}
}
}
return independentDisks.toArray(new VirtualDisk[0]);
}
use of com.vmware.vim25.VirtualDiskFlatVer2BackingInfo in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method createDisk.
// vmdkDatastorePath: [datastore name] vmdkFilePath
public void createDisk(String vmdkDatastorePath, VirtualDiskType diskType, VirtualDiskMode diskMode, String rdmDeviceName, int sizeInMb, ManagedObjectReference morDs, int controllerKey) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - createDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: " + vmdkDatastorePath + ", sizeInMb: " + sizeInMb + ", diskType: " + diskType + ", diskMode: " + diskMode + ", rdmDeviceName: " + rdmDeviceName + ", datastore: " + morDs.get_value() + ", controllerKey: " + controllerKey);
assert (vmdkDatastorePath != null);
assert (morDs != null);
if (controllerKey < 0) {
controllerKey = getIDEDeviceControllerKey();
}
VirtualDisk newDisk = new VirtualDisk();
if (diskType == VirtualDiskType.thin || diskType == VirtualDiskType.preallocated || diskType == VirtualDiskType.eagerZeroedThick) {
VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
backingInfo.setDiskMode(diskMode.persistent.toString());
if (diskType == VirtualDiskType.thin) {
backingInfo.setThinProvisioned(true);
} else {
backingInfo.setThinProvisioned(false);
}
if (diskType == VirtualDiskType.eagerZeroedThick) {
backingInfo.setEagerlyScrub(true);
} else {
backingInfo.setEagerlyScrub(false);
}
backingInfo.setDatastore(morDs);
backingInfo.setFileName(vmdkDatastorePath);
newDisk.setBacking(backingInfo);
} else if (diskType == VirtualDiskType.rdm || diskType == VirtualDiskType.rdmp) {
VirtualDiskRawDiskMappingVer1BackingInfo backingInfo = new VirtualDiskRawDiskMappingVer1BackingInfo();
if (diskType == VirtualDiskType.rdm) {
backingInfo.setCompatibilityMode("virtualMode");
} else {
backingInfo.setCompatibilityMode("physicalMode");
}
backingInfo.setDeviceName(rdmDeviceName);
if (diskType == VirtualDiskType.rdm) {
backingInfo.setDiskMode(diskMode.persistent.toString());
}
backingInfo.setDatastore(morDs);
backingInfo.setFileName(vmdkDatastorePath);
newDisk.setBacking(backingInfo);
}
int deviceNumber = getNextDeviceNumber(controllerKey);
newDisk.setControllerKey(controllerKey);
newDisk.setKey(-deviceNumber);
newDisk.setUnitNumber(deviceNumber);
newDisk.setCapacityInKB(sizeInMb * 1024);
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(newDisk);
deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.create);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
deviceConfigSpecArray[0] = deviceConfigSpec;
reConfigSpec.setDeviceChange(deviceConfigSpecArray);
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
if (!result.equals("sucess")) {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - createDisk() done(failed)");
throw new Exception("Unable to create disk " + vmdkDatastorePath + " due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
_context.waitForTaskProgressDone(morTask);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - createDisk() done(successfully)");
}
use of com.vmware.vim25.VirtualDiskFlatVer2BackingInfo in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getDiskDevice.
// return pair of VirtualDisk and disk device bus name(ide0:0, etc)
public Pair<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath, boolean matchExactly) throws Exception {
VirtualDevice[] devices = (VirtualDevice[]) _context.getServiceUtil().getDynamicProperty(_mor, "config.hardware.device");
s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath);
DatastoreFile dsSrcFile = new DatastoreFile(vmdkDatastorePath);
String srcBaseName = dsSrcFile.getFileBaseName();
if (devices != null && devices.length > 0) {
for (VirtualDevice device : devices) {
if (device instanceof VirtualDisk) {
s_logger.info("Test against disk device, controller key: " + device.getControllerKey() + ", unit number: " + device.getUnitNumber());
VirtualDeviceBackingInfo backingInfo = ((VirtualDisk) device).getBacking();
if (backingInfo instanceof VirtualDiskFlatVer2BackingInfo) {
VirtualDiskFlatVer2BackingInfo diskBackingInfo = (VirtualDiskFlatVer2BackingInfo) backingInfo;
do {
s_logger.info("Test against disk backing : " + diskBackingInfo.getFileName());
DatastoreFile dsBackingFile = new DatastoreFile(diskBackingInfo.getFileName());
String backingBaseName = dsBackingFile.getFileBaseName();
if (matchExactly) {
if (backingBaseName.equalsIgnoreCase(srcBaseName)) {
String deviceNumbering = getDeviceBusName(devices, device);
s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
return new Pair<VirtualDisk, String>((VirtualDisk) device, deviceNumbering);
}
} else {
if (backingBaseName.contains(srcBaseName)) {
String deviceNumbering = getDeviceBusName(devices, device);
s_logger.info("Disk backing : " + diskBackingInfo.getFileName() + " matches ==> " + deviceNumbering);
return new Pair<VirtualDisk, String>((VirtualDisk) device, deviceNumbering);
}
}
diskBackingInfo = diskBackingInfo.getParent();
} while (diskBackingInfo != null);
}
}
}
}
return null;
}
use of com.vmware.vim25.VirtualDiskFlatVer2BackingInfo in project CloudStack-archive by CloudStack-extras.
the class VmwareHelper method setParentBackingInfo.
private static void setParentBackingInfo(VirtualDiskFlatVer2BackingInfo backingInfo, Pair<String, ManagedObjectReference>[] parentDatastorePathList) {
VirtualDiskFlatVer2BackingInfo parentBacking = new VirtualDiskFlatVer2BackingInfo();
parentBacking.setDatastore(parentDatastorePathList[0].second());
parentBacking.setDiskMode(VirtualDiskMode.persistent.toString());
if (parentDatastorePathList.length > 1) {
Pair<String, ManagedObjectReference>[] nextDatastorePathList = new Pair[parentDatastorePathList.length - 1];
for (int i = 0; i < parentDatastorePathList.length - 1; i++) nextDatastorePathList[i] = parentDatastorePathList[i + 1];
setParentBackingInfo(parentBacking, nextDatastorePathList);
}
parentBacking.setFileName(parentDatastorePathList[0].first());
backingInfo.setParent(parentBacking);
}
Aggregations