Search in sources :

Example 41 with Zone

use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method addPasswordAndUserdata.

@Override
public boolean addPasswordAndUserdata(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    boolean result = true;
    if (canHandle(network, Service.UserData)) {
        if (vm.getType() != VirtualMachine.Type.User) {
            return false;
        }
        if (network.getIp6Gateway() != null) {
            s_logger.info("Skip password and userdata service setup for IPv6 VM");
            return true;
        }
        final VirtualMachineProfile uservm = vm;
        final List<DomainRouterVO> routers = getRouters(network, dest);
        if (routers == null || routers.size() == 0) {
            throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
        }
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
        for (final DomainRouterVO domainRouterVO : routers) {
            result = result && networkTopology.applyUserData(network, nic, uservm, dest, domainRouterVO);
        }
    }
    return result;
}
Also used : Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 42 with Zone

use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.

the class VirtualRouterElement method configDhcpSupportForSubnet.

@Override
public boolean configDhcpSupportForSubnet(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
    if (canHandle(network, Service.Dhcp)) {
        if (vm.getType() != VirtualMachine.Type.User) {
            return false;
        }
        final VirtualMachineProfile uservm = vm;
        final List<DomainRouterVO> routers = getRouters(network, dest);
        if (routers == null || routers.size() == 0) {
            throw new ResourceUnavailableException("Can't find at least one router!", DataCenter.class, network.getDataCenterId());
        }
        final Zone zone = zoneRepository.findOne(network.getDataCenterId());
        final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
        return networkTopology.configDhcpForSubnet(network, nic, uservm, dest, routers);
    }
    return false;
}
Also used : Zone(com.cloud.db.model.Zone) NetworkTopology(com.cloud.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 43 with Zone

use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.

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<>();
    final List<? extends Nic> routerNics = _nicDao.listByVmId(profile.getId());
    for (final Nic nic : routerNics) {
        final Network network = _networkModel.getNetwork(nic.getNetworkId());
        final Zone zone = zoneRepository.findOne(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, "pvlan-nic");
                final NetworkTopology networkTopology = _networkTopologyContext.retrieveNetworkTopology(zone);
                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);
    }
    final List<DomainRouterVO> routers = _routerDao.listByVpcId(router.getVpcId());
    for (final DomainRouterVO domainRouterVO : routers) {
        s_logger.info("Updating the redundant state of router " + domainRouterVO);
        updateRoutersRedundantState(domainRouterVO);
    }
    return result;
}
Also used : Zone(com.cloud.db.model.Zone) TimeZone(java.util.TimeZone) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) NicProfile(com.cloud.vm.NicProfile) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) Network(com.cloud.network.Network) NetworkTopology(com.cloud.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 44 with Zone

use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method getControlNic.

protected NicProfile getControlNic(final VirtualMachineProfile profile) {
    final DomainRouterVO router = _routerDao.findById(profile.getId());
    final Zone zone = zoneRepository.findOne(router.getDataCenterId());
    NicProfile controlNic = null;
    if (zone.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 : Zone(com.cloud.db.model.Zone) TimeZone(java.util.TimeZone) NicProfile(com.cloud.vm.NicProfile) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 45 with Zone

use of com.cloud.db.model.Zone in project cosmic by MissionCriticalCloud.

the class VirtualNetworkApplianceManagerImpl method startRouter.

@Override
public VirtualRouter startRouter(final long routerId, final boolean reprogramNetwork) throws ResourceUnavailableException, InsufficientCapacityException, ConcurrentOperationException {
    final Account caller = CallContext.current().getCallingAccount();
    final User callerUser = _accountMgr.getActiveUser(CallContext.current().getCallingUserId());
    // verify parameters
    DomainRouterVO router = _routerDao.findById(routerId);
    if (router == null) {
        throw new InvalidParameterValueException("Unable to find router by id " + routerId + ".");
    }
    _accountMgr.checkAccess(caller, null, true, router);
    final Account owner = _accountMgr.getAccount(router.getAccountId());
    // Check if all networks are implemented for the domR; if not -
    // implement them
    final Zone zone = zoneRepository.findOne(router.getDataCenterId());
    HostPodVO pod = null;
    if (router.getPodIdToDeployIn() != null) {
        pod = _podDao.findById(router.getPodIdToDeployIn());
    }
    final DeployDestination dest = new DeployDestination(zone, pod, null, null);
    final ReservationContext context = new ReservationContextImpl(null, null, callerUser, owner);
    final List<NicVO> nics = _nicDao.listByVmId(routerId);
    for (final NicVO nic : nics) {
        if (!_networkMgr.startNetwork(nic.getNetworkId(), dest, context)) {
            s_logger.warn("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
            throw new CloudRuntimeException("Failed to start network id=" + nic.getNetworkId() + " as a part of domR start");
        }
    }
    // After start network, check if it's already running
    router = _routerDao.findById(routerId);
    if (router.getState() == VirtualMachine.State.Running) {
        return router;
    }
    final UserVO user = _userDao.findById(CallContext.current().getCallingUserId());
    final Map<Param, Object> params = new HashMap<>();
    if (reprogramNetwork) {
        params.put(Param.ReProgramGuestNetworks, true);
    } else {
        params.put(Param.ReProgramGuestNetworks, false);
    }
    final VirtualRouter virtualRouter = _nwHelper.startVirtualRouter(router, user, caller, params);
    if (virtualRouter == null) {
        throw new CloudRuntimeException("Failed to start router with id " + routerId);
    }
    return virtualRouter;
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) HashMap(java.util.HashMap) Zone(com.cloud.db.model.Zone) TimeZone(java.util.TimeZone) HostPodVO(com.cloud.dc.HostPodVO) ReservationContextImpl(com.cloud.vm.ReservationContextImpl) ReservationContext(com.cloud.vm.ReservationContext) UserVO(com.cloud.user.UserVO) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) DeployDestination(com.cloud.deploy.DeployDestination) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Param(com.cloud.vm.VirtualMachineProfile.Param) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Zone (com.cloud.db.model.Zone)106 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)34 ArrayList (java.util.ArrayList)32 DomainRouterVO (com.cloud.vm.DomainRouterVO)28 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)26 Network (com.cloud.network.Network)23 NetworkTopology (com.cloud.network.topology.NetworkTopology)23 Account (com.cloud.user.Account)23 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)23 NetworkVO (com.cloud.network.dao.NetworkVO)22 DeployDestination (com.cloud.deploy.DeployDestination)18 NicProfile (com.cloud.vm.NicProfile)16 List (java.util.List)16 HostPodVO (com.cloud.dc.HostPodVO)15 HostVO (com.cloud.host.HostVO)15 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)14 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)14 DB (com.cloud.utils.db.DB)14 TransactionStatus (com.cloud.utils.db.TransactionStatus)12 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)11