private void updateVnicType(VnicProfileView profile, VmNetworkInterface existingVnic, VmNetworkInterface editedVnic) { boolean shouldBePciPassthroughType = profile != null && profile.isPassthrough() && supportedInterfaceTypes != null && supportedInterfaceTypes.contains(VmInterfaceType.pciPassthrough); if (existingVnic == null) { if (shouldBePciPassthroughType) { editedVnic.setType(VmInterfaceType.pciPassthrough.getValue()); } else { editedVnic.setType(defaultType == null ? null : defaultType.getValue()); } } else { VmInterfaceType existingInterfaceType = VmInterfaceType.forValue(existingVnic.getType()); boolean shouldRestoreToDefault = profile != null && !profile.isPassthrough() && VmInterfaceType.pciPassthrough.equals(existingInterfaceType); if (shouldBePciPassthroughType) { existingVnic.setType(VmInterfaceType.pciPassthrough.getValue()); } else if (shouldRestoreToDefault || supportedInterfaceTypes == null || !supportedInterfaceTypes.contains(existingInterfaceType)) { existingVnic.setType(defaultType == null ? null : defaultType.getValue()); } } }
private int getVmInterfaceType(XmlNode resourceSubTypeNode) { String resourceSubType = resourceSubTypeNode != null ? resourceSubTypeNode.innerText : null; if (StringUtils.isNotEmpty(resourceSubType)) { try { return Integer.parseInt(resourceSubType); } catch(NumberFormatException ex) { for (VmInterfaceType vmInterfaceType : VmInterfaceType.values()) { if (vmInterfaceType.getInternalName().equalsIgnoreCase(resourceSubType)) { return vmInterfaceType.getValue(); } } } } return VmInterfaceType.pv.getValue(); }
public void getNicTypeList(final int osId, Version version, AsyncQuery<List<VmInterfaceType>> asyncQuery) { asyncQuery.converterCallback = returnValue -> { ArrayList<String> nics = (ArrayList<String>) returnValue; List<VmInterfaceType> interfaceTypes = new ArrayList<>(); for (String nic : nics) { try { interfaceTypes.add(VmInterfaceType.valueOf(nic)); } catch (IllegalArgumentException e) { // ignore if we can't find the enum value. } } return interfaceTypes; }; Frontend.getInstance().runQuery(QueryType.OsRepository, new OsQueryParameters(OsRepositoryVerb.GetNetworkDevices, osId, version), asyncQuery); }
nic.getVnicProfileName()), dl); addDetailItem(SafeHtmlUtils.fromSafeConstant(constants.typeInterface()), SafeHtmlUtils.fromString(VmInterfaceType.forValue(nic.getType()).getDescription()), dl); addDetailItem(SafeHtmlUtils.fromSafeConstant(constants.macInterface()), SafeHtmlUtils.fromString(nic.getMacAddress()), dl);
@Override protected VmInterfaceType getRawValue(VmNetworkInterface object) { return VmInterfaceType.forValue(object.getType()); } };
protected void updateSingleNic(XmlNode node, VmNetworkInterface iface, int nicIdx) { String networkName = selectSingleNode(node, VMD_CONNECTION, _xmlNS).innerText; iface.setRemoteNetworkName(networkName); iface.setNetworkName(StringUtils.defaultIfEmpty(networkName, null)); XmlNode vnicProfileNameNode = selectSingleNode(node, VMD_VNIC_PROFILE_NAME, _xmlNS); iface.setVnicProfileName(vnicProfileNameNode == null ? null : StringUtils.defaultIfEmpty(vnicProfileNameNode.innerText, null)); XmlNode linkedNode = selectSingleNode(node, VMD_LINKED, _xmlNS); iface.setLinked(linkedNode == null ? true : Boolean.valueOf(linkedNode.innerText)); XmlNode nameNode = selectSingleNode(node, VMD_NAME, _xmlNS); iface.setName(nameNode != null ? nameNode.innerText : String.format("nic%d", nicIdx)); XmlNode resourceSubTypeNode = selectSingleNode(node, "rasd:ResourceSubType", _xmlNS); iface.setType(getVmInterfaceType(resourceSubTypeNode)); XmlNode speed = selectSingleNode(node, "rasd:speed", _xmlNS); iface.setSpeed(speed != null ? Integer.parseInt(speed.innerText) : VmInterfaceType.forValue(iface.getType()) .getSpeed()); }
public VmNic() { super(new VmNetworkStatistics(), VmInterfaceType.pv.getValue()); linked = true; }
@Override public ValidationResult validate(Object value) { VnicProfileView profile = (VnicProfileView) value; if (VmInterfaceType.pciPassthrough.equals(vnicType) && !profile.isPassthrough()) { return ValidationResult.fail(ConstantsManager.getInstance() .getMessages() .vnicTypeDoesntMatchNonPassthroughProfile(vnicType.getDescription())); } if (!VmInterfaceType.pciPassthrough.equals(vnicType) && profile.isPassthrough()) { return ValidationResult.fail(ConstantsManager.getInstance() .getMessages() .vnicTypeDoesntMatchPassthroughProfile(vnicType.getDescription())); } return ValidationResult.ok(); }
protected void updateLinkChangability() { boolean isNullProfileSelected = getProfile().getSelectedItem() == null; if (isNullProfileSelected) { getLinked().setIsChangeable(false); return; } if (VmInterfaceType.pciPassthrough.equals(getNicType().getSelectedItem()) || getProfile().getSelectedItem().isPassthrough()) { getLinked().setEntity(true); getLinked().setIsChangeable(false); getLinked().setChangeProhibitionReason(ConstantsManager.getInstance() .getConstants() .linkStateUpdateNotSupportedForPassthroughVnic()); return; } getLinked().setIsChangeable(true); }
renderLinkState(networkInterface.isLinked()), dl); addDetailItem(SafeHtmlUtils.fromSafeConstant(constants.typeInterface()), SafeHtmlUtils.fromString(VmInterfaceType.forValue(networkInterface.getType()).getDescription()), dl); addDetailItem(templates.sub(constants.speedInterface(), constants.mbps()), SafeHtmlUtils.fromString(String.valueOf(networkInterface.getSpeed())), dl);
@Override protected VmInterfaceType getRawValue(VmNetworkInterface object) { return VmInterfaceType.forValue(object.getType()); } };
private static NetworkInterface<?> createNic(String macAddress, String name, VmInterfaceType vmInterfaceType) { NetworkInterface<?> nic = new VmNetworkInterface(); nic.setName(name); nic.setMacAddress(macAddress); nic.setType(vmInterfaceType == null ? null : vmInterfaceType.getValue()); return nic; }
@Override protected void initSelectedType() { VmInterfaceType selectedNicType = VmInterfaceType.forValue(getNic().getType()); if (selectedNicType == null || !getSupportedVnicTypes().contains(selectedNicType)) { selectedNicType = getDefaultNicTypeByProfile(); } if (getNicType().getItems() == null) { getNicType().setItems(getSupportedVnicTypes(), selectedNicType); } else { getNicType().setSelectedItem(selectedNicType); } }
nic.setType(null); } else { nic.setType(getNicType().getSelectedItem().getValue());
VmInterfaceType nicType = VmInterfaceType.forValue(getVmInterfaceType(resourceSubTypeNode)); if (nicType == VmInterfaceType.pciPassthrough) { vmDevice.setDevice(VmDeviceType.HOST_DEVICE.getName());