Search in sources :

Example 11 with Nic

use of com.cloud.legacymodel.network.Nic in project cosmic by MissionCriticalCloud.

the class ManagementIPSystemVMInvestigator method isVmAlive.

@Override
public boolean isVmAlive(final VirtualMachine vm, final Host host) throws UnknownVM {
    if (!vm.getType().isUsedBySystem()) {
        s_logger.debug("Not a System Vm, unable to determine state of " + vm + " returning null");
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Testing if " + vm + " is alive");
    }
    if (vm.getHostId() == null) {
        s_logger.debug("There's no host id for " + vm);
        throw new UnknownVM();
    }
    final HostVO vmHost = _hostDao.findById(vm.getHostId());
    if (vmHost == null) {
        s_logger.debug("Unable to retrieve the host by using id " + vm.getHostId());
        throw new UnknownVM();
    }
    final List<? extends Nic> nics = _networkMgr.getNicsForTraffic(vm.getId(), TrafficType.Management);
    if (nics.size() == 0) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Unable to find a management nic, cannot ping this system VM, unable to determine state of " + vm + " returning null");
        }
        throw new UnknownVM();
    }
    for (final Nic nic : nics) {
        if (nic.getIPv4Address() == null) {
            continue;
        }
        // get the data center IP address, find a host on the pod, use that host to ping the data center IP address
        final List<Long> otherHosts = findHostByPod(vmHost.getPodId(), vm.getHostId());
        for (final Long otherHost : otherHosts) {
            final HostStatus vmState = testIpAddress(otherHost, nic.getIPv4Address());
            assert vmState != null;
            // In case of HostStatus.Unknown, next host will be tried
            if (vmState == HostStatus.Up) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("successfully pinged vm's private IP (" + vm.getPrivateIpAddress() + "), returning that the VM is up");
                }
                return Boolean.TRUE;
            } else if (vmState == HostStatus.Down) {
                // We can't ping the VM directly...if we can ping the host, then report the VM down.
                // If we can't ping the host, then we don't have enough information.
                final HostStatus vmHostState = testIpAddress(otherHost, vmHost.getPrivateIpAddress());
                assert vmHostState != null;
                if (vmHostState == HostStatus.Up) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("successfully pinged vm's host IP (" + vmHost.getPrivateIpAddress() + "), but could not ping VM, returning that the VM is down");
                    }
                    return Boolean.FALSE;
                }
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("unable to determine state of " + vm + " returning null");
    }
    throw new UnknownVM();
}
Also used : Nic(com.cloud.legacymodel.network.Nic) HostStatus(com.cloud.legacymodel.dc.HostStatus) HostVO(com.cloud.host.HostVO)

Example 12 with Nic

use of com.cloud.legacymodel.network.Nic in project cosmic by MissionCriticalCloud.

the class CommandSetupHelper method createApplyLoadBalancingRulesCommands.

public void createApplyLoadBalancingRulesCommands(final List<LoadBalancingRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
    final LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
    int i = 0;
    // We don't support VR to be inline currently
    final boolean inline = false;
    for (final LoadBalancingRule rule : rules) {
        final boolean revoked = rule.getState().equals(FirewallRule.State.Revoke);
        final String protocol = rule.getProtocol();
        final String lb_protocol = rule.getLbProtocol();
        final String algorithm = rule.getAlgorithm();
        final String uuid = rule.getUuid();
        final String srcIp = rule.getSourceIp().addr();
        final int srcPort = rule.getSourcePortStart();
        final List<LbDestination> destinations = rule.getDestinations();
        final List<LbStickinessPolicy> stickinessPolicies = rule.getStickinessPolicies();
        // Load default values and fallback to hardcoded if not available
        final Integer defaultClientTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.DefaultLoadBalancerClientTimeout.key()), 60000);
        final Integer defaultServerTimeout = NumbersUtil.parseInt(_configDao.getValue(Config.DefaultLoadBalancerServerTimeout.key()), 60000);
        // set timeouts, use defaults if not available
        Integer clientTimeout = rule.getClientTimeout();
        if (clientTimeout != null) {
            clientTimeout = NumbersUtil.parseInt(clientTimeout.toString(), defaultClientTimeout);
        } else {
            clientTimeout = defaultClientTimeout;
        }
        Integer serverTimeout = rule.getServerTimeout();
        if (serverTimeout != null) {
            serverTimeout = NumbersUtil.parseInt(serverTimeout.toString(), defaultServerTimeout);
        } else {
            serverTimeout = defaultServerTimeout;
        }
        final LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, stickinessPolicies, clientTimeout, serverTimeout);
        lb.setLbProtocol(lb_protocol);
        lbs[i++] = lb;
    }
    String routerPublicIp = null;
    if (router instanceof DomainRouterVO) {
        final DomainRouterVO domr = _routerDao.findById(router.getId());
        routerPublicIp = domr.getPublicIpAddress();
        if (routerPublicIp == null) {
            routerPublicIp = router.getPublicIpAddress();
        }
    }
    final Network guestNetwork = _networkModel.getNetwork(guestNetworkId);
    final Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId());
    final NicProfile nicProfile = new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(guestNetwork.getId(), router.getId()), _networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork));
    final NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId());
    final String maxconn;
    if (offering.getConcurrentConnections() == null) {
        maxconn = _configDao.getValue(Config.NetworkLBHaproxyMaxConn.key());
    } else {
        maxconn = offering.getConcurrentConnections().toString();
    }
    final LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs, routerPublicIp, _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()), router.getPrivateIpAddress(), _itMgr.toNicTO(nicProfile, router.getHypervisorType()), router.getVpcId(), maxconn, offering.isKeepAliveEnabled());
    cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
    cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
    cmd.lbStatsAuth = _configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key());
    cmd.lbStatsPort = _configDao.getValue(Config.NetworkLBHaproxyStatsPort.key());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final Zone zone = zoneRepository.findById(router.getDataCenterId()).orElse(null);
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, zone.getNetworkType().toString());
    cmds.addCommand(cmd);
}
Also used : LoadBalancingRule(com.cloud.legacymodel.network.LoadBalancingRule) NetworkOffering(com.cloud.offering.NetworkOffering) Zone(com.cloud.db.model.Zone) Nic(com.cloud.legacymodel.network.Nic) LoadBalancerTO(com.cloud.legacymodel.to.LoadBalancerTO) LbStickinessPolicy(com.cloud.legacymodel.network.LoadBalancingRule.LbStickinessPolicy) NicProfile(com.cloud.vm.NicProfile) LbDestination(com.cloud.legacymodel.network.LoadBalancingRule.LbDestination) Network(com.cloud.legacymodel.network.Network) DomainRouterVO(com.cloud.vm.DomainRouterVO) LoadBalancerConfigCommand(com.cloud.legacymodel.communication.command.LoadBalancerConfigCommand)

