Search in sources :

Example 1 with Vlan

use of com.cloud.dc.Vlan in project CloudStack-archive by CloudStack-extras.

the class ListVlanIpRangesCmd method execute.

@Override
public void execute() {
    List<? extends Vlan> vlans = _mgr.searchForVlans(this);
    ListResponse<VlanIpRangeResponse> response = new ListResponse<VlanIpRangeResponse>();
    List<VlanIpRangeResponse> vlanResponses = new ArrayList<VlanIpRangeResponse>();
    for (Vlan vlan : vlans) {
        VlanIpRangeResponse vlanResponse = _responseGenerator.createVlanIpRangeResponse(vlan);
        vlanResponse.setObjectName("vlaniprange");
        vlanResponses.add(vlanResponse);
    }
    response.setResponses(vlanResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : VlanIpRangeResponse(com.cloud.api.response.VlanIpRangeResponse) ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) Vlan(com.cloud.dc.Vlan)

Example 2 with Vlan

use of com.cloud.dc.Vlan in project CloudStack-archive by CloudStack-extras.

the class CreateVlanIpRangeCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException {
    try {
        Vlan result = _configService.createVlanAndPublicIpRange(this);
        if (result != null) {
            VlanIpRangeResponse response = _responseGenerator.createVlanIpRangeResponse(result);
            response.setResponseName(getCommandName());
            this.setResponseObject(response);
        } else {
            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create vlan ip range");
        }
    } catch (ConcurrentOperationException ex) {
        s_logger.warn("Exception: ", ex);
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
    } catch (InsufficientCapacityException ex) {
        s_logger.info(ex);
        throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
    }
}
Also used : VlanIpRangeResponse(com.cloud.api.response.VlanIpRangeResponse) ServerApiException(com.cloud.api.ServerApiException) Vlan(com.cloud.dc.Vlan) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

Example 3 with Vlan

use of com.cloud.dc.Vlan in project cloudstack by apache.

the class CiscoVnmcElement method applyPFRules.

@Override
public boolean applyPFRules(Network network, List<PortForwardingRule> rules) throws ResourceUnavailableException {
    if (!_networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.PortForwarding, Provider.CiscoVnmc)) {
        s_logger.error("Port forwarding service is not provided by Cisco Vnmc device on network " + network.getName());
        return false;
    }
    // Find VNMC host for physical network
    List<CiscoVnmcControllerVO> devices = _ciscoVnmcDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No Cisco Vnmc device on network " + network.getName());
        return true;
    }
    // Find if ASA 1000v is associated with network
    NetworkAsa1000vMapVO asaForNetwork = _networkAsa1000vMapDao.findByNetworkId(network.getId());
    if (asaForNetwork == null) {
        s_logger.debug("Cisco ASA 1000v device is not associated with network " + network.getName());
        return true;
    }
    if (network.getState() == Network.State.Allocated) {
        s_logger.debug("External firewall was asked to apply port forwarding rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands.");
        return true;
    }
    CiscoVnmcControllerVO ciscoVnmcDevice = devices.get(0);
    HostVO ciscoVnmcHost = _hostDao.findById(ciscoVnmcDevice.getHostId());
    List<PortForwardingRuleTO> rulesTO = new ArrayList<PortForwardingRuleTO>();
    for (PortForwardingRule rule : rules) {
        IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
        Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
        PortForwardingRuleTO ruleTO = new PortForwardingRuleTO(rule, vlan.getVlanTag(), sourceIp.getAddress().addr());
        rulesTO.add(ruleTO);
    }
    if (!rulesTO.isEmpty()) {
        SetPortForwardingRulesCommand cmd = new SetPortForwardingRulesCommand(rulesTO);
        cmd.setContextParam(NetworkElementCommand.GUEST_VLAN_TAG, BroadcastDomainType.getValue(network.getBroadcastUri()));
        cmd.setContextParam(NetworkElementCommand.GUEST_NETWORK_CIDR, network.getCidr());
        Answer answer = _agentMgr.easySend(ciscoVnmcHost.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            String details = (answer != null) ? answer.getDetails() : "details unavailable";
            String msg = "Unable to apply port forwarding rules to Cisco ASA 1000v appliance due to: " + details + ".";
            s_logger.error(msg);
            throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId());
        }
    }
    return true;
}
Also used : PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) ArrayList(java.util.ArrayList) Vlan(com.cloud.dc.Vlan) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) HostVO(com.cloud.host.HostVO) Answer(com.cloud.agent.api.Answer) SetPortForwardingRulesCommand(com.cloud.agent.api.routing.SetPortForwardingRulesCommand) NetworkAsa1000vMapVO(com.cloud.network.cisco.NetworkAsa1000vMapVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CiscoVnmcControllerVO(com.cloud.network.cisco.CiscoVnmcControllerVO) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress)

Example 4 with Vlan

use of com.cloud.dc.Vlan in project cloudstack by apache.

the class ConfigurationManagerImpl method deletePod.

