use of com.vmware.vim25.VirtualEthernetCard 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.VirtualEthernetCard in project CloudStack-archive by CloudStack-extras.
the class VirtualMachineMO method getDvPortGroupName.
public String getDvPortGroupName(VirtualEthernetCard nic) throws Exception {
VirtualEthernetCardDistributedVirtualPortBackingInfo dvpBackingInfo = (VirtualEthernetCardDistributedVirtualPortBackingInfo) ((VirtualEthernetCard) nic).getBacking();
DistributedVirtualSwitchPortConnection dvsPort = (DistributedVirtualSwitchPortConnection) dvpBackingInfo.getPort();
String dvPortGroupKey = dvsPort.getPortgroupKey();
ManagedObjectReference dvPortGroupMor = new ManagedObjectReference();
dvPortGroupMor.set_value(dvPortGroupKey);
dvPortGroupMor.setType("DistributedVirtualPortgroup");
return (String) _context.getServiceUtil().getDynamicProperty(dvPortGroupMor, "name");
}
use of com.vmware.vim25.VirtualEthernetCard in project CloudStack-archive by CloudStack-extras.
the class VmwareHelper method prepareNicDevice.
public static VirtualDevice prepareNicDevice(VirtualMachineMO vmMo, ManagedObjectReference morNetwork, VirtualEthernetCardType deviceType, String portGroupName, 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();
}
VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
nicBacking.setDeviceName(portGroupName);
nicBacking.setNetwork(morNetwork);
nic.setBacking(nicBacking);
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
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.VirtualEthernetCard in project cloudstack by apache.
the class VmwareResource method plugPublicNic.
private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final String vifMacAddress) throws Exception {
// TODO : probably need to set traffic shaping
Pair<ManagedObjectReference, String> networkInfo = null;
VirtualSwitchType vSwitchType = VirtualSwitchType.StandardVirtualSwitch;
if (_publicTrafficInfo != null) {
vSwitchType = _publicTrafficInfo.getVirtualSwitchType();
}
/** FIXME We have no clue which network this nic is on and that means that we can't figure out the BroadcastDomainType
* so we assume that it's VLAN for now
*/
if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) {
networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, _opsTimeout, true, BroadcastDomainType.Vlan, null);
} else {
networkInfo = HypervisorHostHelper.prepareNetwork(_publicTrafficInfo.getVirtualSwitchName(), "cloud.public", vmMo.getRunningHost(), vlanId, null, null, null, _opsTimeout, vSwitchType, _portsPerDvPortGroup, null, false, BroadcastDomainType.Vlan, _vsmCredentials);
}
int nicIndex = allocPublicNicIndex(vmMo);
try {
VirtualDevice[] nicDevices = vmMo.getNicDevices();
VirtualEthernetCard device = (VirtualEthernetCard) nicDevices[nicIndex];
if (VirtualSwitchType.StandardVirtualSwitch == vSwitchType) {
VirtualEthernetCardNetworkBackingInfo nicBacking = new VirtualEthernetCardNetworkBackingInfo();
nicBacking.setDeviceName(networkInfo.second());
nicBacking.setNetwork(networkInfo.first());
device.setBacking(nicBacking);
} else {
HostMO hostMo = vmMo.getRunningHost();
DatacenterMO dataCenterMo = new DatacenterMO(hostMo.getContext(), hostMo.getHyperHostDatacenter());
device.setBacking(dataCenterMo.getDvPortBackingInfo(networkInfo));
}
VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
//VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setDevice(device);
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
if (!vmMo.configureVm(vmConfigSpec)) {
throw new Exception("Failed to configure devices when plugPublicNic");
}
} catch (Exception e) {
// restore allocation mask in case of exceptions
String nicMasksStr = vmMo.getCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK);
int nicMasks = Integer.parseInt(nicMasksStr);
nicMasks &= ~(1 << nicIndex);
vmMo.setCustomFieldValue(CustomFieldConstants.CLOUD_NIC_MASK, String.valueOf(nicMasks));
throw e;
}
}
use of com.vmware.vim25.VirtualEthernetCard in project cloudstack by apache.
the class VmwareHelper method prepareNicOpaque.
public static VirtualDevice prepareNicOpaque(VirtualMachineMO vmMo, VirtualEthernetCardType deviceType, String portGroupName, String macAddress, int deviceNumber, int contextNumber, boolean conntected, boolean connectOnStart) throws Exception {
assert (vmMo.getRunningHost().hasOpaqueNSXNetwork());
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:
nic = new VirtualE1000();
}
VirtualEthernetCardOpaqueNetworkBackingInfo nicBacking = new VirtualEthernetCardOpaqueNetworkBackingInfo();
nicBacking.setOpaqueNetworkId("br-int");
nicBacking.setOpaqueNetworkType("nsx.network");
nic.setBacking(nicBacking);
VirtualDeviceConnectInfo connectInfo = new VirtualDeviceConnectInfo();
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