Search in sources :

Example 31 with IpAddress

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

the class NiciraNvpElement method applyPFRules.

/**
     * From interface PortForwardingServiceProvider
     */
@Override
public boolean applyPFRules(Network network, List<PortForwardingRule> rules) throws ResourceUnavailableException {
    if (!canHandle(network, Service.PortForwarding)) {
        return false;
    }
    List<NiciraNvpDeviceVO> devices = niciraNvpDao.listByPhysicalNetwork(network.getPhysicalNetworkId());
    if (devices.isEmpty()) {
        s_logger.error("No NiciraNvp Controller on physical network " + network.getPhysicalNetworkId());
        return false;
    }
    NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
    HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
    NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
    if (routermapping == null) {
        s_logger.error("No logical router uuid found for network " + network.getDisplayText());
        return false;
    }
    List<PortForwardingRuleTO> portForwardingRules = 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());
        portForwardingRules.add(ruleTO);
    }
    ConfigurePortForwardingRulesOnLogicalRouterCommand cmd = new ConfigurePortForwardingRulesOnLogicalRouterCommand(routermapping.getLogicalRouterUuid(), portForwardingRules);
    ConfigurePortForwardingRulesOnLogicalRouterAnswer answer = (ConfigurePortForwardingRulesOnLogicalRouterAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
    return answer.getResult();
}
Also used : PortForwardingRuleTO(com.cloud.agent.api.to.PortForwardingRuleTO) NiciraNvpRouterMappingVO(com.cloud.network.NiciraNvpRouterMappingVO) ConfigurePortForwardingRulesOnLogicalRouterCommand(com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterCommand) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) Vlan(com.cloud.dc.Vlan) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) ConfigurePortForwardingRulesOnLogicalRouterAnswer(com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer) HostVO(com.cloud.host.HostVO)

Example 32 with IpAddress

use of com.cloud.network.IpAddress in project CloudStack-archive by CloudStack-extras.

the class ListPublicIpAddressesCmd method execute.

@Override
public void execute() {
    List<? extends IpAddress> result = _mgr.searchForIPAddresses(this);
    ListResponse<IPAddressResponse> response = new ListResponse<IPAddressResponse>();
    List<IPAddressResponse> ipAddrResponses = new ArrayList<IPAddressResponse>();
    for (IpAddress ipAddress : result) {
        IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ipAddress);
        ipResponse.setObjectName("publicipaddress");
        ipAddrResponses.add(ipResponse);
    }
    response.setResponses(ipAddrResponses);
    response.setResponseName(getCommandName());
    this.setResponseObject(response);
}
Also used : ListResponse(com.cloud.api.response.ListResponse) ArrayList(java.util.ArrayList) IpAddress(com.cloud.network.IpAddress) IPAddressResponse(com.cloud.api.response.IPAddressResponse)

Example 33 with IpAddress

use of com.cloud.network.IpAddress in project CloudStack-archive by CloudStack-extras.

the class AssociateIPAddrCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
    UserContext.current().setEventDetails("Ip Id: " + getEntityId());
    IpAddress result = _networkService.associateIP(getEntityId());
    if (result != null) {
        IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(result);
        ipResponse.setResponseName(getCommandName());
        this.setResponseObject(ipResponse);
    } else {
        throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to assign ip address");
    }
}
Also used : ServerApiException(com.cloud.api.ServerApiException) IpAddress(com.cloud.network.IpAddress) IPAddressResponse(com.cloud.api.response.IPAddressResponse)

Example 34 with IpAddress

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

the class CommandSetupHelper method createApplyStaticNatCommands.

