Search in sources :

Example 26 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class NetworkHelperImpl method configurePublicNic.

protected LinkedHashMap<Network, List<? extends NicProfile>> configurePublicNic(final RouterDeploymentDefinition routerDeploymentDefinition, final boolean hasGuestNic) {
    final LinkedHashMap<Network, List<? extends NicProfile>> publicConfig = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
    if (routerDeploymentDefinition.isPublicNetwork()) {
        s_logger.debug("Adding nic for Virtual Router in Public network ");
        // if source nat service is supported by the network, get the source
        // nat ip address
        final NicProfile defaultNic = new NicProfile();
        defaultNic.setDefaultNic(true);
        final PublicIp sourceNatIp = routerDeploymentDefinition.getSourceNatIP();
        defaultNic.setIPv4Address(sourceNatIp.getAddress().addr());
        defaultNic.setIPv4Gateway(sourceNatIp.getGateway());
        defaultNic.setIPv4Netmask(sourceNatIp.getNetmask());
        defaultNic.setMacAddress(sourceNatIp.getMacAddress());
        // get broadcast from public network
        final Network pubNet = _networkDao.findById(sourceNatIp.getNetworkId());
        if (pubNet.getBroadcastDomainType() == BroadcastDomainType.Vxlan) {
            defaultNic.setBroadcastType(BroadcastDomainType.Vxlan);
            defaultNic.setBroadcastUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
            defaultNic.setIsolationUri(BroadcastDomainType.Vxlan.toUri(sourceNatIp.getVlanTag()));
        } else {
            defaultNic.setBroadcastType(BroadcastDomainType.Vlan);
            defaultNic.setBroadcastUri(BroadcastDomainType.Vlan.toUri(sourceNatIp.getVlanTag()));
            defaultNic.setIsolationUri(IsolationType.Vlan.toUri(sourceNatIp.getVlanTag()));
        }
        //If guest nic has already been added we will have 2 devices in the list.
        if (hasGuestNic) {
            defaultNic.setDeviceId(2);
        }
        final NetworkOffering publicOffering = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemPublicNetwork).get(0);
        final List<? extends Network> publicNetworks = _networkMgr.setupNetwork(s_systemAccount, publicOffering, routerDeploymentDefinition.getPlan(), null, null, false);
        final String publicIp = defaultNic.getIPv4Address();
        // We want to use the identical MAC address for RvR on public
        // interface if possible
        final NicVO peerNic = _nicDao.findByIp4AddressAndNetworkId(publicIp, publicNetworks.get(0).getId());
        if (peerNic != null) {
            s_logger.info("Use same MAC as previous RvR, the MAC is " + peerNic.getMacAddress());
            defaultNic.setMacAddress(peerNic.getMacAddress());
        }
        publicConfig.put(publicNetworks.get(0), new ArrayList<NicProfile>(Arrays.asList(defaultNic)));
    }
    return publicConfig;
}
Also used : PublicIp(com.cloud.network.addr.PublicIp) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) NicVO(com.cloud.vm.NicVO) LinkedHashMap(java.util.LinkedHashMap)

Example 27 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class VpcVirtualNetworkApplianceManagerImpl method destroyPrivateGateway.

@Override
public boolean destroyPrivateGateway(final PrivateGateway gateway, final VirtualRouter router) throws ConcurrentOperationException, ResourceUnavailableException {
    boolean result = true;
    if (!_networkModel.isVmPartOfNetwork(router.getId(), gateway.getNetworkId())) {
        s_logger.debug("Router doesn't have nic for gateway " + gateway + " so no need to removed it");
        return result;
    }
    final Network privateNetwork = _networkModel.getNetwork(gateway.getNetworkId());
    final NicProfile nicProfile = _networkModel.getNicProfile(router, privateNetwork.getId(), null);
    s_logger.debug("Releasing private ip for gateway " + gateway + " from " + router);
    result = setupVpcPrivateNetwork(router, false, nicProfile);
    if (!result) {
        s_logger.warn("Failed to release private ip for gateway " + gateway + " on router " + router);
        return false;
    }
    // revoke network acl on the private gateway.
    if (!_networkACLMgr.revokeACLItemsForPrivateGw(gateway)) {
        s_logger.debug("Failed to delete network acl items on " + gateway + " from router " + router);
        return false;
    }
    s_logger.debug("Removing router " + router + " from private network " + privateNetwork + " as a part of delete private gateway");
    result = result && _itMgr.removeVmFromNetwork(router, privateNetwork, null);
    s_logger.debug("Private gateawy " + gateway + " is removed from router " + router);
    return result;
}
Also used : Network(com.cloud.network.Network) NicProfile(com.cloud.vm.NicProfile)

Example 28 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class CreateServiceInstanceCmd method create.

