Search in sources :

Example 1 with HostNetworkAttachmentsPersister

use of org.ovirt.engine.core.vdsbroker.vdsbroker.HostNetworkAttachmentsPersister in project ovirt-engine by oVirt.

the class AttachNetworkToClusterInternalCommand method attachNetwork.

private void attachNetwork(Guid clusterId, NetworkCluster networkClusterFromUserRequest, Network network) {
    networkClusterDao.save(new NetworkCluster(clusterId, network.getId(), NetworkStatus.OPERATIONAL, false, networkClusterFromUserRequest.isRequired(), false, false, false, false));
    List<VDS> hosts = vdsDao.getAllForCluster(clusterId);
    List<Network> networksOfCluster = networkDao.getAllForCluster(clusterId);
    for (VDS host : hosts) {
        HostNetworkAttachmentsPersister persister = new HostNetworkAttachmentsPersister(this.networkAttachmentDao, host.getId(), interfaceDao.getAllInterfacesForVds(host.getId()), Collections.emptyList(), networksOfCluster);
        persister.persistNetworkAttachments();
    }
    if (network.getCluster().isDisplay()) {
        final DisplayNetworkClusterHelper displayNetworkClusterHelper = new DisplayNetworkClusterHelper(networkClusterDao, vmDao, clusterDao, networkClusterFromUserRequest, network.getName(), auditLogDirector);
        if (displayNetworkClusterHelper.isDisplayToBeUpdated()) {
            displayNetworkClusterHelper.warnOnActiveVm();
        }
        networkClusterDao.setNetworkExclusivelyAsDisplay(clusterId, network.getId());
    }
    if (network.getCluster().isMigration()) {
        networkClusterDao.setNetworkExclusivelyAsMigration(clusterId, network.getId());
    }
    if (network.getCluster().isGluster()) {
        networkClusterDao.setNetworkExclusivelyAsGluster(clusterId, network.getId());
    }
    if (network.getCluster().isDefaultRoute()) {
        networkClusterDao.setNetworkExclusivelyAsDefaultRoute(clusterId, network.getId());
    }
    networkClusterHelper.setStatus(clusterId, network);
}
Also used : DisplayNetworkClusterHelper(org.ovirt.engine.core.bll.network.cluster.helper.DisplayNetworkClusterHelper) VDS(org.ovirt.engine.core.common.businessentities.VDS) Network(org.ovirt.engine.core.common.businessentities.network.Network) NetworkCluster(org.ovirt.engine.core.common.businessentities.network.NetworkCluster) HostNetworkAttachmentsPersister(org.ovirt.engine.core.vdsbroker.vdsbroker.HostNetworkAttachmentsPersister)

Example 2 with HostNetworkAttachmentsPersister

use of org.ovirt.engine.core.vdsbroker.vdsbroker.HostNetworkAttachmentsPersister in project ovirt-engine by oVirt.

the class ChangeVDSClusterCommand method executeCommand.

@Override
protected void executeCommand() {
    final Guid targetClusterId = getParameters().getClusterId();
    if (getSourceCluster().getId().equals(targetClusterId)) {
        setSucceeded(true);
        return;
    }
    // save the new cluster id
    TransactionSupport.executeInNewTransaction(() -> {
        VdsStatic staticData = getVds().getStaticData();
        getCompensationContext().snapshotEntity(staticData);
        // of the host is needed to reconfigure the firewall.
        if (targetCluster.getFirewallType() != getSourceCluster().getFirewallType()) {
            staticData.setReinstallRequired(true);
        }
        staticData.setClusterId(targetClusterId);
        vdsStaticDao.update(staticData);
        getCompensationContext().stateChanged();
        // remove the server from resource manager and add it back
        initializeVds();
        return null;
    });
    if (targetStoragePool != null && (getSourceCluster().getStoragePoolId() == null || !targetStoragePool.getId().equals(getSourceCluster().getStoragePoolId()))) {
        VdsActionParameters addVdsSpmIdParams = new VdsActionParameters(getVdsIdRef());
        addVdsSpmIdParams.setSessionId(getParameters().getSessionId());
        addVdsSpmIdParams.setCompensationEnabled(true);
        ActionReturnValue addVdsSpmIdReturn = runInternalAction(ActionType.AddVdsSpmId, addVdsSpmIdParams, cloneContext().withoutLock().withoutExecutionContext());
        if (!addVdsSpmIdReturn.getSucceeded()) {
            setSucceeded(false);
            getReturnValue().setFault(addVdsSpmIdReturn.getFault());
            return;
        }
    }
    if (getSourceCluster().supportsGlusterService() && clusterUtils.hasServers(getSourceCluster().getId())) {
        if (!glusterHostRemove(getSourceCluster().getId())) {
            setSucceeded(false);
            return;
        }
    }
    if (getTargetCluster().supportsGlusterService() && clusterUtils.hasMultipleServers(getTargetCluster().getId())) {
        if (!glusterHostAdd(getTargetCluster().getId())) {
            setSucceeded(false);
            return;
        }
    }
    if (getSourceCluster().getStoragePoolId() != null && (targetStoragePool == null || !getSourceCluster().getStoragePoolId().equals(targetStoragePool.getId()))) {
        vdsSpmIdMapDao.removeByVdsAndStoragePool(getVds().getId(), getSourceCluster().getStoragePoolId());
    }
    HostNetworkAttachmentsPersister persister = new HostNetworkAttachmentsPersister(this.networkAttachmentDao, getVdsId(), interfaceDao.getAllInterfacesForVds(getVdsId()), Collections.emptyList(), getTargetClusterNetworks());
    persister.persistNetworkAttachments();
    if (VDSStatus.PendingApproval != getVds().getStatus()) {
        configureNetworks();
    }
    setSucceeded(true);
}
Also used : VdsStatic(org.ovirt.engine.core.common.businessentities.VdsStatic) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VdsActionParameters(org.ovirt.engine.core.common.action.VdsActionParameters) Guid(org.ovirt.engine.core.compat.Guid) HostNetworkAttachmentsPersister(org.ovirt.engine.core.vdsbroker.vdsbroker.HostNetworkAttachmentsPersister)

Aggregations

HostNetworkAttachmentsPersister (org.ovirt.engine.core.vdsbroker.vdsbroker.HostNetworkAttachmentsPersister)2 DisplayNetworkClusterHelper (org.ovirt.engine.core.bll.network.cluster.helper.DisplayNetworkClusterHelper)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 VdsActionParameters (org.ovirt.engine.core.common.action.VdsActionParameters)1 VDS (org.ovirt.engine.core.common.businessentities.VDS)1 VdsStatic (org.ovirt.engine.core.common.businessentities.VdsStatic)1 Network (org.ovirt.engine.core.common.businessentities.network.Network)1 NetworkCluster (org.ovirt.engine.core.common.businessentities.network.NetworkCluster)1 Guid (org.ovirt.engine.core.compat.Guid)1