use of com.vmware.vim25.VirtualDevice 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]);
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getNextDeviceNumber.
public int getNextDeviceNumber(int controllerKey) throws Exception {
VirtualDevice[] devices = (VirtualDevice[]) _context.getServiceUtil().getDynamicProperty(_mor, "config.hardware.device");
int deviceNumber = -1;
if (devices != null && devices.length > 0) {
for (VirtualDevice device : devices) {
if (device.getControllerKey() != null && device.getControllerKey().intValue() == controllerKey) {
if (device.getUnitNumber() != null && device.getUnitNumber().intValue() > deviceNumber) {
deviceNumber = device.getUnitNumber().intValue();
}
}
}
}
return ++deviceNumber;
}
use of com.vmware.vim25.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getMatchedDevices.
public VirtualDevice[] getMatchedDevices(Class<?>[] deviceClasses) throws Exception {
assert (deviceClasses != null);
List<VirtualDevice> returnList = new ArrayList<VirtualDevice>();
VirtualDevice[] devices = (VirtualDevice[]) _context.getServiceUtil().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 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.VirtualDevice in project CloudStack-archive by CloudStack-extras.
the class VmwareHelper method prepareDvNicDevice.
public static VirtualDevice prepareDvNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType, String dvPortGroupName, String dvSwitchUuid, String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean connectOnStart) throws Exception {
VirtualEthernetCard nic;
switch(deviceType) {
case E1000:
nic = new VirtualE1000();
break;
case PCNet32:
nic = new VirtualPCNet32();
break;
case Vmxnet2:
nic = new VirtualVmxnet2();
break;
case Vmxnet3:
nic = new VirtualVmxnet3();
break;
default:
assert (false);
nic = new VirtualE1000();
}
final VirtualEthernetCardDistributedVirtualPortBackingInfo dvPortBacking = new VirtualEthernetCardDistributedVirtualPortBackingInfo();
final DistributedVirtualSwitchPortConnection dvPortConnection = new DistributedVirtualSwitchPortConnection();
final VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
dvPortConnection.setSwitchUuid(dvSwitchUuid);
dvPortConnection.setPortgroupKey(morNetwork.get_value());
dvPortBacking.setPort(dvPortConnection);
nic.setBacking(dvPortBacking);
nic.setKey(30);
connectInfo.setAllowGuestControl(true);
connectInfo.setConnected(conntected);
connectInfo.setStartConnected(connectOnStart);
nic.setAddressType("Manual");
nic.setConnectable(connectInfo);
nic.setMacAddress(macAddress);
nic.setUnitNumber(deviceNumber);
nic.setKey(-contextNumber);
return nic;
}
Aggregations