Esempio n. 1
0
  @Override
  protected void executeCommand() {
    updateVdsData();
    if (NeedToUpdateVdsBroker()) {
      initializeVds();
    }

    if (getParameters().isInstallHost()) {
      InstallVdsParameters tempVar =
          new InstallVdsParameters(getVdsId(), getParameters().getPassword());
      tempVar.setIsReinstallOrUpgrade(getParameters().isReinstallOrUpgrade());
      tempVar.setoVirtIsoFile(getParameters().getoVirtIsoFile());
      if (getVdsDao().get(getVdsId()).getStatus() == VDSStatus.InstallingOS) {
        // TODO: remove hack when reinstall api will provider override-firewall parameter.
        // https://bugzilla.redhat.com/show_bug.cgi?id=1177126 - for now we override firewall
        // configurations on each deploy for provisioned host to avoid wrong deployment.
        tempVar.setOverrideFirewall(true);
      } else {
        tempVar.setOverrideFirewall(getParameters().getOverrideFirewall());
      }
      tempVar.setOverrideFirewall(getParameters().getOverrideFirewall());
      tempVar.setActivateHost(getParameters().getActivateHost());
      tempVar.setNetworkProviderId(getParameters().getNetworkProviderId());
      tempVar.setNetworkMappings(getParameters().getNetworkMappings());
      tempVar.setAuthMethod(getParameters().getAuthMethod());
      ArrayList<VdcReturnValueBase> resultList =
          runInternalMultipleActions(
              actionType, new ArrayList<VdcActionParametersBase>(Arrays.asList(tempVar)));

      // Since Host status is set to "Installing", failure of InstallVdsCommand will hang the Host
      // to in that
      // status, therefore needed to fail the command to revert the status.
      if (!resultList.isEmpty()) {
        VdcReturnValueBase vdcReturnValueBase = resultList.get(0);
        if (vdcReturnValueBase != null && !vdcReturnValueBase.getCanDoAction()) {
          ArrayList<String> canDoActionMessages = vdcReturnValueBase.getCanDoActionMessages();
          if (!canDoActionMessages.isEmpty()) {
            // add can do action messages to return value so error messages
            // are returned back to the client
            getReturnValue().getCanDoActionMessages().addAll(canDoActionMessages);
            log.error(
                "Installation/upgrade of Host '{}', '{}' failed: {}",
                getVdsId(),
                getVdsName(),
                StringUtils.join(
                    Backend.getInstance()
                        .getErrorsTranslator()
                        .TranslateErrorText(canDoActionMessages),
                    ","));
          }
          // set can do action to false so can do action messages are
          // returned back to client
          getReturnValue().setCanDoAction(false);
          setSucceeded(false);
          // add old vds dynamic data to compensation context. This
          // way the status will revert back to what it was before
          // starting installation process
          getCompensationContext().snapshotEntityStatus(oldHost.getDynamicData());
          getCompensationContext().stateChanged();
          return;
        }
      }
    }

    if (oldHost.getProtocol() != getParameters().getVdsStaticData().getProtocol()) {
      ResourceManager.getInstance().reestablishConnection(oldHost.getId());
    }

    // set clusters network to be operational (if needed)
    if (oldHost.getStatus() == VDSStatus.Up) {
      List<NetworkCluster> networkClusters =
          DbFacade.getInstance().getNetworkClusterDao().getAllForCluster(oldHost.getVdsGroupId());
      List<Network> networks =
          DbFacade.getInstance().getNetworkDao().getAllForCluster(oldHost.getVdsGroupId());
      for (NetworkCluster item : networkClusters) {
        for (Network net : networks) {
          if (net.getId().equals(item.getNetworkId())) {
            NetworkClusterHelper.setStatus(oldHost.getVdsGroupId(), net);
          }
        }
      }
    }
    alertIfPowerManagementNotConfigured(getParameters().getVdsStaticData());
    testVdsPowerManagementStatus(getParameters().getVdsStaticData());
    checkKdumpIntegrationStatus();
    setSucceeded(true);
  }
  @Override
  protected void executeCommand() {
    String address = getParameters().getAddress();
    String subnet =
        StringUtils.isEmpty(getParameters().getSubnet())
            ? getParameters().getNetwork().getSubnet()
            : getParameters().getSubnet();
    String gateway =
        StringUtils.isEmpty(getParameters().getGateway()) ? "" : getParameters().getGateway();
    ArrayList<String> interfaceNames = new ArrayList<>();

    Map<String, VdsNetworkInterface> interfaceByName = Entities.entitiesByName(interfaces);
    for (VdsNetworkInterface i : getParameters().getInterfaces()) {
      VdsNetworkInterface existingIface = interfaceByName.get(i.getName());
      if (Boolean.TRUE.equals(existingIface.getBonded())
          || NetworkUtils.isBondVlan(interfaces, existingIface)) {
        getParameters().setBondName(NetworkUtils.stripVlan(existingIface));
        for (VdsNetworkInterface ix : interfaces) {
          if (NetworkUtils.interfaceBasedOn(existingIface, ix.getBondName())) {
            interfaceNames.add(NetworkUtils.stripVlan(ix));
          }
        }
      } else {
        interfaceNames.add(NetworkUtils.stripVlan(existingIface));
      }
    }

    // updating a vlan over bond if the bond was not provided the bond device should preserve the
    // bonding options
    String bondingOptions = null;
    if (getParameters().getBondingOptions() == null
        && getParameters().getBondName() != null
        && !Entities.entitiesByName(getParameters().getInterfaces())
            .containsKey(getParameters().getBondName())) {
      VdsNetworkInterface bond =
          Entities.entitiesByName(interfaces).get(getParameters().getBondName());
      bondingOptions = bond == null ? null : bond.getBondOptions();
    } else {
      bondingOptions = getParameters().getBondingOptions();
    }

    NetworkVdsmVDSCommandParameters parameters =
        new NetworkVdsmVDSCommandParameters(
            getParameters().getVdsId(),
            getParameters().getNetwork().getName(),
            getParameters().getNetwork().getVlanId(),
            getParameters().getBondName(),
            interfaceNames.toArray(new String[] {}),
            address,
            subnet,
            gateway,
            getParameters().getNetwork().getStp(),
            bondingOptions,
            getParameters().getBootProtocol());
    parameters.setVmNetwork(getParameters().getNetwork().isVmNetwork());
    parameters.setOldNetworkName(getParameters().getOldNetworkName());
    parameters.setConnectionTimeout(
        Config.<Integer>getValue(ConfigValues.NetworkConnectivityCheckTimeoutInSeconds));
    parameters.setCheckConnectivity(getParameters().getCheckConnectivity());

    IPAddress[] adresses = Dns.getHostAddresses(NetworkUtils.OS_REFERENCE_TO_MACHINE_NAME);
    if (adresses != null && adresses.length > 0) {
      parameters.setHostAddr(adresses[0].toString());
    }

    if (getParameters().getCheckConnectivity()) {
      ThreadPoolUtil.execute(new EditNetworkThread(parameters));
      pollVds(getVds());
    } else {
      editNetworkThreadCompat(parameters);
    }

    if (retVal != null && editNetworkDone) {
      // update vds network data
      retVal =
          runVdsCommand(
              VDSCommandType.CollectVdsNetworkData,
              new CollectHostNetworkDataVdsCommandParameters(getVds()));

      if (retVal.getSucceeded()) {
        Guid groupId = getVdsDao().get(getParameters().getVdsId()).getVdsGroupId();
        NetworkClusterHelper.setStatus(groupId, getParameters().getNetwork());
        setSucceeded(true);
      }
    }
  }