use of com.vmware.vim25.VirtualDevice in project cloudstack by apache.
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.getValue());
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;
}
use of com.vmware.vim25.VirtualDevice in project cloudstack by apache.
the class VirtualMachineMO method getVirtualDisks.
public List<VirtualDisk> getVirtualDisks() throws Exception {
List<VirtualDisk> virtualDisks = new ArrayList<VirtualDisk>();
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
for (VirtualDevice device : devices) {
if (device instanceof VirtualDisk) {
virtualDisks.add((VirtualDisk) device);
}
}
return virtualDisks;
}
use of com.vmware.vim25.VirtualDevice in project cloudstack by apache.
the class VirtualMachineMO method getNicDeviceIndex.
public Pair<Integer, VirtualDevice> getNicDeviceIndex(String networkNamePrefix) throws Exception {
List<VirtualDevice> nics = getNicDevices(true);
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") || attachedNetworkSummary.startsWith("DVSwitch")) {
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);
}
use of com.vmware.vim25.VirtualDevice in project cloudstack by apache.
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.getValue() + ", vmdkDatastorePath: " + new Gson().toJson(vmdkDatastorePathChain));
synchronized (_mor.getValue().intern()) {
VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, controllerKey, vmdkDatastorePathChain, -1, 1);
VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(newDisk);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
reConfigSpec.getDeviceChange().add(deviceConfigSpec);
ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
boolean result = _context.getVimClient().waitForTask(morTask);
if (!result) {
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)");
}
Aggregations