Search in sources :

Example 6 with NetworkProfile

use of com.cloud.network.NetworkProfile in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createNetworkResponse.

@Override
public NetworkResponse createNetworkResponse(final ResponseView view, final Network network) {
    // need to get network profile in order to retrieve dns information from
    // there
    final NetworkProfile profile = ApiDBUtils.getNetworkProfile(network.getId());
    final NetworkResponse response = new NetworkResponse();
    response.setId(network.getUuid());
    response.setName(network.getName());
    response.setDisplaytext(network.getDisplayText());
    if (network.getBroadcastDomainType() != null) {
        response.setBroadcastDomainType(network.getBroadcastDomainType().toString());
    }
    if (network.getTrafficType() != null) {
        response.setTrafficType(network.getTrafficType().name());
    }
    if (network.getGuestType() != null) {
        response.setType(network.getGuestType().toString());
    }
    response.setGateway(network.getGateway());
    // FIXME - either set netmask or cidr
    response.setCidr(network.getCidr());
    response.setNetworkCidr(network.getNetworkCidr());
    // network cidr
    if (network.getNetworkCidr() != null) {
        response.setNetmask(NetUtils.cidr2Netmask(network.getNetworkCidr()));
    }
    if (network.getCidr() != null && network.getNetworkCidr() == null) {
        response.setNetmask(NetUtils.cidr2Netmask(network.getCidr()));
    }
    response.setIpExclusionList(((NetworkVO) network).getIpExclusionList());
    response.setIp6Gateway(network.getIp6Gateway());
    response.setIp6Cidr(network.getIp6Cidr());
    // create response for reserved IP ranges that can be used for
    // non-cloudstack purposes
    String reservation = null;
    if (network.getCidr() != null && NetUtils.isNetworkAWithinNetworkB(network.getCidr(), network.getNetworkCidr())) {
        final String[] guestVmCidrPair = network.getCidr().split("\\/");
        final String[] guestCidrPair = network.getNetworkCidr().split("\\/");
        final Long guestVmCidrSize = Long.valueOf(guestVmCidrPair[1]);
        final Long guestCidrSize = Long.valueOf(guestCidrPair[1]);
        final String[] guestVmIpRange = NetUtils.getIpRangeFromCidr(guestVmCidrPair[0], guestVmCidrSize);
        final String[] guestIpRange = NetUtils.getIpRangeFromCidr(guestCidrPair[0], guestCidrSize);
        final long startGuestIp = NetUtils.ip2Long(guestIpRange[0]);
        final long endGuestIp = NetUtils.ip2Long(guestIpRange[1]);
        final long startVmIp = NetUtils.ip2Long(guestVmIpRange[0]);
        final long endVmIp = NetUtils.ip2Long(guestVmIpRange[1]);
        if (startVmIp == startGuestIp && endVmIp < endGuestIp - 1) {
            reservation = NetUtils.long2Ip(endVmIp + 1) + "-" + NetUtils.long2Ip(endGuestIp);
        }
        if (endVmIp == endGuestIp && startVmIp > startGuestIp + 1) {
            reservation = NetUtils.long2Ip(startGuestIp) + "-" + NetUtils.long2Ip(startVmIp - 1);
        }
        if (startVmIp > startGuestIp + 1 && endVmIp < endGuestIp - 1) {
            reservation = NetUtils.long2Ip(startGuestIp) + "-" + NetUtils.long2Ip(startVmIp - 1) + " ,  " + NetUtils.long2Ip(endVmIp + 1) + "-" + NetUtils.long2Ip(endGuestIp);
        }
    }
    response.setReservedIpRange(reservation);
    if (network.getBroadcastUri() != null) {
        final String broadcastUri = network.getBroadcastUri().toString();
        response.setBroadcastUri(broadcastUri);
        String vlan = "N/A";
        switch(BroadcastDomainType.getSchemeValue(network.getBroadcastUri())) {
            case Vlan:
            case Vxlan:
                vlan = BroadcastDomainType.getValue(network.getBroadcastUri());
                break;
        }
        response.setVlan(vlan);
    }
    final DataCenter zone = ApiDBUtils.findZoneById(network.getDataCenterId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    if (network.getPhysicalNetworkId() != null) {
        final PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(network.getPhysicalNetworkId());
        response.setPhysicalNetworkId(pnet.getUuid());
    }
    // populate network offering information
    final NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
    if (networkOffering != null) {
        response.setNetworkOfferingId(networkOffering.getUuid());
        response.setNetworkOfferingName(networkOffering.getName());
        response.setNetworkOfferingDisplayText(networkOffering.getDisplayText());
        response.setNetworkOfferingConserveMode(networkOffering.isConserveMode());
        response.setIsSystem(networkOffering.isSystemOnly());
        response.setNetworkOfferingAvailability(networkOffering.getAvailability().toString());
        response.setIsPersistent(networkOffering.getIsPersistent());
    }
    if (network.getAclType() != null) {
        response.setAclType(network.getAclType().toString());
    }
    response.setDisplayNetwork(network.getDisplayNetwork());
    response.setState(network.getState().toString());
    response.setRestartRequired(network.isRestartRequired());
    final NetworkVO nw = ApiDBUtils.findNetworkById(network.getRelated());
    if (nw != null) {
        response.setRelated(nw.getUuid());
    }
    response.setNetworkDomain(network.getNetworkDomain());
    response.setDns1(profile.getDns1());
    response.setDns2(profile.getDns2());
    // populate capability
    final Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(network.getId(), network.getDataCenterId());
    final List<ServiceResponse> serviceResponses = new ArrayList<>();
    if (serviceCapabilitiesMap != null) {
        for (final Map.Entry<Service, Map<Capability, String>> entry : serviceCapabilitiesMap.entrySet()) {
            final Service service = entry.getKey();
            final ServiceResponse serviceResponse = new ServiceResponse();
            // skip gateway service
            if (service == Service.Gateway) {
                continue;
            }
            serviceResponse.setName(service.getName());
            // set list of capabilities for the service
            final List<CapabilityResponse> capabilityResponses = new ArrayList<>();
            final Map<Capability, String> serviceCapabilities = entry.getValue();
            if (serviceCapabilities != null) {
                for (final Map.Entry<Capability, String> ser_cap_entries : serviceCapabilities.entrySet()) {
                    final Capability capability = ser_cap_entries.getKey();
                    final CapabilityResponse capabilityResponse = new CapabilityResponse();
                    final String capabilityValue = ser_cap_entries.getValue();
                    capabilityResponse.setName(capability.getName());
                    capabilityResponse.setValue(capabilityValue);
                    capabilityResponse.setObjectName("capability");
                    capabilityResponses.add(capabilityResponse);
                }
                serviceResponse.setCapabilities(capabilityResponses);
            }
            serviceResponse.setObjectName("service");
            serviceResponses.add(serviceResponse);
        }
    }
    response.setServices(serviceResponses);
    if (network.getAclType() == null || network.getAclType() == ACLType.Account) {
        populateOwner(response, network);
    } else {
        // get domain from network_domain table
        final Pair<Long, Boolean> domainNetworkDetails = ApiDBUtils.getDomainNetworkDetails(network.getId());
        if (domainNetworkDetails.first() != null) {
            final Domain domain = ApiDBUtils.findDomainById(domainNetworkDetails.first());
            if (domain != null) {
                response.setDomainId(domain.getUuid());
            }
        }
        response.setSubdomainAccess(domainNetworkDetails.second());
    }
    final Long dedicatedDomainId = ApiDBUtils.getDedicatedNetworkDomain(network.getId());
    if (dedicatedDomainId != null) {
        final Domain domain = ApiDBUtils.findDomainById(dedicatedDomainId);
        if (domain != null) {
            response.setDomainId(domain.getUuid());
            response.setDomainName(domain.getName());
        }
    }
    response.setSpecifyIpRanges(network.getSpecifyIpRanges());
    if (network.getVpcId() != null) {
        final Vpc vpc = ApiDBUtils.findVpcById(network.getVpcId());
        if (vpc != null) {
            response.setVpcId(vpc.getUuid());
            response.setVpcName(vpc.getName());
        }
    }
    response.setCanUseForDeploy(ApiDBUtils.canUseForDeploy(network));
    // set tag information
    final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Network, network.getId());
    final List<ResourceTagResponse> tagResponses = new ArrayList<>();
    for (final ResourceTag tag : tags) {
        final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    if (network.getNetworkACLId() != null) {
        final NetworkACL acl = ApiDBUtils.findByNetworkACLId(network.getNetworkACLId());
        if (acl != null) {
            response.setAclId(acl.getUuid());
            response.setAclName(acl.getName());
        }
    }
    response.setStrechedL2Subnet(network.isStrechedL2Network());
    if (network.isStrechedL2Network()) {
        final Set<String> networkSpannedZones = new HashSet<>();
        final List<VMInstanceVO> vmInstances = new ArrayList<>();
        vmInstances.addAll(ApiDBUtils.listUserVMsByNetworkId(network.getId()));
        vmInstances.addAll(ApiDBUtils.listDomainRoutersByNetworkId(network.getId()));
        for (final VirtualMachine vm : vmInstances) {
            final DataCenter vmZone = ApiDBUtils.findZoneById(vm.getDataCenterId());
            networkSpannedZones.add(vmZone.getUuid());
        }
        response.setNetworkSpannedZones(networkSpannedZones);
    }
    response.setObjectName("network");
    return response;
}
Also used : ArrayList(java.util.ArrayList) Vpc(com.cloud.network.vpc.Vpc) NetworkACL(com.cloud.network.vpc.NetworkACL) CapabilityResponse(com.cloud.api.response.CapabilityResponse) ServiceResponse(com.cloud.api.response.ServiceResponse) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) HashSet(java.util.HashSet) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) Capability(com.cloud.network.Network.Capability) NetworkOffering(com.cloud.offering.NetworkOffering) Service(com.cloud.network.Network.Service) VMInstanceVO(com.cloud.vm.VMInstanceVO) NetworkProfile(com.cloud.network.NetworkProfile) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) NetworkResponse(com.cloud.api.response.NetworkResponse) PhysicalNetworkResponse(com.cloud.api.response.PhysicalNetworkResponse) Domain(com.cloud.domain.Domain) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.vm.VirtualMachine)

