Search in sources :

Example 41 with IpAddressTO

use of com.cloud.agent.api.to.IpAddressTO in project cloudstack by apache.

the class CommandSetupHelper method createVpcAssociatePrivateIPCommands.

public void createVpcAssociatePrivateIPCommands(final VirtualRouter router, final List<PrivateIpAddress> ips, final Commands cmds, final boolean add) {
    // Ensure that in multiple vlans case we first send all ip addresses of
    // vlan1, then all ip addresses of vlan2, etc..
    final Map<String, ArrayList<PrivateIpAddress>> vlanIpMap = new HashMap<String, ArrayList<PrivateIpAddress>>();
    for (final PrivateIpAddress ipAddress : ips) {
        final String vlanTag = ipAddress.getBroadcastUri();
        ArrayList<PrivateIpAddress> ipList = vlanIpMap.get(vlanTag);
        if (ipList == null) {
            ipList = new ArrayList<PrivateIpAddress>();
        }
        ipList.add(ipAddress);
        vlanIpMap.put(vlanTag, ipList);
    }
    for (final Map.Entry<String, ArrayList<PrivateIpAddress>> vlanAndIp : vlanIpMap.entrySet()) {
        final List<PrivateIpAddress> ipAddrList = vlanAndIp.getValue();
        final IpAddressTO[] ipsToSend = new IpAddressTO[ipAddrList.size()];
        int i = 0;
        for (final PrivateIpAddress ipAddr : ipAddrList) {
            final Network network = _networkModel.getNetwork(ipAddr.getNetworkId());
            final IpAddressTO ip = new IpAddressTO(Account.ACCOUNT_ID_SYSTEM, ipAddr.getIpAddress(), add, false, ipAddr.getSourceNat(), ipAddr.getBroadcastUri(), ipAddr.getGateway(), ipAddr.getNetmask(), ipAddr.getMacAddress(), null, false);
            ip.setTrafficType(network.getTrafficType());
            ip.setNetworkName(_networkModel.getNetworkTag(router.getHypervisorType(), network));
            ipsToSend[i++] = ip;
        }
        final IpAssocVpcCommand cmd = new IpAssocVpcCommand(ipsToSend);
        cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
        cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(ipAddrList.get(0).getNetworkId(), 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("IPAssocVpcCommand", cmd);
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) IpAddressTO(com.cloud.agent.api.to.IpAddressTO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IpAssocVpcCommand(com.cloud.agent.api.routing.IpAssocVpcCommand) Network(com.cloud.network.Network) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

IpAddressTO (com.cloud.agent.api.to.IpAddressTO)41 ExecutionResult (com.cloud.utils.ExecutionResult)16 InternalErrorException (com.cloud.exception.InternalErrorException)14 IOException (java.io.IOException)12 ConfigurationException (javax.naming.ConfigurationException)12 IpAssocAnswer (com.cloud.agent.api.routing.IpAssocAnswer)9 IpAssocCommand (com.cloud.agent.api.routing.IpAssocCommand)8 ArrayList (java.util.ArrayList)8 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 URISyntaxException (java.net.URISyntaxException)7 HashMap (java.util.HashMap)7 Answer (com.cloud.agent.api.Answer)6 ConnectException (java.net.ConnectException)6 RemoteException (java.rmi.RemoteException)6 IpAssocVpcCommand (com.cloud.agent.api.routing.IpAssocVpcCommand)5 URI (java.net.URI)5 Connect (org.libvirt.Connect)5 LibvirtException (org.libvirt.LibvirtException)5 DataCenterVO (com.cloud.dc.DataCenterVO)4 ExecutionException (com.cloud.utils.exception.ExecutionException)4