use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method copyAllVmDiskFiles.
public void copyAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, boolean followDiskChain) throws Exception {
VirtualDevice[] disks = getAllDiskDevice();
DatacenterMO dcMo = getOwnerDatacenter().first();
if (disks != null) {
for (VirtualDevice disk : disks) {
List<Pair<String, ManagedObjectReference>> vmdkFiles = this.getDiskDatastorePathChain((VirtualDisk) disk, followDiskChain);
for (Pair<String, ManagedObjectReference> fileItem : vmdkFiles) {
DatastoreMO srcDsMo = new DatastoreMO(_context, fileItem.second());
DatastoreFile srcFile = new DatastoreFile(fileItem.first());
DatastoreFile destFile = new DatastoreFile(destDsMo.getName(), destDsDir, srcFile.getFileName());
Pair<VmdkFileDescriptor, byte[]> vmdkDescriptor = null;
vmdkDescriptor = getVmdkFileInfo(fileItem.first());
s_logger.info("Copy VM disk file " + srcFile.getPath() + " to " + destFile.getPath());
srcDsMo.copyDatastoreFile(fileItem.first(), dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
if (vmdkDescriptor != null) {
String vmdkBaseFileName = vmdkDescriptor.first().getBaseFileName();
String baseFilePath = srcFile.getCompanionPath(vmdkBaseFileName);
destFile = new DatastoreFile(destDsMo.getName(), destDsDir, vmdkBaseFileName);
s_logger.info("Copy VM disk file " + baseFilePath + " to " + destFile.getPath());
srcDsMo.copyDatastoreFile(baseFilePath, dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
}
}
}
}
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method moveAllVmDiskFiles.
// this method relies on un-offical VMware API
@Deprecated
public void moveAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, boolean followDiskChain) throws Exception {
VirtualDevice[] disks = getAllDiskDevice();
DatacenterMO dcMo = getOwnerDatacenter().first();
if (disks != null) {
for (VirtualDevice disk : disks) {
List<Pair<String, ManagedObjectReference>> vmdkFiles = this.getDiskDatastorePathChain((VirtualDisk) disk, followDiskChain);
for (Pair<String, ManagedObjectReference> fileItem : vmdkFiles) {
DatastoreMO srcDsMo = new DatastoreMO(_context, fileItem.second());
DatastoreFile srcFile = new DatastoreFile(fileItem.first());
DatastoreFile destFile = new DatastoreFile(destDsMo.getName(), destDsDir, srcFile.getFileName());
Pair<VmdkFileDescriptor, byte[]> vmdkDescriptor = null;
vmdkDescriptor = getVmdkFileInfo(fileItem.first());
s_logger.info("Move VM disk file " + srcFile.getPath() + " to " + destFile.getPath());
srcDsMo.moveDatastoreFile(fileItem.first(), dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
if (vmdkDescriptor != null) {
String vmdkBaseFileName = vmdkDescriptor.first().getBaseFileName();
String baseFilePath = srcFile.getCompanionPath(vmdkBaseFileName);
destFile = new DatastoreFile(destDsMo.getName(), destDsDir, vmdkBaseFileName);
s_logger.info("Move VM disk file " + baseFilePath + " to " + destFile.getPath());
srcDsMo.moveDatastoreFile(baseFilePath, dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
}
}
}
}
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getNicDevices.
public VirtualDevice[] getNicDevices() throws Exception {
VirtualDevice[] devices = (VirtualDevice[]) _context.getServiceUtil().getDynamicProperty(_mor, "config.hardware.device");
List<VirtualDevice> nics = new ArrayList<VirtualDevice>();
if (devices != null) {
for (VirtualDevice device : devices) {
if (device instanceof VirtualEthernetCard) {
nics.add(device);
}
}
}
return nics.toArray(new VirtualDevice[0]);
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method tearDownDevice.
public void tearDownDevice(VirtualDevice device) throws Exception {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[0].setDevice(device);
deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.remove);
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
if (!configureVm(vmConfigSpec)) {
throw new Exception("Failed to detach devices");
}
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method configureVm.
public boolean configureVm(Ternary<VirtualDevice, VirtualDeviceConfigSpecOperation, VirtualDeviceConfigSpecFileOperation>[] devices) throws Exception {
assert (devices != null);
VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length];
int i = 0;
for (Ternary<VirtualDevice, VirtualDeviceConfigSpecOperation, VirtualDeviceConfigSpecFileOperation> deviceTernary : devices) {
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(deviceTernary.first());
deviceConfigSpec.setOperation(deviceTernary.second());
deviceConfigSpec.setFileOperation(deviceTernary.third());
deviceConfigSpecArray[i++] = deviceConfigSpec;
}
configSpec.setDeviceChange(deviceConfigSpecArray);
ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, configSpec);
String result = _context.getServiceUtil().waitForTask(morTask);
if (result.equals("sucess")) {
_context.waitForTaskProgressDone(morTask);
return true;
} else {
s_logger.error("VMware reconfigVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
return false;
}
Aggregations