use of com.vmware.vim25.VirtualDisk in project cloudstack by apache.
the class VirtualMachineMO method getDiskDeviceByBusName.
public VirtualDisk getDiskDeviceByBusName(List<VirtualDevice> allDevices, String busName) throws Exception {
for (VirtualDevice device : allDevices) {
if (device instanceof VirtualDisk) {
VirtualDisk disk = (VirtualDisk) device;
String diskBusName = getDeviceBusName(allDevices, disk);
if (busName.equalsIgnoreCase(diskBusName))
return disk;
}
}
return null;
}
use of com.vmware.vim25.VirtualDisk 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.VirtualDisk 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.VirtualDisk in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method createLinkedClone.
public boolean createLinkedClone(String cloneName, ManagedObjectReference morBaseSnapshot, ManagedObjectReference morFolder, ManagedObjectReference morResourcePool, ManagedObjectReference morDs) throws Exception {
assert (morBaseSnapshot != null);
assert (morFolder != null);
assert (morResourcePool != null);
assert (morDs != null);
VirtualDisk[] independentDisks = getAllIndependentDiskDevice();
VirtualMachineRelocateSpec rSpec = new VirtualMachineRelocateSpec();
if (independentDisks.length > 0) {
VirtualMachineRelocateSpecDiskLocator[] diskLocator = new VirtualMachineRelocateSpecDiskLocator[independentDisks.length];
for (int i = 0; i < diskLocator.length; i++) {
diskLocator[i] = new VirtualMachineRelocateSpecDiskLocator();
diskLocator[i].setDatastore(morDs);
diskLocator[i].setDiskId(independentDisks[i].getKey());
diskLocator[i].setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._moveAllDiskBackingsAndDisallowSharing);
}
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._createNewChildDiskBacking);
rSpec.setDisk(diskLocator);
} else {
rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions._createNewChildDiskBacking);
}
rSpec.setPool(morResourcePool);
VirtualMachineCloneSpec cloneSpec = new VirtualMachineCloneSpec();
cloneSpec.setPowerOn(false);
cloneSpec.setTemplate(false);
cloneSpec.setLocation(rSpec);
cloneSpec.setSnapshot(morBaseSnapshot);
ManagedObjectReference morTask = _context.getService().cloneVM_Task(_mor, morFolder, cloneName, cloneSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware cloneVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
use of com.vmware.vim25.VirtualDisk in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getAllDiskDevice.
public VirtualDisk[] getAllDiskDevice() throws Exception {
List<VirtualDisk> deviceList = new ArrayList<VirtualDisk>();
VirtualDevice[] devices = (VirtualDevice[]) _context.getServiceUtil().getDynamicProperty(_mor, "config.hardware.device");
if (devices != null && devices.length > 0) {
for (VirtualDevice device : devices) {
if (device instanceof VirtualDisk) {
deviceList.add((VirtualDisk) device);
}
}
}
return deviceList.toArray(new VirtualDisk[0]);
}
Aggregations