Example 7 with NetworkProfile

use of com.cloud.network.NetworkProfile in project cosmic by MissionCriticalCloud.

the class NiciraNvpGuestNetworkGuruTest method testShutdown.

@Test
public void testShutdown() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT", "VXLAN" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(Network.State.Implementing);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(netdao.findById(NETWORK_ID)).thenReturn(network);
    final DeployDestination dest = mock(DeployDestination.class);
    final Zone zone = mock(Zone.class);
    when(dest.getZone()).thenReturn(zone);
    final HostVO niciraHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(niciraHost);
    when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
    when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
    when(niciraHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final DeleteLogicalSwitchAnswer answer = mock(DeleteLogicalSwitchAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final NetworkProfile implementednetwork = mock(NetworkProfile.class);
    when(implementednetwork.getId()).thenReturn(NETWORK_ID);
    when(implementednetwork.getBroadcastUri()).thenReturn(new URI("lswitch:aaaa"));
    when(offering.getSpecifyVlan()).thenReturn(false);
    guru.shutdown(implementednetwork, offering);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
    verify(implementednetwork, times(1)).setBroadcastUri(null);
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) Zone(com.cloud.db.model.Zone) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) NetworkProfile(com.cloud.network.NetworkProfile) DeployDestination(com.cloud.deploy.DeployDestination) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeleteLogicalSwitchAnswer(com.cloud.agent.api.DeleteLogicalSwitchAnswer) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 8 with NetworkProfile

