protected static void reportUnsupportedVnicProfileFeatures(
      VM vm,
      VmNic nic,
      VnicProfile vnicProfile,
      List<VNIC_PROFILE_PROPERTIES> unsupportedFeatures) {

    if (unsupportedFeatures.isEmpty()) {
      return;
    }

    AuditLogableBase event = new AuditLogableBase();
    event.setVmId(vm.getId());
    event.setVdsGroupId(vm.getVdsGroupId());
    event.setCustomId(nic.getId().toString());
    event.setCompatibilityVersion(vm.getVdsGroupCompatibilityVersion().toString());
    event.addCustomValue("NicName", nic.getName());
    event.addCustomValue("VnicProfile", vnicProfile == null ? null : vnicProfile.getName());
    String[] unsupportedFeatureNames = new String[unsupportedFeatures.size()];
    for (int i = 0; i < unsupportedFeatures.size(); i++) {
      unsupportedFeatureNames[i] = unsupportedFeatures.get(i).getFeatureName();
    }

    event.addCustomValue("UnsupportedFeatures", StringUtils.join(unsupportedFeatureNames, ", "));
    AuditLogDirector.log(event, AuditLogType.VNIC_PROFILE_UNSUPPORTED_FEATURES);
  }
  /**
   * Checks that the destination cluster has all the networks that the given NICs require.<br>
   * No network on a NIC is allowed (it's checked when running VM).
   *
   * @param interfaces The NICs to check networks on.
   * @return Whether the destination cluster has all networks configured or not.
   */
  private boolean validateDestinationClusterContainsNetworks(List<VmNic> interfaces) {
    List<Network> networks =
        DbFacade.getInstance().getNetworkDao().getAllForCluster(targetClusterId);
    StringBuilder missingNets = new StringBuilder();
    for (VmNic iface : interfaces) {
      Network network = NetworkHelper.getNetworkByVnicProfileId(iface.getVnicProfileId());
      if (network != null) {
        boolean exists = false;
        for (Network net : networks) {
          if (net.getName().equals(network.getName())) {
            exists = true;
            break;
          }
        }
        if (!exists) {
          if (missingNets.length() > 0) {
            missingNets.append(", ");
          }
          missingNets.append(network.getName());
        }
      }
    }
    if (missingNets.length() > 0) {
      parentCommand.addCanDoActionMessage(EngineMessage.MOVE_VM_CLUSTER_MISSING_NETWORK);
      parentCommand.addCanDoActionMessageVariable("networks", missingNets.toString());
      return false;
    }

    return true;
  }
  /** @return A new interface that can be used in tests. */
  private static VmNic createNewInterface() {
    VmNic iface = new VmNic();
    iface.setId(Guid.newGuid());
    iface.setMacAddress(RandomUtils.instance().nextString(10));

    return iface;
  }
Exemplo n.º 4
0
 protected void removeNetwork() {
   List<VmNic> list = getVmNicDao().getAllForTemplate(getVmTemplateId());
   for (VmNic iface : list) {
     DbFacade.getInstance()
         .getVmDeviceDao()
         .remove(new VmDeviceId(iface.getId(), getVmTemplateId()));
     getVmNicDao().remove(iface.getId());
   }
 }
 protected void runAddAndVerify(
     VmNic iface,
     boolean reserveExistingMac,
     VerificationMode addMacVerification,
     int osId,
     Version version) {
   OsRepository osRepository = mock(OsRepository.class);
   when(vmInterfaceManager.getOsRepository()).thenReturn(osRepository);
   when(osRepository.hasNicHotplugSupport(any(Integer.class), any(Version.class)))
       .thenReturn(true);
   vmInterfaceManager.add(
       iface, NoOpCompensationContext.getInstance(), reserveExistingMac, osId, version);
   if (reserveExistingMac) {
     verify(macPoolManagerStrategy, times(1)).forceAddMac((iface.getMacAddress()));
   } else {
     verifyZeroInteractions(macPoolManagerStrategy);
   }
   verifyAddDelegatedCorrectly(iface, addMacVerification);
 }
 /**
  * Verify that {@link VmInterfaceManager#removeAll} delegated correctly to {@link
  * MacPoolManagerStrategy} & Daos.
  *
  * @param iface The interface to check for.
  */
 protected void verifyRemoveAllDelegatedCorrectly(VmNic iface) {
   verify(macPoolManagerStrategy, times(1)).freeMac(iface.getMacAddress());
   verify(vmNicDao).remove(iface.getId());
   verify(vmNetworkStatisticsDao).remove(iface.getId());
 }
 /**
  * Verify that {@link VmInterfaceManager#add} delegated correctly to {@link
  * MacPoolManagerStrategy} & Daos.
  *
  * @param iface The interface to check for.
  * @param addMacVerification Mode to check (times(1), never(), etc) for {@link
  *     MacPoolManagerStrategy#addMac(String)}.
  */
 protected void verifyAddDelegatedCorrectly(VmNic iface, VerificationMode addMacVerification) {
   verify(macPoolManagerStrategy, addMacVerification).forceAddMac(iface.getMacAddress());
   verify(vmNicDao).save(iface);
   verify(vmNetworkStatisticsDao).save(iface.getStatistics());
 }