Search in sources :

Example 51 with NicProfile

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

the class ConsoleProxyManagerImpl method finalizeDeployment.

@Override
public boolean finalizeDeployment(Commands cmds, VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
    finalizeCommandsOnStart(cmds, profile);
    ConsoleProxyVO proxy = _consoleProxyDao.findById(profile.getId());
    DataCenter dc = dest.getDataCenter();
    List<NicProfile> nics = profile.getNics();
    for (NicProfile nic : nics) {
        if ((nic.getTrafficType() == TrafficType.Public && dc.getNetworkType() == NetworkType.Advanced) || (nic.getTrafficType() == TrafficType.Guest && (dc.getNetworkType() == NetworkType.Basic || dc.isSecurityGroupEnabled()))) {
            proxy.setPublicIpAddress(nic.getIPv4Address());
            proxy.setPublicNetmask(nic.getIPv4Netmask());
            proxy.setPublicMacAddress(nic.getMacAddress());
        } else if (nic.getTrafficType() == TrafficType.Management) {
            proxy.setPrivateIpAddress(nic.getIPv4Address());
            proxy.setPrivateMacAddress(nic.getMacAddress());
        }
    }
    _consoleProxyDao.update(proxy.getId(), proxy);
    return true;
}
Also used : DataCenter(com.cloud.dc.DataCenter) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) NicProfile(com.cloud.vm.NicProfile)

Example 52 with NicProfile

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

the class ConsoleProxyManagerImpl method finalizeVirtualMachineProfile.

@Override
public boolean finalizeVirtualMachineProfile(VirtualMachineProfile profile, DeployDestination dest, ReservationContext context) {
    ConsoleProxyVO vm = _consoleProxyDao.findById(profile.getId());
    Map<String, String> details = _vmDetailsDao.listDetailsKeyPairs(vm.getId());
    vm.setDetails(details);
    StringBuilder buf = profile.getBootArgsBuilder();
    buf.append(" template=domP type=consoleproxy");
    buf.append(" host=").append(ApiServiceConfiguration.ManagementHostIPAdr.value());
    buf.append(" port=").append(_mgmtPort);
    buf.append(" name=").append(profile.getVirtualMachine().getHostName());
    if (_sslEnabled) {
        buf.append(" premium=true");
    }
    buf.append(" zone=").append(dest.getDataCenter().getId());
    buf.append(" pod=").append(dest.getPod().getId());
    buf.append(" guid=Proxy.").append(profile.getId());
    buf.append(" proxy_vm=").append(profile.getId());
    if (_disableRpFilter) {
        buf.append(" disable_rp_filter=true");
    }
    boolean externalDhcp = false;
    String externalDhcpStr = _configDao.getValue("direct.attach.network.externalIpAllocator.enabled");
    if (externalDhcpStr != null && externalDhcpStr.equalsIgnoreCase("true")) {
        externalDhcp = true;
    }
    if (Boolean.valueOf(_configDao.getValue("system.vm.random.password"))) {
        buf.append(" vmpassword=").append(_configDao.getValue("system.vm.password"));
    }
    for (NicProfile nic : profile.getNics()) {
        int deviceId = nic.getDeviceId();
        if (nic.getIPv4Address() == null) {
            buf.append(" eth").append(deviceId).append("ip=").append("0.0.0.0");
            buf.append(" eth").append(deviceId).append("mask=").append("0.0.0.0");
        } else {
            buf.append(" eth").append(deviceId).append("ip=").append(nic.getIPv4Address());
            buf.append(" eth").append(deviceId).append("mask=").append(nic.getIPv4Netmask());
        }
        if (nic.isDefaultNic()) {
            buf.append(" gateway=").append(nic.getIPv4Gateway());
        }
        if (nic.getTrafficType() == TrafficType.Management) {
            String mgmt_cidr = _configDao.getValue(Config.ManagementNetwork.key());
            if (NetUtils.isValidCIDR(mgmt_cidr)) {
                buf.append(" mgmtcidr=").append(mgmt_cidr);
            }
            buf.append(" localgw=").append(dest.getPod().getGateway());
        }
    }
    /* External DHCP mode */
    if (externalDhcp) {
        buf.append(" bootproto=dhcp");
    }
    DataCenterVO dc = _dcDao.findById(profile.getVirtualMachine().getDataCenterId());
    buf.append(" internaldns1=").append(dc.getInternalDns1());
    if (dc.getInternalDns2() != null) {
        buf.append(" internaldns2=").append(dc.getInternalDns2());
    }
    buf.append(" dns1=").append(dc.getDns1());
    if (dc.getDns2() != null) {
        buf.append(" dns2=").append(dc.getDns2());
    }
    String bootArgs = buf.toString();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Boot Args for " + profile + ": " + bootArgs);
    }
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) ConsoleProxyVO(com.cloud.vm.ConsoleProxyVO) NicProfile(com.cloud.vm.NicProfile)

Example 53 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 54 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 55 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)

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