Search in sources :

Example 91 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cloudstack by apache.

the class NetworkOrchestrator method configure.

@Override
@DB
public boolean configure(final String name, final Map<String, Object> params) throws ConfigurationException {
    // populate providers
    final Map<Network.Service, Set<Network.Provider>> defaultSharedNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
    final Set<Network.Provider> defaultProviders = new HashSet<Network.Provider>();
    defaultProviders.add(Network.Provider.VirtualRouter);
    defaultSharedNetworkOfferingProviders.put(Service.Dhcp, defaultProviders);
    defaultSharedNetworkOfferingProviders.put(Service.Dns, defaultProviders);
    defaultSharedNetworkOfferingProviders.put(Service.UserData, defaultProviders);
    final Map<Network.Service, Set<Network.Provider>> defaultIsolatedNetworkOfferingProviders = defaultSharedNetworkOfferingProviders;
    defaultIsolatedNetworkOfferingProviders.put(Service.Dhcp, defaultProviders);
    defaultIsolatedNetworkOfferingProviders.put(Service.Dns, defaultProviders);
    defaultIsolatedNetworkOfferingProviders.put(Service.UserData, defaultProviders);
    defaultIsolatedNetworkOfferingProviders.put(Service.Firewall, defaultProviders);
    defaultIsolatedNetworkOfferingProviders.put(Service.Gateway, defaultProviders);
    defaultIsolatedNetworkOfferingProviders.put(Service.Lb, defaultProviders);
    defaultIsolatedNetworkOfferingProviders.put(Service.StaticNat, defaultProviders);
    defaultIsolatedNetworkOfferingProviders.put(Service.PortForwarding, defaultProviders);
    defaultIsolatedNetworkOfferingProviders.put(Service.Vpn, defaultProviders);
    final Map<Network.Service, Set<Network.Provider>> defaultSharedSGEnabledNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
    defaultSharedSGEnabledNetworkOfferingProviders.put(Service.Dhcp, defaultProviders);
    defaultSharedSGEnabledNetworkOfferingProviders.put(Service.Dns, defaultProviders);
    defaultSharedSGEnabledNetworkOfferingProviders.put(Service.UserData, defaultProviders);
    final Set<Provider> sgProviders = new HashSet<Provider>();
    sgProviders.add(Provider.SecurityGroupProvider);
    defaultSharedSGEnabledNetworkOfferingProviders.put(Service.SecurityGroup, sgProviders);
    final Map<Network.Service, Set<Network.Provider>> defaultIsolatedSourceNatEnabledNetworkOfferingProviders = new HashMap<Network.Service, Set<Network.Provider>>();
    defaultProviders.clear();
    defaultProviders.add(Network.Provider.VirtualRouter);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Dhcp, defaultProviders);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Dns, defaultProviders);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.UserData, defaultProviders);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Firewall, defaultProviders);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Gateway, defaultProviders);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Lb, defaultProviders);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.SourceNat, defaultProviders);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.StaticNat, defaultProviders);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.PortForwarding, defaultProviders);
    defaultIsolatedSourceNatEnabledNetworkOfferingProviders.put(Service.Vpn, defaultProviders);
    final Map<Network.Service, Set<Network.Provider>> defaultVPCOffProviders = new HashMap<Network.Service, Set<Network.Provider>>();
    defaultProviders.clear();
    defaultProviders.add(Network.Provider.VPCVirtualRouter);
    defaultVPCOffProviders.put(Service.Dhcp, defaultProviders);
    defaultVPCOffProviders.put(Service.Dns, defaultProviders);
    defaultVPCOffProviders.put(Service.UserData, defaultProviders);
    defaultVPCOffProviders.put(Service.NetworkACL, defaultProviders);
    defaultVPCOffProviders.put(Service.Gateway, defaultProviders);
    defaultVPCOffProviders.put(Service.Lb, defaultProviders);
    defaultVPCOffProviders.put(Service.SourceNat, defaultProviders);
    defaultVPCOffProviders.put(Service.StaticNat, defaultProviders);
    defaultVPCOffProviders.put(Service.PortForwarding, defaultProviders);
    defaultVPCOffProviders.put(Service.Vpn, defaultProviders);
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            NetworkOfferingVO offering = null;
            // #1 - quick cloud network offering
            if (_networkOfferingDao.findByUniqueName(NetworkOffering.QuickCloudNoServices) == null) {
                offering = _configMgr.createNetworkOffering(NetworkOffering.QuickCloudNoServices, "Offering for QuickCloud with no services", TrafficType.Guest, null, true, Availability.Optional, null, new HashMap<Network.Service, Set<Network.Provider>>(), true, Network.GuestType.Shared, false, null, true, null, true, false, null, false, null, true, false, null, null, true);
            }
            // #2 - SG enabled network offering
            if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOfferingWithSGService) == null) {
                offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOfferingWithSGService, "Offering for Shared Security group enabled networks", TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false, null, false, null, true, false, null, null, true);
            }
            // #3 - shared network offering with no SG service
            if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedNetworkOffering) == null) {
                offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedNetworkOffering, "Offering for Shared networks", TrafficType.Guest, null, true, Availability.Optional, null, defaultSharedNetworkOfferingProviders, true, Network.GuestType.Shared, false, null, true, null, true, false, null, false, null, true, false, null, null, true);
            }
            // #4 - default isolated offering with Source nat service
            if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService) == null) {
                offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingWithSourceNatService, "Offering for Isolated networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Required, null, defaultIsolatedSourceNatEnabledNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, false, false, null, false, null, true, false, null, null, true);
            }
            // #5 - default vpc offering with LB service
            if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks) == null) {
                offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworks, "Offering for Isolated VPC networks with Source Nat service enabled", TrafficType.Guest, null, false, Availability.Optional, null, defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, null, null, true);
            }
            // #6 - default vpc offering with no LB service
            if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB) == null) {
                // remove LB service
                defaultVPCOffProviders.remove(Service.Lb);
                offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksNoLB, "Offering for Isolated VPC networks with Source Nat service enabled and LB service disabled", TrafficType.Guest, null, false, Availability.Optional, null, defaultVPCOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, null, null, true);
            }
            // #7 - isolated offering with source nat disabled
            if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOffering) == null) {
                offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOffering, "Offering for Isolated networks with no Source Nat service", TrafficType.Guest, null, true, Availability.Optional, null, defaultIsolatedNetworkOfferingProviders, true, Network.GuestType.Isolated, false, null, true, null, true, false, null, false, null, true, false, null, null, true);
            }
            // #8 - network offering with internal lb service
            final Map<Network.Service, Set<Network.Provider>> internalLbOffProviders = new HashMap<Network.Service, Set<Network.Provider>>();
            final Set<Network.Provider> defaultVpcProvider = new HashSet<Network.Provider>();
            defaultVpcProvider.add(Network.Provider.VPCVirtualRouter);
            final Set<Network.Provider> defaultInternalLbProvider = new HashSet<Network.Provider>();
            defaultInternalLbProvider.add(Network.Provider.InternalLbVm);
            internalLbOffProviders.put(Service.Dhcp, defaultVpcProvider);
            internalLbOffProviders.put(Service.Dns, defaultVpcProvider);
            internalLbOffProviders.put(Service.UserData, defaultVpcProvider);
            internalLbOffProviders.put(Service.NetworkACL, defaultVpcProvider);
            internalLbOffProviders.put(Service.Gateway, defaultVpcProvider);
            internalLbOffProviders.put(Service.Lb, defaultInternalLbProvider);
            internalLbOffProviders.put(Service.SourceNat, defaultVpcProvider);
            if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB) == null) {
                offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultIsolatedNetworkOfferingForVpcNetworksWithInternalLB, "Offering for Isolated VPC networks with Internal Lb support", TrafficType.Guest, null, false, Availability.Optional, null, internalLbOffProviders, true, Network.GuestType.Isolated, false, null, false, null, false, false, null, false, null, true, true, null, null, true);
                offering.setInternalLb(true);
                offering.setPublicLb(false);
                _networkOfferingDao.update(offering.getId(), offering);
            }
            final Map<Network.Service, Set<Network.Provider>> netscalerServiceProviders = new HashMap<Network.Service, Set<Network.Provider>>();
            final Set<Network.Provider> vrProvider = new HashSet<Network.Provider>();
            vrProvider.add(Provider.VirtualRouter);
            final Set<Network.Provider> sgProvider = new HashSet<Network.Provider>();
            sgProvider.add(Provider.SecurityGroupProvider);
            final Set<Network.Provider> nsProvider = new HashSet<Network.Provider>();
            nsProvider.add(Provider.Netscaler);
            netscalerServiceProviders.put(Service.Dhcp, vrProvider);
            netscalerServiceProviders.put(Service.Dns, vrProvider);
            netscalerServiceProviders.put(Service.UserData, vrProvider);
            netscalerServiceProviders.put(Service.SecurityGroup, sgProvider);
            netscalerServiceProviders.put(Service.StaticNat, nsProvider);
            netscalerServiceProviders.put(Service.Lb, nsProvider);
            final Map<Service, Map<Capability, String>> serviceCapabilityMap = new HashMap<Service, Map<Capability, String>>();
            final Map<Capability, String> elb = new HashMap<Capability, String>();
            elb.put(Capability.ElasticLb, "true");
            final Map<Capability, String> eip = new HashMap<Capability, String>();
            eip.put(Capability.ElasticIp, "true");
            serviceCapabilityMap.put(Service.Lb, elb);
            serviceCapabilityMap.put(Service.StaticNat, eip);
            if (_networkOfferingDao.findByUniqueName(NetworkOffering.DefaultSharedEIPandELBNetworkOffering) == null) {
                offering = _configMgr.createNetworkOffering(NetworkOffering.DefaultSharedEIPandELBNetworkOffering, "Offering for Shared networks with Elastic IP and Elastic LB capabilities", TrafficType.Guest, null, true, Availability.Optional, null, netscalerServiceProviders, true, Network.GuestType.Shared, false, null, true, serviceCapabilityMap, true, false, null, false, null, true, false, null, null, true);
                offering.setDedicatedLB(false);
                _networkOfferingDao.update(offering.getId(), offering);
            }
            _networkOfferingDao.persistDefaultL2NetworkOfferings();
        }
    });
    AssignIpAddressSearch = _ipAddressDao.createSearchBuilder();
    AssignIpAddressSearch.and("dc", AssignIpAddressSearch.entity().getDataCenterId(), Op.EQ);
    AssignIpAddressSearch.and("allocated", AssignIpAddressSearch.entity().getAllocatedTime(), Op.NULL);
    AssignIpAddressSearch.and("vlanId", AssignIpAddressSearch.entity().getVlanId(), Op.IN);
    final SearchBuilder<VlanVO> vlanSearch = _vlanDao.createSearchBuilder();
    vlanSearch.and("type", vlanSearch.entity().getVlanType(), Op.EQ);
    vlanSearch.and("networkId", vlanSearch.entity().getNetworkId(), Op.EQ);
    AssignIpAddressSearch.join("vlan", vlanSearch, vlanSearch.entity().getId(), AssignIpAddressSearch.entity().getVlanId(), JoinType.INNER);
    AssignIpAddressSearch.done();
    AssignIpAddressFromPodVlanSearch = _ipAddressDao.createSearchBuilder();
    AssignIpAddressFromPodVlanSearch.and("dc", AssignIpAddressFromPodVlanSearch.entity().getDataCenterId(), Op.EQ);
    AssignIpAddressFromPodVlanSearch.and("allocated", AssignIpAddressFromPodVlanSearch.entity().getAllocatedTime(), Op.NULL);
    AssignIpAddressFromPodVlanSearch.and("vlanId", AssignIpAddressFromPodVlanSearch.entity().getVlanId(), Op.IN);
    final SearchBuilder<VlanVO> podVlanSearch = _vlanDao.createSearchBuilder();
    podVlanSearch.and("type", podVlanSearch.entity().getVlanType(), Op.EQ);
    podVlanSearch.and("networkId", podVlanSearch.entity().getNetworkId(), Op.EQ);
    final SearchBuilder<PodVlanMapVO> podVlanMapSB = _podVlanMapDao.createSearchBuilder();
    podVlanMapSB.and("podId", podVlanMapSB.entity().getPodId(), Op.EQ);
    AssignIpAddressFromPodVlanSearch.join("podVlanMapSB", podVlanMapSB, podVlanMapSB.entity().getVlanDbId(), AssignIpAddressFromPodVlanSearch.entity().getVlanId(), JoinType.INNER);
    AssignIpAddressFromPodVlanSearch.join("vlan", podVlanSearch, podVlanSearch.entity().getId(), AssignIpAddressFromPodVlanSearch.entity().getVlanId(), JoinType.INNER);
    AssignIpAddressFromPodVlanSearch.done();
    _executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Network-Scavenger"));
    _agentMgr.registerForHostEvents(this, true, false, true);
    Network.State.getStateMachine().registerListener(new NetworkStateListener(_configDao));
    s_logger.info("Network Manager is configured.");
    return true;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) VlanVO(com.cloud.dc.VlanVO) HashSet(java.util.HashSet) Capability(com.cloud.network.Network.Capability) NamedThreadFactory(com.cloud.utils.concurrency.NamedThreadFactory) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ResourceLimitService(com.cloud.user.ResourceLimitService) VpcVirtualNetworkApplianceService(com.cloud.network.VpcVirtualNetworkApplianceService) AnnotationService(org.apache.cloudstack.annotation.AnnotationService) RemoteAccessVpnService(com.cloud.network.vpn.RemoteAccessVpnService) DnsServiceProvider(com.cloud.network.element.DnsServiceProvider) UserDataServiceProvider(com.cloud.network.element.UserDataServiceProvider) DhcpServiceProvider(com.cloud.network.element.DhcpServiceProvider) LoadBalancingServiceProvider(com.cloud.network.element.LoadBalancingServiceProvider) StaticNatServiceProvider(com.cloud.network.element.StaticNatServiceProvider) Provider(com.cloud.network.Network.Provider) NetworkStateListener(com.cloud.network.NetworkStateListener) PodVlanMapVO(com.cloud.dc.PodVlanMapVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) DB(com.cloud.utils.db.DB)