Example 13 with Nic

use of com.cloud.legacymodel.network.Nic in project cosmic by MissionCriticalCloud.

the class NetworkHelperImpl method configureGuestNic.

@Override
public LinkedHashMap<Network, List<? extends NicProfile>> configureGuestNic(final RouterDeploymentDefinition routerDeploymentDefinition) throws ConcurrentOperationException, InsufficientAddressCapacityException {
    // Form networks
    final LinkedHashMap<Network, List<? extends NicProfile>> networks = new LinkedHashMap<>(3);
    // 1) Guest network
    final Network guestNetwork = routerDeploymentDefinition.getGuestNetwork();
    if (guestNetwork != null) {
        logger.debug("Adding nic for Virtual Router in Guest network " + guestNetwork);
        String defaultNetworkStartIp = null, defaultNetworkStartIpv6 = null;
        if (!routerDeploymentDefinition.isPublicNetwork()) {
            final Nic placeholder = _networkModel.getPlaceholderNicForRouter(guestNetwork, routerDeploymentDefinition.getPodId());
            if (guestNetwork.getCidr() != null) {
                if (placeholder != null && placeholder.getIPv4Address() != null) {
                    logger.debug("Requesting ipv4 address " + placeholder.getIPv4Address() + " stored in placeholder nic for the network " + guestNetwork);
                    defaultNetworkStartIp = placeholder.getIPv4Address();
                } else {
                    final String startIp = _networkModel.getStartIpAddress(guestNetwork.getId());
                    if (startIp != null && _ipAddressDao.findByIpAndSourceNetworkId(guestNetwork.getId(), startIp).getAllocatedTime() == null) {
                        defaultNetworkStartIp = startIp;
                    } else if (logger.isDebugEnabled()) {
                        logger.debug("First ipv4 " + startIp + " in network id=" + guestNetwork.getId() + " is already allocated, can't use it for domain router; will get random ip address from the range");
                    }
                }
            }
            if (guestNetwork.getIp6Cidr() != null) {
                if (placeholder != null && placeholder.getIPv6Address() != null) {
                    logger.debug("Requesting ipv6 address " + placeholder.getIPv6Address() + " stored in placeholder nic for the network " + guestNetwork);
                    defaultNetworkStartIpv6 = placeholder.getIPv6Address();
                } else {
                    final String startIpv6 = _networkModel.getStartIpv6Address(guestNetwork.getId());
                    if (startIpv6 != null && _ipv6Dao.findByNetworkIdAndIp(guestNetwork.getId(), startIpv6) == null) {
                        defaultNetworkStartIpv6 = startIpv6;
                    } else if (logger.isDebugEnabled()) {
                        logger.debug("First ipv6 " + startIpv6 + " in network id=" + guestNetwork.getId() + " is already allocated, can't use it for domain router; will get random ipv6 address from the range");
                    }
                }
            }
        }
        final NicProfile gatewayNic = new NicProfile(defaultNetworkStartIp, defaultNetworkStartIpv6);
        if (routerDeploymentDefinition.isPublicNetwork()) {
            if (routerDeploymentDefinition.isRedundant()) {
                gatewayNic.setIPv4Address(_ipAddrMgr.acquireGuestIpAddressForRouter(guestNetwork, null));
            } else {
                gatewayNic.setIPv4Address(guestNetwork.getGateway());
            }
            gatewayNic.setBroadcastUri(guestNetwork.getBroadcastUri());
            gatewayNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
            gatewayNic.setIsolationUri(guestNetwork.getBroadcastUri());
            gatewayNic.setMode(guestNetwork.getMode());
            final String gatewayCidr = guestNetwork.getCidr();
            gatewayNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr));
        } else {
            gatewayNic.setDefaultNic(true);
        }
        networks.put(guestNetwork, new ArrayList<>(Arrays.asList(gatewayNic)));
    }
    return networks;
}
Also used : Network(com.cloud.legacymodel.network.Network) Nic(com.cloud.legacymodel.network.Nic) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with Nic

