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());
      }
    }
  }
Example #2
0
  protected void updateSingleNic(XmlNode node, VmNetworkInterface iface) {
    String networkName = selectSingleNode(node, OvfProperties.VMD_CONNECTION, _xmlNS).innerText;
    iface.setNetworkName(StringUtils.defaultIfEmpty(networkName, null));

    XmlNode vnicProfileNameNode =
        selectSingleNode(node, OvfProperties.VMD_VNIC_PROFILE_NAME, _xmlNS);
    iface.setVnicProfileName(
        vnicProfileNameNode == null
            ? null
            : StringUtils.defaultIfEmpty(vnicProfileNameNode.innerText, null));

    XmlNode linkedNode = selectSingleNode(node, OvfProperties.VMD_LINKED, _xmlNS);
    iface.setLinked(linkedNode == null ? true : Boolean.valueOf(linkedNode.innerText));

    iface.setName(selectSingleNode(node, OvfProperties.VMD_NAME, _xmlNS).innerText);

    String resourceSubType = selectSingleNode(node, "rasd:ResourceSubType", _xmlNS).innerText;
    if (StringUtils.isNotEmpty(resourceSubType)) {
      iface.setType(Integer.parseInt(resourceSubType));
    }

    XmlNode speed = selectSingleNode(node, "rasd:speed", _xmlNS);
    iface.setSpeed(
        (speed != null)
            ? Integer.parseInt(speed.innerText)
            : VmInterfaceType.forValue(iface.getType()).getSpeed());
  }
 static VmNetworkInterface setUpEntityExpectations(
     VmNetworkInterface entity, VmNetworkStatistics statistics, int index, String networkName) {
   expect(entity.getId()).andReturn(GUIDS[index]).anyTimes();
   expect(entity.getVmId()).andReturn(INSTANCE_TYPE_ID).anyTimes();
   expect(entity.getNetworkName()).andReturn(networkName).anyTimes();
   expect(entity.getName()).andReturn(NAMES[index]).anyTimes();
   expect(entity.getMacAddress()).andReturn(ADDRESSES[2]).anyTimes();
   expect(entity.getType()).andReturn(0).anyTimes();
   expect(entity.getSpeed()).andReturn(50).anyTimes();
   return setUpStatisticalEntityExpectations(entity, statistics);
 }
 private VmNetworkInterface setUpNicExpectations() {
   VmNetworkInterface nic = control.createMock(VmNetworkInterface.class);
   expect(nic.getId()).andReturn(NIC_ID).anyTimes();
   expect(nic.getType()).andReturn(0).anyTimes();
   return nic;
 }