Example 92 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cloudstack by apache.

the class NetworkOrchestrator method implementNetwork.

@Override
@DB
public Pair<NetworkGuru, NetworkVO> implementNetwork(final long networkId, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
    final Pair<NetworkGuru, NetworkVO> implemented = new Pair<NetworkGuru, NetworkVO>(null, null);
    NetworkVO network = _networksDao.findById(networkId);
    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
    if (isNetworkImplemented(network)) {
        s_logger.debug("Network id=" + networkId + " is already implemented");
        implemented.set(guru, network);
        return implemented;
    }
    // Acquire lock only when network needs to be implemented
    network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
    if (network == null) {
        // see NetworkVO.java
        final ConcurrentOperationException ex = new ConcurrentOperationException("Unable to acquire network configuration");
        ex.addProxyObject(_entityMgr.findById(Network.class, networkId).getUuid());
        throw ex;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Lock is acquired for network id " + networkId + " as a part of network implement");
    }
    try {
        if (isNetworkImplemented(network)) {
            s_logger.debug("Network id=" + networkId + " is already implemented");
            implemented.set(guru, network);
            return implemented;
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Asking " + guru.getName() + " to implement " + network);
        }
        final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
        network.setReservationId(context.getReservationId());
        if (isSharedNetworkWithServices(network)) {
            network.setState(Network.State.Implementing);
        } else {
            stateTransitTo(network, Event.ImplementNetwork);
        }
        final Network result = guru.implement(network, offering, dest, context);
        network.setCidr(result.getCidr());
        network.setBroadcastUri(result.getBroadcastUri());
        network.setGateway(result.getGateway());
        network.setMode(result.getMode());
        network.setPhysicalNetworkId(result.getPhysicalNetworkId());
        _networksDao.update(networkId, network);
        // implement network elements and re-apply all the network rules
        implementNetworkElementsAndResources(dest, context, network, offering);
        long dcId = dest.getDataCenter().getId();
        if (networkMeetsPersistenceCriteria(network, offering, false)) {
            setupPersistentNetwork(network, offering, dcId);
        }
        if (isSharedNetworkWithServices(network)) {
            network.setState(Network.State.Implemented);
        } else {
            stateTransitTo(network, Event.OperationSucceeded);
        }
        network.setRestartRequired(false);
        _networksDao.update(network.getId(), network);
        implemented.set(guru, network);
        return implemented;
    } catch (final NoTransitionException e) {
        s_logger.error(e.getMessage());
        return new Pair<NetworkGuru, NetworkVO>(null, null);
    } catch (final CloudRuntimeException | OperationTimedoutException e) {
        s_logger.error("Caught exception: " + e.getMessage());
        return new Pair<NetworkGuru, NetworkVO>(null, null);
    } finally {
        if (implemented.first() == null) {
            s_logger.debug("Cleaning up because we're unable to implement the network " + network);
            try {
                if (isSharedNetworkWithServices(network)) {
                    network.setState(Network.State.Shutdown);
                    _networksDao.update(networkId, network);
                } else {
                    stateTransitTo(network, Event.OperationFailed);
                }
            } catch (final NoTransitionException e) {
                s_logger.error(e.getMessage());
            }
            try {
                shutdownNetwork(networkId, context, false);
            } catch (final Exception e) {
                // Don't throw this exception as it would hide the original thrown exception, just log
                s_logger.error("Exception caught while shutting down a network as part of a failed implementation", e);
            }
        }
        _networksDao.releaseFromLockTable(networkId);
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Lock is released for network id " + networkId + " as a part of network implement");
        }
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) NetworkGuru(com.cloud.network.guru.NetworkGuru) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConnectionException(com.cloud.exception.ConnectionException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ResourceAllocationException(com.cloud.exception.ResourceAllocationException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) Pair(com.cloud.utils.Pair) DB(com.cloud.utils.db.DB)

Example 93 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cloudstack by apache.

the class NetworkOrchestrator method reprogramNetworkRules.

// This method re-programs the rules/ips for existing network
protected boolean reprogramNetworkRules(final long networkId, final Account caller, final Network network) throws ResourceUnavailableException {
    boolean success = true;
    // Apply egress rules first to effect the egress policy early on the guest traffic
    final List<FirewallRuleVO> firewallEgressRulesToApply = _firewallDao.listByNetworkPurposeTrafficType(networkId, Purpose.Firewall, FirewallRule.TrafficType.Egress);
    final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    final DataCenter zone = _dcDao.findById(network.getDataCenterId());
    if (_networkModel.areServicesSupportedInNetwork(network.getId(), Service.Firewall) && _networkModel.areServicesSupportedInNetwork(network.getId(), Service.Firewall) && (network.getGuestType() == Network.GuestType.Isolated || network.getGuestType() == Network.GuestType.Shared && zone.getNetworkType() == NetworkType.Advanced)) {
        // add default egress rule to accept the traffic
        _firewallMgr.applyDefaultEgressFirewallRule(network.getId(), offering.isEgressDefaultPolicy(), true);
    }
    if (!_firewallMgr.applyFirewallRules(firewallEgressRulesToApply, false, caller)) {
        s_logger.warn("Failed to reapply firewall Egress rule(s) as a part of network id=" + networkId + " restart");
        success = false;
    }
    // associate all ip addresses
    if (!_ipAddrMgr.applyIpAssociations(network, false)) {
        s_logger.warn("Failed to apply ip addresses as a part of network id" + networkId + " restart");
        success = false;
    }
    // apply static nat
    if (!_rulesMgr.applyStaticNatsForNetwork(networkId, false, caller)) {
        s_logger.warn("Failed to apply static nats a part of network id" + networkId + " restart");
        success = false;
    }
    // apply firewall rules
    final List<FirewallRuleVO> firewallIngressRulesToApply = _firewallDao.listByNetworkPurposeTrafficType(networkId, Purpose.Firewall, FirewallRule.TrafficType.Ingress);
    if (!_firewallMgr.applyFirewallRules(firewallIngressRulesToApply, false, caller)) {
        s_logger.warn("Failed to reapply Ingress firewall rule(s) as a part of network id=" + networkId + " restart");
        success = false;
    }
    // apply port forwarding rules
    if (!_rulesMgr.applyPortForwardingRulesForNetwork(networkId, false, caller)) {
        s_logger.warn("Failed to reapply port forwarding rule(s) as a part of network id=" + networkId + " restart");
        success = false;
    }
    // apply static nat rules
    if (!_rulesMgr.applyStaticNatRulesForNetwork(networkId, false, caller)) {
        s_logger.warn("Failed to reapply static nat rule(s) as a part of network id=" + networkId + " restart");
        success = false;
    }
    // apply public load balancer rules
    if (!_lbMgr.applyLoadBalancersForNetwork(networkId, Scheme.Public)) {
        s_logger.warn("Failed to reapply Public load balancer rules as a part of network id=" + networkId + " restart");
        success = false;
    }
    // apply internal load balancer rules
    if (!_lbMgr.applyLoadBalancersForNetwork(networkId, Scheme.Internal)) {
        s_logger.warn("Failed to reapply internal load balancer rules as a part of network id=" + networkId + " restart");
        success = false;
    }
    // apply vpn rules
    final List<? extends RemoteAccessVpn> vpnsToReapply = _vpnMgr.listRemoteAccessVpns(networkId);
    if (vpnsToReapply != null) {
        for (final RemoteAccessVpn vpn : vpnsToReapply) {
            // Start remote access vpn per ip
            if (_vpnMgr.startRemoteAccessVpn(vpn.getServerAddressId(), false) == null) {
                s_logger.warn("Failed to reapply vpn rules as a part of network id=" + networkId + " restart");
                success = false;
            }
        }
    }
    // apply network ACLs
    if (!_networkACLMgr.applyACLToNetwork(networkId)) {
        s_logger.warn("Failed to reapply network ACLs as a part of  of network id=" + networkId + " restart");
        success = false;
    }
    return success;
}
Also used : DataCenter(com.cloud.dc.DataCenter) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn)

