private NonOperationalReason enforceNetworkCompliance(
      VDS host, boolean skipManagementNetwork, List<Network> clusterNetworks) {
    if (host.getStatus() != VDSStatus.Maintenance) {
      if (skipManagementNetwork) {
        skipManagementNetworkCheck(host.getInterfaces(), clusterNetworks, host.getVdsGroupId());
      }

      Map<String, String> customLogValues;

      // here we check if the host networks match it's cluster networks
      String networks = getMissingOperationalClusterNetworks(host, clusterNetworks);
      if (networks.length() > 0) {
        customLogValues = new HashMap<>();
        customLogValues.put("Networks", networks);

        setNonOperational(host, NonOperationalReason.NETWORK_UNREACHABLE, customLogValues);
        return NonOperationalReason.NETWORK_UNREACHABLE;
      }

      // Check that VM networks are implemented above a bridge.
      networks = getVmNetworksImplementedAsBridgeless(host, clusterNetworks);
      if (networks.length() > 0) {
        customLogValues = new HashMap<>();
        customLogValues.put("Networks", networks);

        setNonOperational(host, NonOperationalReason.VM_NETWORK_IS_BRIDGELESS, customLogValues);
        return NonOperationalReason.VM_NETWORK_IS_BRIDGELESS;
      }
    }

    return NonOperationalReason.NONE;
  }
  private void logChangedDisplayNetwork(
      VDS host,
      Collection<Network> engineHostNetworks,
      Collection<VdsNetworkInterface> engineInterfaces) {

    if (isVmRunningOnHost(host.getId())) {
      final Network engineDisplayNetwork =
          findDisplayNetwork(host.getVdsGroupId(), engineHostNetworks);

      if (engineDisplayNetwork == null) {
        return;
      }

      final IsNetworkOnInterfacePredicate isNetworkOnInterfacePredicate =
          new IsNetworkOnInterfacePredicate(engineDisplayNetwork.getName());
      final VdsNetworkInterface vdsmDisplayInterface =
          LinqUtils.firstOrNull(host.getInterfaces(), isNetworkOnInterfacePredicate);
      final VdsNetworkInterface engineDisplayInterface =
          LinqUtils.firstOrNull(engineInterfaces, isNetworkOnInterfacePredicate);
      final DisplayInterfaceEqualityPredicate displayIneterfaceEqualityPredicate =
          new DisplayInterfaceEqualityPredicate(engineDisplayInterface);
      if (vdsmDisplayInterface == null // the display interface is't on host anymore
          || !displayIneterfaceEqualityPredicate.eval(vdsmDisplayInterface)) {
        final AuditLogableBase loggable = new AuditLogableBase(host.getId());
        auditLogDirector.log(loggable, AuditLogType.NETWORK_UPDATE_DISPLAY_FOR_HOST_WITH_ACTIVE_VM);
      }
    }
  }
  @Override
  public NonOperationalReason persistAndEnforceNetworkCompliance(
      VDS host, boolean skipManagementNetwork, UserConfiguredNetworkData userConfiguredData) {

    List<VdsNetworkInterface> dbIfaces = interfaceDao.getAllInterfacesForVds(host.getId());
    List<Network> clusterNetworks = networkDao.getAllForCluster(host.getVdsGroupId());

    persistTopology(host, dbIfaces, clusterNetworks, userConfiguredData);
    NonOperationalReason nonOperationalReason =
        enforceNetworkCompliance(host, skipManagementNetwork, clusterNetworks);
    auditNetworkCompliance(host, dbIfaces, clusterNetworks);
    return nonOperationalReason;
  }
  @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 boolean canDoAction() {
    String ifaceGateway = null;
    interfaces = getDbFacade().getInterfaceDao().getAllInterfacesForVds(getParameters().getVdsId());

    // check that interface exists
    for (final VdsNetworkInterface i : getParameters().getInterfaces()) {
      VdsNetworkInterface iface =
          interfaces.stream().filter(x -> x.getName().equals(i.getName())).findFirst().orElse(null);
      if (iface == null) {
        addCanDoActionMessage(EngineMessage.NETWORK_INTERFACE_NOT_EXISTS);
        return false;
      }
      ifaceGateway = iface.getGateway();
    }

    // check that the old network name is not null
    if (StringUtils.isEmpty(getParameters().getOldNetworkName())) {
      addCanDoActionMessage(EngineMessage.NETWORK_OLD_NETWORK_NOT_SPECIFIED);
      return false;
    }

    VDS vds = getVdsDao().get(getParameters().getVdsId());
    if (vds.getStatus() != VDSStatus.Maintenance) {
      // check that the old network exists in host
      boolean ifaceFound =
          interfaces
              .stream()
              .anyMatch(
                  i ->
                      i.getNetworkName() != null
                          && i.getNetworkName().equals(getParameters().getNetwork().getName()));
      if (ifaceFound) {
        addCanDoActionMessage(EngineMessage.NETWORK_HOST_IS_BUSY);
        return false;
      }
    }

    // check that the old network exists in host
    boolean ifacenetNotFound =
        interfaces
            .stream()
            .noneMatch(
                i ->
                    i.getNetworkName() != null
                        && i.getNetworkName().equals(getParameters().getOldNetworkName()));
    if (ifacenetNotFound) {
      addCanDoActionMessage(EngineMessage.NETWORK_NOT_EXISTS);
      return false;
    }

    final Guid clusterId = getVdsGroupId();
    if (!managementNetworkUtil.isManagementNetwork(
        getParameters().getNetwork().getName(), clusterId)) {
      if (managementNetworkUtil.isManagementNetwork(
          getParameters().getOldNetworkName(), clusterId)) {
        getReturnValue()
            .getCanDoActionMessages()
            .add(EngineMessage.NETWORK_DEFAULT_UPDATE_NAME_INVALID.toString());
        getReturnValue()
            .getCanDoActionMessages()
            .add(String.format("$NetworkName %1$s", getParameters().getOldNetworkName()));
        return false;
      }

      if (StringUtils.isNotEmpty(getParameters().getGateway())) {
        if (!getParameters().getGateway().equals(ifaceGateway)) {
          addCanDoActionMessage(EngineMessage.NETWORK_ATTACH_ILLEGAL_GATEWAY);
          return false;
        }
        // if the gateway didn't change we don't want the vdsm to set it.
        else {
          getParameters().setGateway(null);
        }
      }

      // check connectivity
      if (getParameters().getCheckConnectivity()) {
        addCanDoActionMessage(EngineMessage.NETWORK_CHECK_CONNECTIVITY);
        return false;
      }
    }

    // check address exists in static ip
    if (getParameters().getBootProtocol() == NetworkBootProtocol.STATIC_IP) {
      if (StringUtils.isEmpty(getParameters().getAddress())) {
        addCanDoActionMessage(EngineMessage.NETWORK_ADDR_MANDATORY_IN_STATIC_IP);
        return false;
      }
    }

    Network network = getNetworkDao().getByNameAndCluster(getNetworkName(), vds.getVdsGroupId());
    if (network != null && network.isExternal()) {
      return failCanDoAction(EngineMessage.EXTERNAL_NETWORK_CANNOT_BE_PROVISIONED);
    }

    return true;
  }