use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method attachDisk.
public void attachDisk(String[] vmdkDatastorePathChain, ManagedObjectReference morDs) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: " + new Gson().toJson(vmdkDatastorePathChain) + ", datastore: " + morDs.get_value());
VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, getScsiDeviceControllerKey(), vmdkDatastorePathChain, morDs, -1, 1);
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(newDisk);
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 - attachDisk() done(failed)");
throw new Exception("Failed to attach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
_context.waitForTaskProgressDone(morTask);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method attachDisk.
public void attachDisk(Pair<String, ManagedObjectReference>[] vmdkDatastorePathChain, int controllerKey) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.get_value() + ", vmdkDatastorePath: " + new Gson().toJson(vmdkDatastorePathChain));
VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, controllerKey, vmdkDatastorePathChain, -1, 1);
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(newDisk);
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 - attachDisk() done(failed)");
throw new Exception("Failed to attach disk due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
_context.waitForTaskProgressDone(morTask);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - attachDisk() done(successfully)");
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method cloneFromDiskChain.
public void cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb, String[] disks, ManagedObjectReference morDs) throws Exception {
assert (disks != null);
assert (disks.length >= 1);
HostMO hostMo = getRunningHost();
VirtualMachineConfigInfo vmConfigInfo = getConfigInfo();
if (!hostMo.createBlankVm(clonedVmName, 1, cpuSpeedMHz, 0, false, memoryMb, 0, vmConfigInfo.getGuestId(), morDs, false))
throw new Exception("Unable to create a blank VM");
VirtualMachineMO clonedVmMo = hostMo.findVmOnHyperHost(clonedVmName);
if (clonedVmMo == null)
throw new Exception("Unable to find just-created blank VM");
boolean bSuccess = false;
try {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
VirtualDevice device = VmwareHelper.prepareDiskDevice(clonedVmMo, -1, disks, morDs, -1, 1);
deviceConfigSpecArray[0].setDevice(device);
deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.add);
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
clonedVmMo.configureVm(vmConfigSpec);
bSuccess = true;
} finally {
if (!bSuccess) {
clonedVmMo.detachAllDisks();
clonedVmMo.destroy();
}
}
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method plugDevice.
public void plugDevice(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.add);
vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
if (!configureVm(vmConfigSpec)) {
throw new Exception("Failed to add devices");
}
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getNicDeviceIndex.
public Pair<Integer, VirtualDevice> getNicDeviceIndex(String networkNamePrefix) 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);
}
}
}
Collections.sort(nics, new Comparator<VirtualDevice>() {
@Override
public int compare(VirtualDevice arg0, VirtualDevice arg1) {
int unitNumber0 = arg0.getUnitNumber() != null ? arg0.getUnitNumber().intValue() : -1;
int unitNumber1 = arg1.getUnitNumber() != null ? arg1.getUnitNumber().intValue() : -1;
if (unitNumber0 < unitNumber1)
return -1;
else if (unitNumber0 > unitNumber1)
return 1;
return 0;
}
});
int index = 0;
String attachedNetworkSummary;
String dvPortGroupName;
for (VirtualDevice nic : nics) {
attachedNetworkSummary = ((VirtualEthernetCard) nic).getDeviceInfo().getSummary();
if (attachedNetworkSummary.startsWith(networkNamePrefix)) {
return new Pair<Integer, VirtualDevice>(new Integer(index), nic);
} else if (attachedNetworkSummary.endsWith("DistributedVirtualPortBackingInfo.summary")) {
dvPortGroupName = getDvPortGroupName((VirtualEthernetCard) nic);
if (dvPortGroupName != null && dvPortGroupName.startsWith(networkNamePrefix)) {
s_logger.debug("Found a dvPortGroup already associated with public NIC.");
return new Pair<Integer, VirtualDevice>(new Integer(index), nic);
}
}
index++;
}
return new Pair<Integer, VirtualDevice>(new Integer(-1), null);
}
Aggregations