Example 94 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cloudstack by apache.

the class NetworkOrchestrator method isNetworkImplemented.

boolean isNetworkImplemented(final NetworkVO network) {
    final Network.State state = network.getState();
    final NetworkOfferingVO offeringVO = _networkOfferingDao.findById(network.getNetworkOfferingId());
    if (state == Network.State.Implemented) {
        return true;
    } else if (state == Network.State.Setup) {
        final DataCenterVO zone = _dcDao.findById(network.getDataCenterId());
        if ((!isSharedNetworkOfferingWithServices(network.getNetworkOfferingId()) && !offeringVO.isPersistent()) || zone.getNetworkType() == NetworkType.Basic) {
            return true;
        }
    }
    return false;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Example 95 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cloudstack by apache.

the class UserVmManagerImpl method getDefaultNetwork.

private NetworkVO getDefaultNetwork(DataCenter zone, Account owner, boolean selectAny) throws InsufficientCapacityException, ResourceAllocationException {
    NetworkVO defaultNetwork = null;
    // if no network is passed in
    // Check if default virtual network offering has
    // Availability=Required. If it's true, search for corresponding
    // network
    // * if network is found, use it. If more than 1 virtual network is
    // found, throw an error
    // * if network is not found, create a new one and use it
    List<NetworkOfferingVO> requiredOfferings = _networkOfferingDao.listByAvailability(Availability.Required, false);
    if (requiredOfferings.size() < 1) {
        throw new InvalidParameterValueException("Unable to find network offering with availability=" + Availability.Required + " to automatically create the network as a part of vm creation");
    }
    if (requiredOfferings.get(0).getState() == NetworkOffering.State.Enabled) {
        // get Virtual networks
        List<? extends Network> virtualNetworks = _networkModel.listNetworksForAccount(owner.getId(), zone.getId(), Network.GuestType.Isolated);
        if (virtualNetworks == null) {
            throw new InvalidParameterValueException("No (virtual) networks are found for account " + owner);
        }
        if (virtualNetworks.isEmpty()) {
            defaultNetwork = createDefaultNetworkForAccount(zone, owner, requiredOfferings);
        } else if (virtualNetworks.size() > 1 && !selectAny) {
            throw new InvalidParameterValueException("More than 1 default Isolated networks are found for account " + owner + "; please specify networkIds");
        } else {
            defaultNetwork = _networkDao.findById(virtualNetworks.get(0).getId());
        }
    } else {
        throw new InvalidParameterValueException("Required network offering id=" + requiredOfferings.get(0).getId() + " is not in " + NetworkOffering.State.Enabled);
    }
    return defaultNetwork;
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Aggregations

NetworkOfferingVO (com.cloud.offerings.NetworkOfferingVO)128 NetworkVO (com.cloud.network.dao.NetworkVO)45 ArrayList (java.util.ArrayList)34 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)32 Network (com.cloud.network.Network)27 DB (com.cloud.utils.db.DB)27 Test (org.junit.Test)27 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)26 Service (com.cloud.network.Network.Service)26 Account (com.cloud.user.Account)24 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)23 Provider (com.cloud.network.Network.Provider)22 PhysicalNetwork (com.cloud.network.PhysicalNetwork)21 HashSet (java.util.HashSet)21 TransactionStatus (com.cloud.utils.db.TransactionStatus)20 HashMap (java.util.HashMap)20 Set (java.util.Set)20 DataCenterVO (com.cloud.dc.DataCenterVO)19 NetworkOffering (com.cloud.offering.NetworkOffering)19 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)18