@Override
@DB
public boolean deletePod(final DeletePodCmd cmd) {
    final Long podId = cmd.getId();
    // Make sure the pod exists
    if (!validPod(podId)) {
        throw new InvalidParameterValueException("A pod with ID: " + podId + " does not exist.");
    }
    checkIfPodIsDeletable(podId);
    final HostPodVO pod = _podDao.findById(podId);
    Transaction.execute(new TransactionCallbackNoReturn() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            // Delete private ip addresses for the pod if there are any
            final List<DataCenterIpAddressVO> privateIps = _privateIpAddressDao.listByPodIdDcId(podId, pod.getDataCenterId());
            if (!privateIps.isEmpty()) {
                if (!_privateIpAddressDao.deleteIpAddressByPod(podId)) {
                    throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
                }
            }
            // Delete link local ip addresses for the pod
            final List<DataCenterLinkLocalIpAddressVO> localIps = _linkLocalIpAllocDao.listByPodIdDcId(podId, pod.getDataCenterId());
            if (!localIps.isEmpty()) {
                if (!_linkLocalIpAllocDao.deleteIpAddressByPod(podId)) {
                    throw new CloudRuntimeException("Failed to cleanup private ip addresses for pod " + podId);
                }
            }
            // Delete vlans associated with the pod
            final List<? extends Vlan> vlans = _networkModel.listPodVlans(podId);
            if (vlans != null && !vlans.isEmpty()) {
                for (final Vlan vlan : vlans) {
                    _vlanDao.remove(vlan.getId());
                }
            }
            // Delete corresponding capacity records
            _capacityDao.removeBy(null, null, podId, null, null);
            // Delete the pod
            if (!_podDao.remove(podId)) {
                throw new CloudRuntimeException("Failed to delete pod " + podId);
            }
            // remove from dedicated resources
            final DedicatedResourceVO dr = _dedicatedDao.findByPodId(podId);
            if (dr != null) {
                _dedicatedDao.remove(dr.getId());
            }
        }
    });
    return true;
}
Also used : InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) ArrayList(java.util.ArrayList) List(java.util.List) Vlan(com.cloud.dc.Vlan) DedicatedResourceVO(com.cloud.dc.DedicatedResourceVO) HostPodVO(com.cloud.dc.HostPodVO) DB(com.cloud.utils.db.DB)

Example 5 with Vlan

use of com.cloud.dc.Vlan in project cloudstack by apache.

the class ExternalFirewallDeviceManagerImpl method applyStaticNatRules.

public boolean applyStaticNatRules(Network network, List<? extends StaticNat> rules) throws ResourceUnavailableException {
    long zoneId = network.getDataCenterId();
    DataCenterVO zone = _dcDao.findById(zoneId);
    ExternalFirewallDeviceVO fwDeviceVO = getExternalFirewallForNetwork(network);
    HostVO externalFirewall = _hostDao.findById(fwDeviceVO.getHostId());
    assert (externalFirewall != null);
    if (network.getState() == Network.State.Allocated) {
        s_logger.debug("External firewall was asked to apply firewall rules for network with ID " + network.getId() + "; this network is not implemented. Skipping backend commands.");
        return true;
    }
    List<StaticNatRuleTO> staticNatRules = new ArrayList<StaticNatRuleTO>();
    for (StaticNat rule : rules) {
        IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
        Vlan vlan = _vlanDao.findById(sourceIp.getVlanId());
        StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, vlan.getVlanTag(), sourceIp.getAddress().addr(), -1, -1, rule.getDestIpAddress(), -1, -1, "any", rule.isForRevoke(), false);
        staticNatRules.add(ruleTO);
    }
    sendStaticNatRules(staticNatRules, zone, externalFirewall.getId());
    return true;
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) ExternalFirewallDeviceVO(com.cloud.network.dao.ExternalFirewallDeviceVO) ArrayList(java.util.ArrayList) Vlan(com.cloud.dc.Vlan) HostVO(com.cloud.host.HostVO) StaticNat(com.cloud.network.rules.StaticNat)

Aggregations

Vlan (com.cloud.dc.Vlan)22 ArrayList (java.util.ArrayList)10 HostVO (com.cloud.host.HostVO)6 DataCenterVO (com.cloud.dc.DataCenterVO)5 VlanVO (com.cloud.dc.VlanVO)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)4 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)4 PortForwardingRuleTO (com.cloud.agent.api.to.PortForwardingRuleTO)3 IpAddress (com.cloud.network.IpAddress)3 ExternalFirewallDeviceVO (com.cloud.network.dao.ExternalFirewallDeviceVO)3 PortForwardingRule (com.cloud.network.rules.PortForwardingRule)3 VlanIpRangeResponse (org.apache.cloudstack.api.response.VlanIpRangeResponse)3 Answer (com.cloud.agent.api.Answer)2 VlanIpRangeResponse (com.cloud.api.response.VlanIpRangeResponse)2 HostPodVO (com.cloud.dc.HostPodVO)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 PublicIpAddress (com.cloud.network.PublicIpAddress)2 List (java.util.List)2 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)1