use of com.cloud.network.NetworkProfile in project cosmic by MissionCriticalCloud.

the class NetworkOrchestrator method shutdownNetwork.

@Override
@DB
public boolean shutdownNetwork(final long networkId, final ReservationContext context, final boolean cleanupElements) {
    NetworkVO network = _networksDao.findById(networkId);
    if (network.getState() == Network.State.Allocated) {
        s_logger.debug("Network is already shutdown: " + network);
        return true;
    }
    if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) {
        s_logger.debug("Network is not implemented: " + network);
        return false;
    }
    try {
        // do global lock for the network
        network = _networksDao.acquireInLockTable(networkId, NetworkLockTimeout.value());
        if (network == null) {
            s_logger.warn("Unable to acquire lock for the network as a part of network shutdown");
            return false;
        }
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Lock is acquired for network " + network + " as a part of network shutdown");
        }
        if (network.getState() == Network.State.Allocated) {
            s_logger.debug("Network is already shutdown: " + network);
            return true;
        }
        if (network.getState() != Network.State.Implemented && network.getState() != Network.State.Shutdown) {
            s_logger.debug("Network is not implemented: " + network);
            return false;
        }
        if (isSharedNetworkWithServices(network)) {
            network.setState(Network.State.Shutdown);
            _networksDao.update(network.getId(), network);
        } else {
            try {
                stateTransitTo(network, Event.DestroyNetwork);
            } catch (final NoTransitionException e) {
                network.setState(Network.State.Shutdown);
                _networksDao.update(network.getId(), network);
            }
        }
        final boolean success = shutdownNetworkElementsAndResources(context, cleanupElements, network);
        final NetworkVO networkFinal = network;
        final boolean result = Transaction.execute(new TransactionCallback<Boolean>() {

            @Override
            public Boolean doInTransaction(final TransactionStatus status) {
                boolean result = false;
                if (success) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Network id=" + networkId + " is shutdown successfully, cleaning up corresponding resources now.");
                    }
                    final NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, networkFinal.getGuruName());
                    final NetworkProfile profile = convertNetworkToNetworkProfile(networkFinal.getId());
                    guru.shutdown(profile, _networkOfferingDao.findById(networkFinal.getNetworkOfferingId()));
                    applyProfileToNetwork(networkFinal, profile);
                    final Zone zone = _zoneRepository.findOne(networkFinal.getDataCenterId());
                    if (isSharedNetworkOfferingWithServices(networkFinal.getNetworkOfferingId()) && zone.getNetworkType() == com.cloud.model.enumeration.NetworkType.Advanced) {
                        networkFinal.setState(Network.State.Setup);
                    } else {
                        try {
                            stateTransitTo(networkFinal, Event.OperationSucceeded);
                        } catch (final NoTransitionException e) {
                            networkFinal.setState(Network.State.Allocated);
                            networkFinal.setRestartRequired(false);
                        }
                    }
                    _networksDao.update(networkFinal.getId(), networkFinal);
                    _networksDao.clearCheckForGc(networkId);
                    result = true;
                } else {
                    try {
                        stateTransitTo(networkFinal, Event.OperationFailed);
                    } catch (final NoTransitionException e) {
                        networkFinal.setState(Network.State.Implemented);
                        _networksDao.update(networkFinal.getId(), networkFinal);
                    }
                    result = false;
                }
                return result;
            }
        });
        return result;
    } finally {
        if (network != null) {
            _networksDao.releaseFromLockTable(network.getId());
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Lock is released for network " + network + " as a part of network shutdown");
            }
        }
    }
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkProfile(com.cloud.network.NetworkProfile) Zone(com.cloud.db.model.Zone) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) NetworkGuru(com.cloud.network.guru.NetworkGuru) TransactionStatus(com.cloud.utils.db.TransactionStatus) DB(com.cloud.utils.db.DB)

