use of com.vmware.vim25.VirtualDevice in project cloudstack by apache.
the class VirtualMachineMO method getNicDevices.
private List<VirtualDevice> getNicDevices(boolean sorted) throws Exception {
List<VirtualDevice> devices = _context.getVimClient().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);
}
}
}
if (sorted) {
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;
}
});
}
return nics;
}
use of com.vmware.vim25.VirtualDevice 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.VirtualDevice in project cloudstack by apache.
the class VirtualMachineMO method getMatchedDevices.
public VirtualDevice[] getMatchedDevices(Class<?>[] deviceClasses) throws Exception {
assert (deviceClasses != null);
List<VirtualDevice> returnList = new ArrayList<VirtualDevice>();
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
if (devices != null) {
for (VirtualDevice device : devices) {
for (Class<?> clz : deviceClasses) {
if (clz.isInstance(device)) {
returnList.add(device);
break;
}
}
}
}
return returnList.toArray(new VirtualDevice[0]);
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method tearDownDevices.
public void tearDownDevices(Class<?>[] deviceClasses) throws Exception {
VirtualDevice[] devices = getMatchedDevices(deviceClasses);
if (devices.length > 0) {
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length];
for (int i = 0; i < devices.length; i++) {
deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
deviceConfigSpecArray[i].setDevice(devices[i]);
deviceConfigSpecArray[i].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 detachIso.
public void detachIso(String isoDatastorePath) throws Exception {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.get_value() + ", isoDatastorePath: " + isoDatastorePath);
VirtualDevice device = getIsoDevice();
if (device == null) {
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachIso() done(failed)");
throw new Exception("Unable to find a CDROM device");
}
VirtualCdromRemotePassthroughBackingInfo backingInfo = new VirtualCdromRemotePassthroughBackingInfo();
backingInfo.setDeviceName("");
device.setBacking(backingInfo);
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(device);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
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 - detachIso() done(failed)");
throw new Exception("Failed to detachIso due to " + TaskMO.getTaskFailureInfo(_context, morTask));
}
_context.waitForTaskProgressDone(morTask);
if (s_logger.isTraceEnabled())
s_logger.trace("vCenter API trace - detachIso() done(successfully)");
}
Aggregations