Search in sources :

Example 71 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method updateNetworkOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_EDIT, eventDescription = "updating network offering")
public NetworkOffering updateNetworkOffering(final UpdateNetworkOfferingCmd cmd) {
    final String displayText = cmd.getDisplayText();
    final Long id = cmd.getId();
    final String name = cmd.getNetworkOfferingName();
    final String availabilityStr = cmd.getAvailability();
    final Integer sortKey = cmd.getSortKey();
    final Integer maxconn = cmd.getMaxconnections();
    Availability availability = null;
    final String state = cmd.getState();
    CallContext.current().setEventDetails(" Id: " + id);
    // Verify input parameters
    final NetworkOfferingVO offeringToUpdate = _networkOfferingDao.findById(id);
    if (offeringToUpdate == null) {
        throw new InvalidParameterValueException("unable to find network offering " + id);
    }
    // Don't allow to update system network offering
    if (offeringToUpdate.isSystemOnly()) {
        throw new InvalidParameterValueException("Can't update system network offerings");
    }
    final NetworkOfferingVO offering = _networkOfferingDao.createForUpdate(id);
    if (name != null) {
        offering.setName(name);
    }
    if (displayText != null) {
        offering.setDisplayText(displayText);
    }
    if (sortKey != null) {
        offering.setSortKey(sortKey);
    }
    if (state != null) {
        boolean validState = false;
        for (final NetworkOffering.State st : NetworkOffering.State.values()) {
            if (st.name().equalsIgnoreCase(state)) {
                validState = true;
                offering.setState(st);
            }
        }
        if (!validState) {
            throw new InvalidParameterValueException("Incorrect state value: " + state);
        }
    }
    // Verify availability
    if (availabilityStr != null) {
        for (final Availability avlb : Availability.values()) {
            if (avlb.name().equalsIgnoreCase(availabilityStr)) {
                availability = avlb;
            }
        }
        if (availability == null) {
            throw new InvalidParameterValueException("Invalid value for Availability. Supported types: " + Availability.Required + ", " + Availability.Optional);
        } else {
            if (availability == NetworkOffering.Availability.Required) {
                final boolean canOffBeRequired = offeringToUpdate.getGuestType() == GuestType.Isolated && _networkModel.areServicesSupportedByNetworkOffering(offeringToUpdate.getId(), Service.SourceNat);
                if (!canOffBeRequired) {
                    throw new InvalidParameterValueException("Availability can be " + NetworkOffering.Availability.Required + " only for networkOfferings of type " + GuestType.Isolated + " and with " + Service.SourceNat.getName() + " enabled");
                }
                // only one network offering in the system can be Required
                final List<NetworkOfferingVO> offerings = _networkOfferingDao.listByAvailability(Availability.Required, false);
                if (!offerings.isEmpty() && offerings.get(0).getId() != offeringToUpdate.getId()) {
                    throw new InvalidParameterValueException("System already has network offering id=" + offerings.get(0).getId() + " with availability " + Availability.Required);
                }
            }
            offering.setAvailability(availability);
        }
    }
    if (_ntwkOffServiceMapDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Lb)) {
        if (maxconn != null) {
            offering.setConcurrentConnections(maxconn);
        }
    }
    if (_networkOfferingDao.update(id, offering)) {
        return _networkOfferingDao.findById(id);
    } else {
        return null;
    }
}
Also used : Availability(com.cloud.offering.NetworkOffering.Availability) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NetworkOffering(com.cloud.offering.NetworkOffering) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ActionEvent(com.cloud.event.ActionEvent)

Example 72 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method deleteNetworkOffering.

@Override
@ActionEvent(eventType = EventTypes.EVENT_NETWORK_OFFERING_DELETE, eventDescription = "deleting network offering")
public boolean deleteNetworkOffering(final DeleteNetworkOfferingCmd cmd) {
    final Long offeringId = cmd.getId();
    CallContext.current().setEventDetails(" Id: " + offeringId);
    // Verify network offering id
    final NetworkOfferingVO offering = _networkOfferingDao.findById(offeringId);
    if (offering == null) {
        throw new InvalidParameterValueException("unable to find network offering " + offeringId);
    } else if (offering.getRemoved() != null || offering.isSystemOnly()) {
        throw new InvalidParameterValueException("unable to find network offering " + offeringId);
    }
    // Don't allow to delete default network offerings
    if (offering.isDefault() == true) {
        throw new InvalidParameterValueException("Default network offering can't be deleted");
    }
    // don't allow to delete network offering if it's in use by existing
    // networks (the offering can be disabled
    // though)
    final int networkCount = _networkDao.getNetworkCountByNetworkOffId(offeringId);
    if (networkCount > 0) {
        throw new InvalidParameterValueException("Can't delete network offering " + offeringId + " as its used by " + networkCount + " networks. " + "To make the network offering unavaiable, disable it");
    }
    if (_networkOfferingDao.remove(offeringId)) {
        return true;
    } else {
        return false;
    }
}
Also used : InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) ActionEvent(com.cloud.event.ActionEvent)

