use of com.vmware.vim25.VirtualVmxnet3 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.VirtualVmxnet3 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;
}
use of com.vmware.vim25.VirtualVmxnet3 in project cloudstack by apache.
the class VmwareResource method getUnmanageInstanceNics.
private List<UnmanagedInstanceTO.Nic> getUnmanageInstanceNics(VmwareHypervisorHost hyperHost, VirtualMachineMO vmMo) {
List<UnmanagedInstanceTO.Nic> instanceNics = new ArrayList<>();
HashMap<String, List<String>> guestNicMacIPAddressMap = new HashMap<>();
try {
GuestInfo guestInfo = vmMo.getGuestInfo();
if (guestInfo.getToolsStatus() == VirtualMachineToolsStatus.TOOLS_OK) {
for (GuestNicInfo nicInfo : guestInfo.getNet()) {
if (CollectionUtils.isNotEmpty(nicInfo.getIpAddress())) {
List<String> ipAddresses = new ArrayList<>();
for (String ipAddress : nicInfo.getIpAddress()) {
if (NetUtils.isValidIp4(ipAddress)) {
ipAddresses.add(ipAddress);
}
}
guestNicMacIPAddressMap.put(nicInfo.getMacAddress(), ipAddresses);
}
}
} else {
s_logger.info(String.format("Unable to retrieve guest nics for instance: %s from VMware tools as tools status: %s", vmMo.getName(), guestInfo.getToolsStatus().toString()));
}
} catch (Exception e) {
s_logger.info("Unable to retrieve guest nics for instance from VMware tools. " + e.getMessage());
}
VirtualDevice[] nics = null;
try {
nics = vmMo.getNicDevices();
} catch (Exception e) {
s_logger.info("Unable to retrieve unmanaged instance nics. " + e.getMessage());
}
if (nics != null) {
for (VirtualDevice nic : nics) {
try {
VirtualEthernetCard ethCardDevice = (VirtualEthernetCard) nic;
s_logger.error(nic.getClass().getCanonicalName() + " " + nic.getBacking().getClass().getCanonicalName() + " " + ethCardDevice.getMacAddress());
UnmanagedInstanceTO.Nic instanceNic = new UnmanagedInstanceTO.Nic();
instanceNic.setNicId(ethCardDevice.getDeviceInfo().getLabel());
if (ethCardDevice instanceof VirtualPCNet32) {
instanceNic.setAdapterType(VirtualEthernetCardType.PCNet32.toString());
} else if (ethCardDevice instanceof VirtualVmxnet2) {
instanceNic.setAdapterType(VirtualEthernetCardType.Vmxnet2.toString());
} else if (ethCardDevice instanceof VirtualVmxnet3) {
instanceNic.setAdapterType(VirtualEthernetCardType.Vmxnet3.toString());
} else {
instanceNic.setAdapterType(VirtualEthernetCardType.E1000.toString());
}
instanceNic.setMacAddress(ethCardDevice.getMacAddress());
if (guestNicMacIPAddressMap.containsKey(instanceNic.getMacAddress())) {
instanceNic.setIpAddress(guestNicMacIPAddressMap.get(instanceNic.getMacAddress()));
}
if (ethCardDevice.getSlotInfo() != null) {
instanceNic.setPciSlot(ethCardDevice.getSlotInfo().toString());
}
VirtualDeviceBackingInfo backing = ethCardDevice.getBacking();
if (backing instanceof VirtualEthernetCardDistributedVirtualPortBackingInfo) {
VirtualEthernetCardDistributedVirtualPortBackingInfo backingInfo = (VirtualEthernetCardDistributedVirtualPortBackingInfo) backing;
DistributedVirtualSwitchPortConnection port = backingInfo.getPort();
String portKey = port.getPortKey();
String portGroupKey = port.getPortgroupKey();
String dvSwitchUuid = port.getSwitchUuid();
s_logger.debug("NIC " + nic.toString() + " is connected to dvSwitch " + dvSwitchUuid + " pg " + portGroupKey + " port " + portKey);
ManagedObjectReference dvSwitchManager = vmMo.getContext().getVimClient().getServiceContent().getDvSwitchManager();
ManagedObjectReference dvSwitch = vmMo.getContext().getVimClient().getService().queryDvsByUuid(dvSwitchManager, dvSwitchUuid);
// Get all ports
DistributedVirtualSwitchPortCriteria criteria = new DistributedVirtualSwitchPortCriteria();
criteria.setInside(true);
criteria.getPortgroupKey().add(portGroupKey);
List<DistributedVirtualPort> dvPorts = vmMo.getContext().getVimClient().getService().fetchDVPorts(dvSwitch, criteria);
for (DistributedVirtualPort dvPort : dvPorts) {
// Find the port for this NIC by portkey
if (portKey.equals(dvPort.getKey())) {
VMwareDVSPortSetting settings = (VMwareDVSPortSetting) dvPort.getConfig().getSetting();
if (settings.getVlan() instanceof VmwareDistributedVirtualSwitchVlanIdSpec) {
VmwareDistributedVirtualSwitchVlanIdSpec vlanId = (VmwareDistributedVirtualSwitchVlanIdSpec) settings.getVlan();
s_logger.trace("Found port " + dvPort.getKey() + " with vlan " + vlanId.getVlanId());
if (vlanId.getVlanId() > 0 && vlanId.getVlanId() < 4095) {
instanceNic.setVlan(vlanId.getVlanId());
}
} else if (settings.getVlan() instanceof VmwareDistributedVirtualSwitchPvlanSpec) {
VmwareDistributedVirtualSwitchPvlanSpec pvlanSpec = (VmwareDistributedVirtualSwitchPvlanSpec) settings.getVlan();
s_logger.trace("Found port " + dvPort.getKey() + " with pvlan " + pvlanSpec.getPvlanId());
if (pvlanSpec.getPvlanId() > 0 && pvlanSpec.getPvlanId() < 4095) {
DistributedVirtualSwitchMO dvSwitchMo = new DistributedVirtualSwitchMO(vmMo.getContext(), dvSwitch);
Pair<Integer, HypervisorHostHelper.PvlanType> vlanDetails = dvSwitchMo.retrieveVlanFromPvlan(pvlanSpec.getPvlanId(), dvSwitch);
if (vlanDetails != null && vlanDetails.first() != null && vlanDetails.second() != null) {
instanceNic.setVlan(vlanDetails.first());
instanceNic.setPvlan(pvlanSpec.getPvlanId());
instanceNic.setPvlanType(vlanDetails.second().toString());
}
}
}
break;
}
}
} else if (backing instanceof VirtualEthernetCardNetworkBackingInfo) {
VirtualEthernetCardNetworkBackingInfo backingInfo = (VirtualEthernetCardNetworkBackingInfo) backing;
instanceNic.setNetwork(backingInfo.getDeviceName());
if (hyperHost instanceof HostMO) {
HostMO hostMo = (HostMO) hyperHost;
HostPortGroupSpec portGroupSpec = hostMo.getHostPortGroupSpec(backingInfo.getDeviceName());
instanceNic.setVlan(portGroupSpec.getVlanId());
}
}
instanceNics.add(instanceNic);
} catch (Exception e) {
s_logger.info("Unable to retrieve unmanaged instance nic info. " + e.getMessage());
}
}
Collections.sort(instanceNics, new Comparator<UnmanagedInstanceTO.Nic>() {
@Override
public int compare(final UnmanagedInstanceTO.Nic nic1, final UnmanagedInstanceTO.Nic nic2) {
return extractInt(nic1) - extractInt(nic2);
}
int extractInt(UnmanagedInstanceTO.Nic nic) {
String num = nic.getNicId().replaceAll("\\D", "");
// return 0 if no digits found
return num.isEmpty() ? 0 : Integer.parseInt(num);
}
});
}
return instanceNics;
}
Aggregations