Search in sources :

Example 81 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method finalizeStart.

@Override
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
    final DomainRouterVO router = _routerDao.findById(profile.getId());
    // process all the answers
    for (final Answer answer : cmds.getAnswers()) {
        // handle any command failures
        if (!answer.getResult()) {
            final String cmdClassName = answer.getClass().getCanonicalName().replace("Answer", "Command");
            final String errorMessage = "Command: " + cmdClassName + " failed while starting virtual router";
            final String errorDetails = "Details: " + answer.getDetails() + " " + answer.toString();
            // add alerts for the failed commands
            _alertMgr.sendAlert(AlertService.AlertType.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterId(), router.getPodIdToDeployIn(), errorMessage, errorDetails);
            s_logger.error(answer.getDetails());
            s_logger.warn(errorMessage);
            // Stop the router if any of the commands failed
            return false;
        }
    }
    // at this point, all the router command are successful.
    boolean result = true;
    // Get guest networks info
    final List<Network> guestNetworks = new ArrayList<Network>();
    final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
    for (final Nic nic : routerNics) {
        final Network network = _networkModel.getNetwork(nic.getNetworkId());
        final DataCenterVO dcVO = _dcDao.findById(network.getDataCenterId());
        if (network.getTrafficType() == TrafficType.Guest) {
            guestNetworks.add(network);
            if (nic.getBroadcastUri().getScheme().equals("pvlan")) {
                final NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(), 0, false, "pvlan-nic");
                final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(dcVO);
                try {
                    result = networkTopology.setupDhcpForPvlan(true, router, router.getHostId(), nicProfile);
                } catch (final ResourceUnavailableException e) {
                    s_logger.debug("ERROR in finalizeStart: ", e);
                }
            }
        }
    }
    if (result) {
        final GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer) cmds.getAnswer("getDomRVersion");
        router.setTemplateVersion(versionAnswer.getTemplateVersion());
        router.setScriptsVersion(versionAnswer.getScriptsVersion());
        _routerDao.persist(router, guestNetworks);
    }
    return result;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) Network(com.cloud.network.Network) NetworkTopology(org.apache.cloudstack.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 82 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class VirtualNetworkApplianceManagerImpl method getControlNic.

protected NicProfile getControlNic(final VirtualMachineProfile profile) {
    final DomainRouterVO router = _routerDao.findById(profile.getId());
    final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
    NicProfile controlNic = null;
    if (profile.getHypervisorType() == HypervisorType.VMware && dcVo.getNetworkType() == NetworkType.Basic) {
        // for basic network mode, we will use the guest NIC for control NIC
        for (final NicProfile nic : profile.getNics()) {
            if (nic.getTrafficType() == TrafficType.Guest && nic.getIPv4Address() != null) {
                controlNic = nic;
            }
        }
    } else {
        for (final NicProfile nic : profile.getNics()) {
            if (nic.getTrafficType() == TrafficType.Control && nic.getIPv4Address() != null) {
                controlNic = nic;
            }
        }
    }
    return controlNic;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 83 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class PrivateGatewayRules method accept.

@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
    _router = router;
    boolean result = false;
    try {
        final NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
        _network = networkModel.getNetwork(_privateGateway.getNetworkId());
        final NicProfileHelper nicProfileHelper = visitor.getVirtualNetworkApplianceFactory().getNicProfileHelper();
        final NicProfile requested = nicProfileHelper.createPrivateNicProfileForGateway(_privateGateway, _router);
        final NetworkHelper networkHelper = visitor.getVirtualNetworkApplianceFactory().getNetworkHelper();
        if (!networkHelper.checkRouterVersion(_router)) {
            s_logger.warn("Router requires upgrade. Unable to send command to router: " + _router.getId());
            return false;
        }
        final VirtualMachineManager itMgr = visitor.getVirtualNetworkApplianceFactory().getItMgr();
        _nicProfile = itMgr.addVmToNetwork(_router, _network, requested);
        // setup source nat
        if (_nicProfile != null) {
            _isAddOperation = true;
            // result = setupVpcPrivateNetwork(router, true, guestNic);
            result = visitor.visit(this);
        }
    } catch (final Exception ex) {
        s_logger.warn("Failed to create private gateway " + _privateGateway + " on router " + _router + " due to ", ex);
    } finally {
        if (!result) {
            s_logger.debug("Failed to setup gateway " + _privateGateway + " on router " + _router + " with the source nat. Will now remove the gateway.");
            _isAddOperation = false;
            final boolean isRemoved = destroyPrivateGateway(visitor);
            if (isRemoved) {
                s_logger.debug("Removed the gateway " + _privateGateway + " from router " + _router + " as a part of cleanup");
            } else {
                s_logger.warn("Failed to remove the gateway " + _privateGateway + " from router " + _router + " as a part of cleanup");
            }
        }
    }
    return result;
}
Also used : NetworkModel(com.cloud.network.NetworkModel) VirtualMachineManager(com.cloud.vm.VirtualMachineManager) NicProfileHelper(com.cloud.network.router.NicProfileHelper) NicProfile(com.cloud.vm.NicProfile) NetworkHelper(com.cloud.network.router.NetworkHelper) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 84 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class VpcVirtualNetworkApplianceManagerImpl method addVpcRouterToGuestNetwork.

@Override
public boolean addVpcRouterToGuestNetwork(final VirtualRouter router, final Network network, final Map<VirtualMachineProfile.Param, Object> params) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    if (network.getTrafficType() != TrafficType.Guest) {
        s_logger.warn("Network " + network + " is not of type " + TrafficType.Guest);
        return false;
    }
    // Add router to the Guest network
    boolean result = true;
    try {
        // 1) add nic to the router
        _routerDao.addRouterToGuestNetwork(router, network);
        final NicProfile guestNic = _itMgr.addVmToNetwork(router, network, null);
        // 2) setup guest network
        if (guestNic != null) {
            result = setupVpcGuestNetwork(network, router, true, guestNic);
        } else {
            s_logger.warn("Failed to add router " + router + " to guest network " + network);
            result = false;
        }
        // 3) apply networking rules
        if (result && params.get(Param.ReProgramGuestNetworks) != null && (Boolean) params.get(Param.ReProgramGuestNetworks) == true) {
            sendNetworkRulesToRouter(router.getId(), network.getId());
        }
    } catch (final Exception ex) {
        s_logger.warn("Failed to add router " + router + " to network " + network + " due to ", ex);
        result = false;
    } finally {
        if (!result) {
            s_logger.debug("Removing the router " + router + " from network " + network + " as a part of cleanup");
            if (removeVpcRouterFromGuestNetwork(router, network)) {
                s_logger.debug("Removed the router " + router + " from network " + network + " as a part of cleanup");
            } else {
                s_logger.warn("Failed to remove the router " + router + " from network " + network + " as a part of cleanup");
            }
        } else {
            s_logger.debug("Succesfully added router " + router + " to guest network " + network);
        }
    }
    return result;
}
Also used : NicProfile(com.cloud.vm.NicProfile) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Aggregations

NicProfile (com.cloud.vm.NicProfile)84 Network (com.cloud.network.Network)31 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)28 NetworkVO (com.cloud.network.dao.NetworkVO)27 ArrayList (java.util.ArrayList)23 DataCenterVO (com.cloud.dc.DataCenterVO)19 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)18 DomainRouterVO (com.cloud.vm.DomainRouterVO)16 NicVO (com.cloud.vm.NicVO)14 List (java.util.List)14 DataCenter (com.cloud.dc.DataCenter)13 NetworkOffering (com.cloud.offering.NetworkOffering)12 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)11 NetworkGuru (com.cloud.network.guru.NetworkGuru)11 LinkedHashMap (java.util.LinkedHashMap)11 Provider (com.cloud.network.Network.Provider)10 Nic (com.cloud.vm.Nic)10 ReservationContext (com.cloud.vm.ReservationContext)10 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9