Search in sources :

Example 36 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class NuageVspGuestNetworkGuruTest method testDeallocate.

@Test
public void testDeallocate() throws Exception {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getUuid()).thenReturn("aaaaaa");
    when(network.getNetworkOfferingId()).thenReturn(NETWORK_ID);
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(network.getVpcId()).thenReturn(null);
    when(network.getDomainId()).thenReturn(NETWORK_ID);
    when(_networkDao.acquireInLockTable(NETWORK_ID, 1200)).thenReturn(network);
    final NetworkOfferingVO offering = mock(NetworkOfferingVO.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(_networkOfferingDao.findById(NETWORK_ID)).thenReturn(offering);
    final DomainVO domain = mock(DomainVO.class);
    when(domain.getUuid()).thenReturn("aaaaaa");
    when(_domainDao.findById(NETWORK_ID)).thenReturn(domain);
    final NicVO nic = mock(NicVO.class);
    when(nic.getId()).thenReturn(NETWORK_ID);
    when(nic.getIPv4Address()).thenReturn("10.10.10.10");
    when(nic.getMacAddress()).thenReturn("c8:60:00:56:e5:58");
    when(_nicDao.findById(NETWORK_ID)).thenReturn(nic);
    final NicProfile nicProfile = mock(NicProfile.class);
    when(nicProfile.getId()).thenReturn(NETWORK_ID);
    when(nicProfile.getIPv4Address()).thenReturn("10.10.10.10");
    when(nicProfile.getMacAddress()).thenReturn("c8:60:00:56:e5:58");
    final VirtualMachine vm = mock(VirtualMachine.class);
    when(vm.getType()).thenReturn(VirtualMachine.Type.User);
    when(vm.getState()).thenReturn(VirtualMachine.State.Expunging);
    final VirtualMachineProfile vmProfile = mock(VirtualMachineProfile.class);
    when(vmProfile.getUuid()).thenReturn("aaaaaa");
    when(vmProfile.getInstanceName()).thenReturn("Test-VM");
    when(vmProfile.getVirtualMachine()).thenReturn(vm);
    _nuageVspGuestNetworkGuru.deallocate(network, nicProfile, vmProfile);
}
Also used : DomainVO(com.cloud.domain.DomainVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) NicProfile(com.cloud.vm.NicProfile) VirtualMachineProfile(com.cloud.vm.VirtualMachineProfile) NicVO(com.cloud.vm.NicVO) VirtualMachine(com.cloud.vm.VirtualMachine) NuageTest(com.cloud.NuageTest) Test(org.junit.Test)

Example 37 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class NetworkHelperImpl method configureControlNic.

protected LinkedHashMap<Network, List<? extends NicProfile>> configureControlNic(final RouterDeploymentDefinition routerDeploymentDefinition) {
    final LinkedHashMap<Network, List<? extends NicProfile>> controlConfig = new LinkedHashMap<Network, List<? extends NicProfile>>(3);
    s_logger.debug("Adding nic for Virtual Router in Control network ");
    final List<? extends NetworkOffering> offerings = _networkModel.getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
    final NetworkOffering controlOffering = offerings.get(0);
    final Network controlNic = _networkMgr.setupNetwork(s_systemAccount, controlOffering, routerDeploymentDefinition.getPlan(), null, null, false).get(0);
    controlConfig.put(controlNic, new ArrayList<NicProfile>());
    return controlConfig;
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) LinkedHashMap(java.util.LinkedHashMap)

Example 38 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class NetworkHelperImpl method reallocateRouterNetworks.

@Override
public void reallocateRouterNetworks(final RouterDeploymentDefinition routerDeploymentDefinition, final VirtualRouter router, final VMTemplateVO template, final HypervisorType hType) throws ConcurrentOperationException, InsufficientCapacityException {
    final ServiceOfferingVO routerOffering = _serviceOfferingDao.findById(routerDeploymentDefinition.getServiceOfferingId());
    final LinkedHashMap<Network, List<? extends NicProfile>> networks = configureDefaultNics(routerDeploymentDefinition);
    _itMgr.allocate(router.getInstanceName(), template, routerOffering, networks, routerDeploymentDefinition.getPlan(), hType);
}
Also used : Network(com.cloud.network.Network) List(java.util.List) ArrayList(java.util.ArrayList) ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) NicProfile(com.cloud.vm.NicProfile) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO)

Example 39 with NicProfile

use of com.cloud.vm.NicProfile in project cloudstack by apache.

the class NicProfileHelperImpl method createGuestNicProfileForVpcRouter.

@Override
public NicProfile createGuestNicProfileForVpcRouter(final RouterDeploymentDefinition vpcRouterDeploymentDefinition, final Network guestNetwork) {
    final NicProfile guestNic = new NicProfile();
    if (vpcRouterDeploymentDefinition.isRedundant()) {
        guestNic.setIPv4Address(_ipAddrMgr.acquireGuestIpAddress(guestNetwork, null));
    } else {
        guestNic.setIPv4Address(guestNetwork.getGateway());
    }
    guestNic.setBroadcastUri(guestNetwork.getBroadcastUri());
    guestNic.setBroadcastType(guestNetwork.getBroadcastDomainType());
    guestNic.setIsolationUri(guestNetwork.getBroadcastUri());
    guestNic.setMode(guestNetwork.getMode());
    final String gatewayCidr = guestNetwork.getCidr();
    guestNic.setIPv4Netmask(NetUtils.getCidrNetmask(gatewayCidr));
    return guestNic;
}
Also used : NicProfile(com.cloud.vm.NicProfile)

Example 40 with NicProfile

use of com.cloud.vm.NicProfile 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

NicProfile (com.cloud.vm.NicProfile)84 Network (com.cloud.network.Network)31 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)28 NetworkVO (com.cloud.network.dao.NetworkVO)27 ArrayList (java.util.ArrayList)23 DataCenterVO (com.cloud.dc.DataCenterVO)19 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)18 DomainRouterVO (com.cloud.vm.DomainRouterVO)16 NicVO (com.cloud.vm.NicVO)14 List (java.util.List)14 DataCenter (com.cloud.dc.DataCenter)13 NetworkOffering (com.cloud.offering.NetworkOffering)12 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)11 NetworkGuru (com.cloud.network.guru.NetworkGuru)11 LinkedHashMap (java.util.LinkedHashMap)11 Provider (com.cloud.network.Network.Provider)10 Nic (com.cloud.vm.Nic)10 ReservationContext (com.cloud.vm.ReservationContext)10 VirtualMachineProfile (com.cloud.vm.VirtualMachineProfile)10 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)9