Search in sources :

Example 16 with NetworkTopology

use of org.apache.cloudstack.network.topology.NetworkTopology in project cloudstack by apache.

the class VirtualRouterElement method rollbackMigration.

@Override
public void rollbackMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final ReservationContext src, final ReservationContext dst) {
    if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
        return;
    }
    if (vm.getType() == VirtualMachine.Type.DomainRouter) {
        assert vm instanceof DomainRouterVO;
        final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
        try {
            networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nic);
        } catch (final ResourceUnavailableException e) {
            s_logger.warn("Timed Out", e);
        }
    } else if (vm.getType() == VirtualMachine.Type.User) {
        assert vm instanceof UserVmVO;
        final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
        _userVmMgr.setupVmForPvlan(true, userVm.getHostId(), nic);
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) UserVmVO(com.cloud.vm.UserVmVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 17 with NetworkTopology

use of org.apache.cloudstack.network.topology.NetworkTopology in project cloudstack by apache.

the class VirtualRouterElement method saveUserData.

@Override
public boolean saveUserData(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException {
    if (!canHandle(network, null)) {
        return false;
    }
    final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
    if (routers == null || routers.isEmpty()) {
        s_logger.debug("Can't find virtual router element in network " + network.getId());
        return true;
    }
    final VirtualMachineProfile uservm = vm;
    final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
    boolean result = true;
    for (final DomainRouterVO domainRouterVO : routers) {
        result = result && networkTopology.saveUserDataToRouter(network, nic, uservm, domainRouterVO);
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 18 with NetworkTopology

use of org.apache.cloudstack.network.topology.NetworkTopology in project cloudstack by apache.

the class VirtualRouterElement method prepareMigration.

@Override
public boolean prepareMigration(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) {
    if (nic.getBroadcastType() != Networks.BroadcastDomainType.Pvlan) {
        return true;
    }
    if (vm.getType() == VirtualMachine.Type.DomainRouter) {
        assert vm instanceof DomainRouterVO;
        final DomainRouterVO router = (DomainRouterVO) vm.getVirtualMachine();
        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
        try {
            networkTopology.setupDhcpForPvlan(false, router, router.getHostId(), nic);
        } catch (final ResourceUnavailableException e) {
            s_logger.warn("Timed Out", e);
        }
    } else if (vm.getType() == VirtualMachine.Type.User) {
        assert vm instanceof UserVmVO;
        final UserVmVO userVm = (UserVmVO) vm.getVirtualMachine();
        _userVmMgr.setupVmForPvlan(false, userVm.getHostId(), nic);
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) UserVmVO(com.cloud.vm.UserVmVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 19 with NetworkTopology

use of org.apache.cloudstack.network.topology.NetworkTopology in project cloudstack by apache.

the class VirtualRouterElement method savePassword.

@Override
public boolean savePassword(final Network network, final NicProfile nic, final VirtualMachineProfile vm) throws ResourceUnavailableException {
    if (!canHandle(network, null)) {
        return false;
    }
    final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
    if (routers == null || routers.isEmpty()) {
        s_logger.debug("Can't find virtual router element in network " + network.getId());
        return true;
    }
    final VirtualMachineProfile uservm = vm;
    final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
    final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
    // save the password in DB
    for (final VirtualRouter router : routers) {
        if (router.getState() == State.Running) {
            return networkTopology.savePasswordToRouter(network, nic, uservm, router);
        }
    }
    final String password = (String) uservm.getParameter(VirtualMachineProfile.Param.VmPassword);
    final String password_encrypted = DBEncryptionUtil.encrypt(password);
    final UserVmVO userVmVO = _userVmDao.findById(vm.getId());
    _userVmDao.loadDetails(userVmVO);
    userVmVO.setDetail("password", password_encrypted);
    _userVmDao.saveDetails(userVmVO);
    userVmVO.setUpdateParameters(true);
    _userVmDao.update(userVmVO.getId(), userVmVO);
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) UserVmVO(com.cloud.vm.UserVmVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO) VirtualRouter(com.cloud.network.router.VirtualRouter)

Example 20 with NetworkTopology

use of org.apache.cloudstack.network.topology.NetworkTopology in project cloudstack by apache.

the class VpcVirtualRouterElement method applyNetworkACLs.

@Override
public boolean applyNetworkACLs(final Network network, final List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
    boolean result = true;
    if (canHandle(network, Service.NetworkACL)) {
        final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
        if (routers == null || routers.isEmpty()) {
            s_logger.debug("Virtual router elemnt doesn't need to apply firewall rules on the backend; virtual " + "router doesn't exist in the network " + network.getId());
            return true;
        }
        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(dcVO);
        for (final DomainRouterVO domainRouterVO : routers) {
            try {
                result = result && networkTopology.applyNetworkACLs(network, rules, domainRouterVO, false);
            } catch (final Exception ex) {
                s_logger.debug("Failed to apply network acl in network " + network.getId());
            }
        }
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) DomainRouterVO(com.cloud.vm.DomainRouterVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

DataCenterVO (com.cloud.dc.DataCenterVO)27 DomainRouterVO (com.cloud.vm.DomainRouterVO)27 NetworkTopology (org.apache.cloudstack.network.topology.NetworkTopology)27 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)10 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)6 Network (com.cloud.network.Network)5 UserVmVO (com.cloud.vm.UserVmVO)4 Service (com.cloud.network.Network.Service)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3 NicProfile (com.cloud.vm.NicProfile)3 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 Nic (com.cloud.vm.Nic)2 ArrayList (java.util.ArrayList)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1 Answer (com.cloud.agent.api.Answer)1 CheckRouterAnswer (com.cloud.agent.api.CheckRouterAnswer)1 CheckS2SVpnConnectionsAnswer (com.cloud.agent.api.CheckS2SVpnConnectionsAnswer)1 GetDomRVersionAnswer (com.cloud.agent.api.GetDomRVersionAnswer)1 GetRouterAlertsAnswer (com.cloud.agent.api.GetRouterAlertsAnswer)1