Search in sources :

Example 6 with PrivateIpAddress

use of com.cloud.network.vpc.PrivateIpAddress in project cloudstack by apache.

the class NicProfileHelperImpl method createPrivateNicProfileForGateway.

@Override
@DB
public NicProfile createPrivateNicProfileForGateway(final VpcGateway privateGateway, final VirtualRouter router) {
    final Network privateNetwork = _networkModel.getNetwork(privateGateway.getNetworkId());
    PrivateIpVO ipVO = _privateIpDao.allocateIpAddress(privateNetwork.getDataCenterId(), privateNetwork.getId(), privateGateway.getIp4Address());
    final Long vpcId = privateGateway.getVpcId();
    final Vpc activeVpc = _vpcMgr.getActiveVpc(vpcId);
    if (activeVpc.isRedundant() && ipVO == null) {
        ipVO = _privateIpDao.findByIpAndVpcId(vpcId, privateGateway.getIp4Address());
    }
    Nic privateNic = null;
    if (ipVO != null) {
        privateNic = _nicDao.findByIp4AddressAndNetworkId(ipVO.getIpAddress(), privateNetwork.getId());
    }
    NicProfile privateNicProfile = new NicProfile();
    if (privateNic != null) {
        privateNicProfile = new NicProfile(privateNic, privateNetwork, privateNic.getBroadcastUri(), privateNic.getIsolationUri(), _networkModel.getNetworkRate(privateNetwork.getId(), router.getId()), _networkModel.isSecurityGroupSupportedInNetwork(privateNetwork), _networkModel.getNetworkTag(router.getHypervisorType(), privateNetwork));
        if (router.getIsRedundantRouter()) {
            String newMacAddress = NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress(), NetworkModel.MACIdentifier.value()));
            privateNicProfile.setMacAddress(newMacAddress);
        }
    } else {
        final String netmask = NetUtils.getCidrNetmask(privateNetwork.getCidr());
        final PrivateIpAddress ip = new PrivateIpAddress(ipVO, privateNetwork.getBroadcastUri().toString(), privateNetwork.getGateway(), netmask, NetUtils.long2Mac(NetUtils.createSequenceBasedMacAddress(ipVO.getMacAddress(), NetworkModel.MACIdentifier.value())));
        final URI netUri = BroadcastDomainType.fromString(ip.getBroadcastUri());
        privateNicProfile.setIPv4Address(ip.getIpAddress());
        privateNicProfile.setIPv4Gateway(ip.getGateway());
        privateNicProfile.setIPv4Netmask(ip.getNetmask());
        privateNicProfile.setIsolationUri(netUri);
        privateNicProfile.setBroadcastUri(netUri);
        // can we solve this in setBroadcastUri()???
        // or more plugable construct is desirable
        privateNicProfile.setBroadcastType(BroadcastDomainType.getSchemeValue(netUri));
        privateNicProfile.setFormat(AddressFormat.Ip4);
        privateNicProfile.setReservationId(String.valueOf(ip.getBroadcastUri()));
        privateNicProfile.setMacAddress(ip.getMacAddress());
    }
    return privateNicProfile;
}
Also used : PrivateIpAddress(com.cloud.network.vpc.PrivateIpAddress) Network(com.cloud.network.Network) Vpc(com.cloud.network.vpc.Vpc) Nic(com.cloud.vm.Nic) PrivateIpVO(com.cloud.network.vpc.PrivateIpVO) NicProfile(com.cloud.vm.NicProfile) URI(java.net.URI) DB(com.cloud.utils.db.DB)

Aggregations

PrivateIpAddress (com.cloud.network.vpc.PrivateIpAddress)6 Network (com.cloud.network.Network)5 PrivateIpVO (com.cloud.network.vpc.PrivateIpVO)5 ArrayList (java.util.ArrayList)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)3 NicProfile (com.cloud.vm.NicProfile)3 Commands (com.cloud.agent.manager.Commands)2 DataCenter (com.cloud.dc.DataCenter)2 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)2 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)2 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)2 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 Nic (com.cloud.vm.Nic)2 HashMap (java.util.HashMap)2 ConfigurationException (javax.naming.ConfigurationException)2 Command (com.cloud.agent.api.Command)1 NetworkUsageCommand (com.cloud.agent.api.NetworkUsageCommand)1 PlugNicCommand (com.cloud.agent.api.PlugNicCommand)1 SetupGuestNetworkCommand (com.cloud.agent.api.SetupGuestNetworkCommand)1