Example 9 with NetworkProfile

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

the class NiciraNvpGuestNetworkGuruTest method testShutdown.

@Test
public void testShutdown() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "STT", "VXLAN" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
    when(nvpdao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] { device }));
    when(device.getId()).thenReturn(1L);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(false);
    mock(DeploymentPlan.class);
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
    when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
    when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
    when(netdao.findById(NETWORK_ID)).thenReturn(network);
    final DeployDestination dest = mock(DeployDestination.class);
    final DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    final HostVO niciraHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(niciraHost);
    when(niciraHost.getDetail("transportzoneuuid")).thenReturn("aaaa");
    when(niciraHost.getDetail("transportzoneisotype")).thenReturn("stt");
    when(niciraHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    final Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    final ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    final DeleteLogicalSwitchAnswer answer = mock(DeleteLogicalSwitchAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    final NetworkProfile implementednetwork = mock(NetworkProfile.class);
    when(implementednetwork.getId()).thenReturn(NETWORK_ID);
    when(implementednetwork.getBroadcastUri()).thenReturn(new URI("lswitch:aaaa"));
    when(offering.isSpecifyVlan()).thenReturn(false);
    guru.shutdown(implementednetwork, offering);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
    verify(implementednetwork, times(1)).setBroadcastUri(null);
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) NiciraNvpDeviceVO(com.cloud.network.NiciraNvpDeviceVO) URI(java.net.URI) HostVO(com.cloud.host.HostVO) ReservationContext(com.cloud.vm.ReservationContext) NetworkProfile(com.cloud.network.NetworkProfile) DataCenter(com.cloud.dc.DataCenter) DeployDestination(com.cloud.deploy.DeployDestination) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeleteLogicalSwitchAnswer(com.cloud.agent.api.DeleteLogicalSwitchAnswer) Domain(com.cloud.domain.Domain) Test(org.junit.Test)

Example 10 with NetworkProfile

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

the class VxlanGuestNetworkGuruTest method testShutdown.

@Test
public void testShutdown() throws InsufficientVirtualNetworkCapacityException, URISyntaxException {
    PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById(anyLong())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VXLAN" }));
    when(physnet.getId()).thenReturn(42L);
    NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(42L);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Vxlan);
    when(network.getBroadcastUri()).thenReturn(new URI("vxlan:12345"));
    when(network.getPhysicalNetworkId()).thenReturn(42L);
    when(netdao.findById(42L)).thenReturn(network);
    DeployDestination dest = mock(DeployDestination.class);
    DataCenter dc = mock(DataCenter.class);
    when(dest.getDataCenter()).thenReturn(dc);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(42L);
    Domain dom = mock(Domain.class);
    when(dom.getName()).thenReturn("domain");
    Account acc = mock(Account.class);
    when(acc.getAccountName()).thenReturn("accountname");
    ReservationContext res = mock(ReservationContext.class);
    when(res.getDomain()).thenReturn(dom);
    when(res.getAccount()).thenReturn(acc);
    NetworkProfile implementednetwork = mock(NetworkProfile.class);
    when(implementednetwork.getId()).thenReturn(42L);
    when(implementednetwork.getBroadcastUri()).thenReturn(new URI("vxlan:12345"));
    when(offering.isSpecifyVlan()).thenReturn(false);
    guru.shutdown(implementednetwork, offering);
    verify(implementednetwork, times(1)).setBroadcastUri(null);
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkProfile(com.cloud.network.NetworkProfile) DataCenter(com.cloud.dc.DataCenter) NetworkOffering(com.cloud.offering.NetworkOffering) DeployDestination(com.cloud.deploy.DeployDestination) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Domain(com.cloud.domain.Domain) URI(java.net.URI) ReservationContext(com.cloud.vm.ReservationContext) Test(org.junit.Test)

Aggregations

NetworkProfile (com.cloud.network.NetworkProfile)10 NetworkVO (com.cloud.network.dao.NetworkVO)10 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)10 Domain (com.cloud.domain.Domain)5 NetworkGuru (com.cloud.network.guru.NetworkGuru)5 NetworkOffering (com.cloud.offering.NetworkOffering)5 DataCenter (com.cloud.dc.DataCenter)4 DeployDestination (com.cloud.deploy.DeployDestination)3 Account (com.cloud.user.Account)3 DB (com.cloud.utils.db.DB)3 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)3 ReservationContext (com.cloud.vm.ReservationContext)3 URI (java.net.URI)3 Test (org.junit.Test)3 DeleteLogicalSwitchAnswer (com.cloud.agent.api.DeleteLogicalSwitchAnswer)2 Zone (com.cloud.db.model.Zone)2 HostVO (com.cloud.host.HostVO)2 Capability (com.cloud.network.Network.Capability)2 Service (com.cloud.network.Network.Service)2 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)2