@Override
public void create() throws ResourceAllocationException {
    // Parameter validation
    try {
        DataCenter zone = _entityMgr.findById(DataCenter.class, zoneId);
        if (zone == null) {
            throw new InvalidParameterValueException("Unable to find zone ID " + zoneId);
        }
        Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
        VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
        if (template == null) {
            throw new InvalidParameterValueException("Invalid template ID " + templateId);
        }
        ServiceOffering serviceOffering = _entityMgr.findById(ServiceOffering.class, serviceOfferingId);
        if (serviceOffering == null) {
            throw new InvalidParameterValueException("Invalid service offering ID " + serviceOfferingId);
        }
        Network left = _networkService.getNetwork(leftNetworkId);
        if (left == null) {
            throw new InvalidParameterValueException("Invalid ID for left network " + leftNetworkId);
        }
        Network right = _networkService.getNetwork(rightNetworkId);
        if (right == null) {
            throw new InvalidParameterValueException("Invalid ID for right network " + rightNetworkId);
        }
        if (name.isEmpty()) {
            throw new InvalidParameterValueException("service instance name is empty");
        }
        ServiceVirtualMachine svm = _vrouterService.createServiceInstance(zone, owner, template, serviceOffering, name, left, right);
        if (svm == null) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to create service instance");
        }
        setEntityId(svm.getId());
        setEntityUuid(svm.getUuid());
    } catch (Exception ex) {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage());
    }
}
Also used : Account(com.cloud.user.Account) DataCenter(com.cloud.dc.DataCenter) VirtualMachineTemplate(com.cloud.template.VirtualMachineTemplate) ServerApiException(org.apache.cloudstack.api.ServerApiException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ServiceOffering(com.cloud.offering.ServiceOffering) Network(com.cloud.network.Network) ServiceVirtualMachine(org.apache.cloudstack.network.contrail.management.ServiceVirtualMachine) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) NetworkRuleConflictException(com.cloud.exception.NetworkRuleConflictException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 29 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method finalizeStart.

@Override
public boolean finalizeStart(final VirtualMachineProfile profile, final long hostId, final Commands cmds, final ReservationContext context) {
    DomainRouterVO internalLbVm = _internalLbVmDao.findById(profile.getId());
    boolean result = true;
    Answer answer = cmds.getAnswer("checkSsh");
    if (answer != null && answer instanceof CheckSshAnswer) {
        final CheckSshAnswer sshAnswer = (CheckSshAnswer) answer;
        if (sshAnswer == null || !sshAnswer.getResult()) {
            s_logger.warn("Unable to ssh to the internal LB VM: " + sshAnswer.getDetails());
            result = false;
        }
    } else {
        result = false;
    }
    if (result == false) {
        return result;
    }
    //Get guest network info
    final List<Network> guestNetworks = new ArrayList<Network>();
    final List<? extends Nic> internalLbVmNics = _nicDao.listByVmId(profile.getId());
    for (final Nic internalLbVmNic : internalLbVmNics) {
        final Network network = _ntwkModel.getNetwork(internalLbVmNic.getNetworkId());
        if (network.getTrafficType() == TrafficType.Guest) {
            guestNetworks.add(network);
        }
    }
    answer = cmds.getAnswer("getDomRVersion");
    if (answer != null && answer instanceof GetDomRVersionAnswer) {
        final GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer) answer;
        if (answer == null || !answer.getResult()) {
            s_logger.warn("Unable to get the template/scripts version of internal LB VM " + internalLbVm.getInstanceName() + " due to: " + versionAnswer.getDetails());
            result = false;
        } else {
            internalLbVm.setTemplateVersion(versionAnswer.getTemplateVersion());
            internalLbVm.setScriptsVersion(versionAnswer.getScriptsVersion());
            internalLbVm = _internalLbVmDao.persist(internalLbVm, guestNetworks);
        }
    } else {
        result = false;
    }
    return result;
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) Answer(com.cloud.agent.api.Answer) Network(com.cloud.network.Network) ArrayList(java.util.ArrayList) Nic(com.cloud.vm.Nic) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 30 with Network

use of com.cloud.network.Network in project cloudstack by apache.

the class InternalLoadBalancerVMManagerImpl method getInternalLbControlIp.

protected String getInternalLbControlIp(final long internalLbVmId) {
    String controlIpAddress = null;
    final List<NicVO> nics = _nicDao.listByVmId(internalLbVmId);
    for (final NicVO nic : nics) {
        final Network ntwk = _ntwkModel.getNetwork(nic.getNetworkId());
        if (ntwk.getTrafficType() == TrafficType.Control) {
            controlIpAddress = nic.getIPv4Address();
        }
    }
    if (controlIpAddress == null) {
        s_logger.warn("Unable to find Internal LB control ip in its attached NICs!. Internal LB vm: " + internalLbVmId);
        final DomainRouterVO internalLbVm = _internalLbVmDao.findById(internalLbVmId);
        return internalLbVm.getPrivateIpAddress();
    }
    return controlIpAddress;
}
Also used : Network(com.cloud.network.Network) NicVO(com.cloud.vm.NicVO) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Aggregations

Network (com.cloud.network.Network)235 ArrayList (java.util.ArrayList)86 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)63 Account (com.cloud.user.Account)60 Test (org.junit.Test)55 NetworkOffering (com.cloud.offering.NetworkOffering)52 PhysicalNetwork (com.cloud.network.PhysicalNetwork)50 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)50 NetworkVO (com.cloud.network.dao.NetworkVO)38 DataCenter (com.cloud.dc.DataCenter)34 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)31 NicProfile (com.cloud.vm.NicProfile)31 HostVO (com.cloud.host.HostVO)27 DB (com.cloud.utils.db.DB)27 List (java.util.List)27 DataCenterVO (com.cloud.dc.DataCenterVO)26 IPAddressVO (com.cloud.network.dao.IPAddressVO)25 HashMap (java.util.HashMap)24 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)23 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)20