Пример #1
0
  @Override
  protected boolean canDoAction() {
    oldHost = getVdsDao().get(getVdsId());
    UpdateHostValidator validator =
        new UpdateHostValidator(
            getDbFacade(), oldHost, getParameters().getvds(), getParameters().isInstallHost());

    return validate(validator.hostExists())
        && validate(validator.hostStatusValid())
        && validate(validator.nameNotEmpty())
        && validate(validator.nameLengthIsLegal())
        && validate(validator.updateHostAddressAllowed())
        && validate(validator.nameNotUsed())
        && validate(validator.hostNameNotUsed())
        && validate(validator.statusSupportedForHostInstallation())
        && validate(
            validator.passwordProvidedForHostInstallation(
                getParameters().getAuthMethod(), getParameters().getPassword()))
        && validate(validator.updatePortAllowed())
        && validate(validator.clusterNotChanged())
        && validate(validator.changeProtocolAllowed())
        && validate(validator.hostProviderExists())
        && validate(validator.hostProviderTypeMatches())
        && validateNetworkProviderConfiguration()
        && isPowerManagementLegal(
            getParameters().getVdsStaticData().isPmEnabled(),
            getParameters().getFenceAgents(),
            oldHost.getVdsGroupCompatibilityVersion().toString())
        && validate(validator.protocolIsNotXmlrpc(getVdsGroup()));
  }
  @Before
  public void setupMocks() {
    when(dbFacade.getVdsDao()).thenReturn(vdsDao);

    when(vdsDao.get(eq(TARGET_HOST_ID))).thenReturn(targetHost);
    when(targetHost.getId()).thenReturn(TARGET_HOST_ID);

    when(vdsDao.get(eq(PROXY_HOST_ID))).thenReturn(proxyHost);
    when(proxyHost.getId()).thenReturn(PROXY_HOST_ID);
    when(proxyHost.getVdsGroupCompatibilityVersion()).thenReturn(Version.getLast());
  }
Пример #3
0
  public void postUpdateHost(Collection<VDS> hosts) {
    // Filter hosts
    hosts = Linq.where(hosts, new Linq.HostStatusPredicate(VDSStatus.Up));

    // Allow only hosts with version above 2.2 for export storage.
    ArrayList<VDS> list = new ArrayList<VDS>();
    if (getCurrentStorageItem() != null
        && getCurrentStorageItem().getRole() == StorageDomainType.ImportExport) {
      for (VDS host : hosts) {
        if (host.getVdsGroupCompatibilityVersion().compareTo(new Version("2.2"))
            >= 0) { //$NON-NLS-1$
          list.add(host);
        }
      }
      hosts = list;
    }

    VDS oldSelectedItem = getHost().getSelectedItem();
    VDS selectedItem = null;

    // On Edit of active storage - only SPM is available. In edit of storage in maintenance,
    // any host can perform the operation, thus no need to filter to use just the SPM
    if (getStorage() != null && getStorage().getStatus() != StorageDomainStatus.Maintenance) {
      VDS spm = getSPM(hosts);
      hosts = spm != null ? Collections.singletonList(spm) : Collections.<VDS>emptyList();
    }

    // Try to select previously selected host.
    if (oldSelectedItem != null) {
      selectedItem = Linq.firstOrDefault(hosts, new Linq.HostPredicate(oldSelectedItem.getId()));
    }

    // Select a default - if there's a SPM choose it, otherwise choose the first host in the list.
    if (selectedItem == null) {
      VDS spm = getSPM(hosts);
      selectedItem = spm == null ? Linq.firstOrDefault(hosts) : spm;
    }

    getHost().setItems(hosts, selectedItem);
  }
  private Map<String, Object> generateNetworks() {
    Map<String, Object> networks = new HashMap<String, Object>();
    NetworkQoSDao qosDao = getDbFacade().getQosDao();
    for (Network network : getParameters().getNetworks()) {
      Map<String, Object> opts = new HashMap<String, Object>();
      VdsNetworkInterface iface =
          findNetworkInterface(
              network.getName(), getParameters().getInterfaces(), getParameters().getBonds());
      String ifaceNameWithoutVlan = NetworkUtils.stripVlan(iface);
      Boolean bonded = findInterfaceByName(ifaceNameWithoutVlan).getBonded();
      String type = (bonded != null && bonded) ? "bonding" : "nic";
      opts.put(type, ifaceNameWithoutVlan);
      if (NetworkUtils.isVlan(network)) {
        opts.put("vlan", network.getVlanId().toString());
      }

      if (iface.getBootProtocol() != null) {
        addBootProtocol(opts, iface);
      }

      if (network.getMtu() == 0) {
        opts.put("mtu", NetworkUtils.getDefaultMtu().toString());
      } else {
        opts.put("mtu", String.valueOf(network.getMtu()));
      }

      opts.put("bridged", Boolean.toString(network.isVmNetwork()));
      if (network.isVmNetwork()) {
        opts.put(VdsProperties.STP, network.getStp() ? "yes" : "no");
      }

      VDS host = getDbFacade().getVdsDao().get(getParameters().getVdsId());
      Version version = host.getVdsGroupCompatibilityVersion();
      if (qosConfiguredOnInterface(iface, network) && FeatureSupported.hostNetworkQos(version)) {
        NetworkQosMapper qosMapper =
            new NetworkQosMapper(
                opts, VdsProperties.HOST_QOS_INBOUND, VdsProperties.HOST_QOS_OUTBOUND);
        qosMapper.serialize(
            iface.isQosOverridden() ? iface.getQos() : qosDao.get(network.getQosId()));
      }

      Set<Version> supportedClusterVersionsSet = host.getSupportedClusterVersionsSet();
      if (supportedClusterVersionsSet == null || supportedClusterVersionsSet.isEmpty()) {
        log.warnFormat(
            "Host {0} ({1}) doesn't contain Supported Cluster Versions, therefore 'defaultRoute'"
                + " will not be sent via the SetupNetworks",
            host.getName(), host.getId());
      } else if (FeatureSupported.defaultRoute(Collections.max(supportedClusterVersionsSet))
          && NetworkUtils.isManagementNetwork(network)
          && (iface.getBootProtocol() == NetworkBootProtocol.DHCP
              || (iface.getBootProtocol() == NetworkBootProtocol.STATIC_IP
                  && StringUtils.isNotEmpty(iface.getGateway())))) {
        opts.put(DEFAULT_ROUTE, Boolean.TRUE);
      }

      if (iface.hasCustomProperties()) {
        opts.put(VdsProperties.NETWORK_CUSTOM_PROPERTIES, iface.getCustomProperties());
      }

      networks.put(network.getName(), opts);
    }

    for (String net : getParameters().getRemovedNetworks()) {
      networks.put(net, REMOVE_OBJ);
    }

    return networks;
  }