use of com.cloud.legacymodel.network.Nic in project cosmic by MissionCriticalCloud.

the class NicProfileHelperImpl method createPrivateNicProfileForGateway.

@Override
@DB
public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGateway, final VirtualRouter router) {
    final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
    final Long vpcId = privateGateway.getVpcId();
    final Vpc activeVpc = _vpcMgr.getActiveVpc(vpcId);
    PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(privateNetwork.getDataCenterId(), privateNetwork.getId(), vpcId, privateGateway.getIp4Address());
    if (activeVpc.isRedundant() && ipVO == null) {
        ipVO = _privateIpDao.findByIpAndVpcId(vpcId, privateGateway.getIp4Address());
    }
    Nic privateNic = null;
    if (ipVO != null) {
        privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId());
    }
    NicProfile privateNicProfile = new NicProfile();
    if (privateNic != null) {
        privateNicProfile = new NicProfile(privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate(privateNetwork.getId(), router.getId()), _networkModel.getNetworkTag(router.getHypervisorType(), privateNetwork));
        if (router.getIsRedundantRouter()) {
            final String newMacAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress()));
            privateNicProfile.setMacAddress(newMacAddress);
        }
    } else {
        final String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr());
        final PrivateIpAddress ip = new PrivateIpAddress(ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask, NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress())));
        final URI netUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
        privateNicProfile.setIPv4Address(ip.getIpAddress());
        privateNicProfile.setIPv4Gateway(ip.getGateway());
        privateNicProfile.setIPv4Netmask(ip.getNetmask());
        privateNicProfile.setIsolationUri(netUri);
        privateNicProfile.setBroadcastUri(netUri);
        // can we solve this in setBroadcastUri()???
        // or more plugable construct is desirable
        privateNicProfile.setBroadcastType(BroadcastDomainType.getSchemeValue(netUri));
        privateNicProfile.setFormat(IpAddressFormat.Ip4);
        privateNicProfile.setReservationId(String.valueOf(ip.getBroadcastUri()));
        privateNicProfile.setMacAddress(ip.getMacAddress());
    }
    return privateNicProfile;
}
Also used : PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) Network(com.cloud.legacymodel.network.Network) Vpc(com.cloud.legacymodel.network.vpc.Vpc) Nic(com.cloud.legacymodel.network.Nic) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) DB(com.cloud.utils.db.DB)

Example 15 with Nic

use of com.cloud.legacymodel.network.Nic 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.findById(network.getDataCenterId()).orElse(null);
        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.legacymodel.network.Nic) NicProfile(com.cloud.vm.NicProfile) NetworkUsageAnswer(com.cloud.legacymodel.communication.answer.NetworkUsageAnswer) GetDomRVersionAnswer(com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer) AgentControlAnswer(com.cloud.legacymodel.communication.answer.AgentControlAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.legacymodel.communication.answer.CheckS2SVpnConnectionsAnswer) Answer(com.cloud.legacymodel.communication.answer.Answer) CheckRouterAnswer(com.cloud.legacymodel.communication.answer.CheckRouterAnswer) Network(com.cloud.legacymodel.network.Network) NetworkTopology(com.cloud.network.topology.NetworkTopology) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) GetDomRVersionAnswer(com.cloud.legacymodel.communication.answer.GetDomRVersionAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Nic (com.cloud.legacymodel.network.Nic)37 Network (com.cloud.legacymodel.network.Network)19 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)17 ArrayList (java.util.ArrayList)13 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)11 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)11 NicProfile (com.cloud.vm.NicProfile)8 IPAddressVO (com.cloud.network.dao.IPAddressVO)7 DB (com.cloud.utils.db.DB)7 Zone (com.cloud.db.model.Zone)5 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)5 InsufficientAddressCapacityException (com.cloud.legacymodel.exceptions.InsufficientAddressCapacityException)5 Ip (com.cloud.legacymodel.network.Ip)5 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)5 UserVm (com.cloud.uservm.UserVm)5 DomainRouterVO (com.cloud.vm.DomainRouterVO)5 CallContext (com.cloud.context.CallContext)4 IpAddress (com.cloud.network.IpAddress)4 PublicIp (com.cloud.network.addr.PublicIp)4 NetworkVO (com.cloud.network.dao.NetworkVO)4