Example 73 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cosmic by MissionCriticalCloud.

the class ConfigurationManagerImpl method listNetworkOfferings.

@Override
public List<? extends NetworkOffering> listNetworkOfferings(final TrafficType trafficType, final boolean systemOnly) {
    final Filter searchFilter = new Filter(NetworkOfferingVO.class, "created", false, null, null);
    final SearchCriteria<NetworkOfferingVO> sc = _networkOfferingDao.createSearchCriteria();
    if (trafficType != null) {
        sc.addAnd("trafficType", SearchCriteria.Op.EQ, trafficType);
    }
    sc.addAnd("systemOnly", SearchCriteria.Op.EQ, systemOnly);
    return _networkOfferingDao.search(sc, searchFilter);
}
Also used : Filter(com.cloud.utils.db.Filter) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO)

Example 74 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cosmic by MissionCriticalCloud.

the class CommandSetupHelper method createApplyFirewallRulesCommands.

public void createApplyFirewallRulesCommands(final List<? extends FirewallRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
    final List<FirewallRuleTO> rulesTO = new ArrayList<>();
    String systemRule = null;
    Boolean defaultEgressPolicy = false;
    if (rules != null) {
        if (rules.size() > 0) {
            if (rules.get(0).getTrafficType() == FirewallRule.TrafficType.Egress && rules.get(0).getType() == FirewallRule.FirewallRuleType.System) {
                systemRule = String.valueOf(FirewallRule.FirewallRuleType.System);
            }
        }
        for (final FirewallRule rule : rules) {
            _rulesDao.loadSourceCidrs((FirewallRuleVO) rule);
            final FirewallRule.TrafficType traffictype = rule.getTrafficType();
            if (traffictype == FirewallRule.TrafficType.Ingress) {
                final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
                final FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, sourceIp.getAddress().addr(), Purpose.Firewall, traffictype);
                rulesTO.add(ruleTO);
            } else if (rule.getTrafficType() == FirewallRule.TrafficType.Egress) {
                final NetworkVO network = _networkDao.findById(guestNetworkId);
                final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
                defaultEgressPolicy = offering.getEgressDefaultPolicy();
                assert rule.getSourceIpAddressId() == null : "ipAddressId should be null for egress firewall rule. ";
                final FirewallRuleTO ruleTO = new FirewallRuleTO(rule, null, "", Purpose.Firewall, traffictype, defaultEgressPolicy);
                rulesTO.add(ruleTO);
            }
        }
    }
    final SetFirewallRulesCommand cmd = new SetFirewallRulesCommand(rulesTO);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final Zone zone = zoneRepository.findOne(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, zone.getNetworkType().toString());
    if (systemRule != null) {
        cmd.setAccessDetail(NetworkElementCommand.FIREWALL_EGRESS_DEFAULT, systemRule);
    } else {
        cmd.setAccessDetail(NetworkElementCommand.FIREWALL_EGRESS_DEFAULT, String.valueOf(defaultEgressPolicy));
    }
    cmds.addCommand(cmd);
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) Zone(com.cloud.db.model.Zone) ArrayList(java.util.ArrayList) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) FirewallRuleTO(com.cloud.agent.api.to.FirewallRuleTO) FirewallRule(com.cloud.network.rules.FirewallRule) SetFirewallRulesCommand(com.cloud.agent.api.routing.SetFirewallRulesCommand)

Example 75 with NetworkOfferingVO

use of com.cloud.offerings.NetworkOfferingVO in project cosmic by MissionCriticalCloud.

the class NetworkModelImpl method checkIpForService.

@Override
public boolean checkIpForService(final IpAddress userIp, final Service service, Long networkId) {
    if (networkId == null) {
        networkId = userIp.getAssociatedWithNetworkId();
    }
    final NetworkVO network = _networksDao.findById(networkId);
    final NetworkOfferingVO offering = _networkOfferingDao.findById(network.getNetworkOfferingId());
    if (offering.getGuestType() != GuestType.Isolated) {
        return true;
    }
    final IPAddressVO ipVO = _ipAddressDao.findById(userIp.getId());
    final PublicIp publicIp = PublicIp.createFromAddrAndVlan(ipVO, _vlanDao.findById(userIp.getVlanId()));
    if (!canIpUsedForService(publicIp, service, networkId)) {
        return false;
    }
    if (!offering.isConserveMode()) {
        return canIpUsedForNonConserveService(publicIp, service);
    }
    return true;
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) PublicIp(com.cloud.network.addr.PublicIp) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) IPAddressVO(com.cloud.network.dao.IPAddressVO)

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