public void createApplyStaticNatCommands(final List<? extends StaticNat> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
    final List<StaticNatRuleTO> rulesTO = new ArrayList<StaticNatRuleTO>();
    if (rules != null) {
        for (final StaticNat rule : rules) {
            final IpAddress sourceIp = _networkModel.getIp(rule.getSourceIpAddressId());
            final StaticNatRuleTO ruleTO = new StaticNatRuleTO(0, sourceIp.getAddress().addr(), null, null, rule.getDestIpAddress(), null, null, null, rule.isForRevoke(), false);
            rulesTO.add(ruleTO);
        }
    }
    final SetStaticNatRulesCommand cmd = new SetStaticNatRulesCommand(rulesTO, router.getVpcId());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
    cmds.addCommand(cmd);
}
Also used : StaticNatRuleTO(com.cloud.agent.api.to.StaticNatRuleTO) DataCenterVO(com.cloud.dc.DataCenterVO) SetStaticNatRulesCommand(com.cloud.agent.api.routing.SetStaticNatRulesCommand) ArrayList(java.util.ArrayList) PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) StaticNat(com.cloud.network.rules.StaticNat)

Example 35 with IpAddress

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

the class CommandSetupHelper method createSite2SiteVpnCfgCommands.

public void createSite2SiteVpnCfgCommands(final Site2SiteVpnConnection conn, final boolean isCreate, final VirtualRouter router, final Commands cmds) {
    final Site2SiteCustomerGatewayVO gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
    final Site2SiteVpnGatewayVO vpnGw = _s2sVpnGatewayDao.findById(conn.getVpnGatewayId());
    final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId());
    final Vpc vpc = _vpcDao.findById(ip.getVpcId());
    final String localPublicIp = ip.getAddress().toString();
    final String localGuestCidr = vpc.getCidr();
    final String localPublicGateway = _vlanDao.findById(ip.getVlanId()).getVlanGateway();
    final String peerGatewayIp = gw.getGatewayIp();
    final String peerGuestCidrList = gw.getGuestCidrList();
    final String ipsecPsk = gw.getIpsecPsk();
    final String ikePolicy = gw.getIkePolicy();
    final String espPolicy = gw.getEspPolicy();
    final Long ikeLifetime = gw.getIkeLifetime();
    final Long espLifetime = gw.getEspLifetime();
    final Boolean dpd = gw.getDpd();
    final Boolean encap = gw.getEncap();
    final Site2SiteVpnCfgCommand cmd = new Site2SiteVpnCfgCommand(isCreate, localPublicIp, localPublicGateway, localGuestCidr, peerGatewayIp, peerGuestCidrList, ikePolicy, espPolicy, ipsecPsk, ikeLifetime, espLifetime, dpd, conn.isPassive(), encap);
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
    cmds.addCommand("applyS2SVpn", cmd);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Site2SiteVpnCfgCommand(com.cloud.agent.api.routing.Site2SiteVpnCfgCommand) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) Vpc(com.cloud.network.vpc.Vpc) Site2SiteVpnGatewayVO(com.cloud.network.dao.Site2SiteVpnGatewayVO) PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress)

Aggregations

IpAddress (com.cloud.network.IpAddress)58 ArrayList (java.util.ArrayList)26 PublicIpAddress (com.cloud.network.PublicIpAddress)20 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)16 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)16 Network (com.cloud.network.Network)14 FirewallRule (com.cloud.network.rules.FirewallRule)11 HostVO (com.cloud.host.HostVO)9 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)9 DataCenterVO (com.cloud.dc.DataCenterVO)7 CiscoVnmcControllerVO (com.cloud.network.cisco.CiscoVnmcControllerVO)7 NetworkAsa1000vMapVO (com.cloud.network.cisco.NetworkAsa1000vMapVO)7 IPAddressVO (com.cloud.network.dao.IPAddressVO)7 PrivateIpAddress (com.cloud.network.vpc.PrivateIpAddress)7 Answer (com.cloud.agent.api.Answer)6 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)6 PublicIp (com.cloud.network.addr.PublicIp)6 StaticNat (com.cloud.network.rules.StaticNat)6 Account (com.cloud.user.Account)6 NetworkRuleConflictException (com.cloud.exception.NetworkRuleConflictException)5