Search in sources :

Example 36 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testDesignNoConnectivityInOffering.

@Test
public void testDesignNoConnectivityInOffering() {
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnetdao.findById((Long) any())).thenReturn(physnet);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VCS" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    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);
    final DeploymentPlan plan = mock(DeploymentPlan.class);
    final Network network = mock(Network.class);
    final Account account = mock(Account.class);
    final Network designednetwork = guru.design(offering, plan, network, account);
    assertTrue(designednetwork == null);
}
Also used : Account(com.cloud.user.Account) NetworkOffering(com.cloud.offering.NetworkOffering) Network(com.cloud.network.Network) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) DeploymentPlan(com.cloud.deploy.DeploymentPlan) Test(org.junit.Test)

Example 37 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testTrashFail.

@Test
public void testTrashFail() {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    final HostVO brocadeHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
    when(brocadeHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final BrocadeVcsNetworkVlanMappingVO mapping = mock(BrocadeVcsNetworkVlanMappingVO.class);
    when(mapping.getVlanId()).thenReturn(14);
    when(vcsmapdao.findByNetworkId(anyLong())).thenReturn(mapping);
    when(vcsmapdao.remove(anyLong())).thenReturn(true);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    final List<BrocadeVcsDeviceVO> devices = mock(List.class);
    when(devices.isEmpty()).thenReturn(true);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final boolean result = guru.trash(network, offering);
    assertTrue(result == false);
    verify(agentmgr, times(0)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) BrocadeVcsNetworkVlanMappingVO(com.cloud.network.BrocadeVcsNetworkVlanMappingVO) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) Test(org.junit.Test)

Example 38 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testCanHandle.

@Test
public void testCanHandle() {
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    final PhysicalNetworkVO physnet = mock(PhysicalNetworkVO.class);
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VCS" }));
    when(physnet.getId()).thenReturn(NETWORK_ID);
    when(nosd.areServicesSupportedByNetworkOffering(NETWORK_ID, Service.Connectivity)).thenReturn(true);
    assertTrue(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
    // Not supported TrafficType != Guest
    when(offering.getTrafficType()).thenReturn(TrafficType.Management);
    assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
    // Not supported: GuestType Shared
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Shared);
    assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
    // Not supported: Basic networking
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    assertFalse(guru.canHandle(offering, NetworkType.Basic, physnet) == true);
    // Not supported: IsolationMethod != VCS
    when(physnet.getIsolationMethods()).thenReturn(Arrays.asList(new String[] { "VLAN" }));
    assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) Test(org.junit.Test)

Example 39 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class BrocadeVcsGuestNetworkGuruTest method testTrash.

@Test
public void testTrash() {
    final NetworkVO network = mock(NetworkVO.class);
    when(network.getName()).thenReturn("testnetwork");
    when(network.getState()).thenReturn(State.Implementing);
    when(network.getId()).thenReturn(NETWORK_ID);
    when(network.getDataCenterId()).thenReturn(NETWORK_ID);
    final NetworkOffering offering = mock(NetworkOffering.class);
    when(offering.getId()).thenReturn(NETWORK_ID);
    when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
    when(offering.getGuestType()).thenReturn(GuestType.Isolated);
    final HostVO brocadeHost = mock(HostVO.class);
    when(hostdao.findById(anyLong())).thenReturn(brocadeHost);
    when(brocadeHost.getId()).thenReturn(NETWORK_ID);
    when(netmodel.findPhysicalNetworkId(anyLong(), (String) any(), (TrafficType) any())).thenReturn(NETWORK_ID);
    final BrocadeVcsNetworkVlanMappingVO mapping = mock(BrocadeVcsNetworkVlanMappingVO.class);
    when(mapping.getVlanId()).thenReturn(14);
    when(vcsmapdao.findByNetworkId(anyLong())).thenReturn(mapping);
    final BrocadeVcsDeviceVO brocadeDevice = mock(BrocadeVcsDeviceVO.class);
    when(brocadeDevice.getHostId()).thenReturn(NETWORK_ID);
    final List<BrocadeVcsDeviceVO> devices = new ArrayList();
    devices.add(brocadeDevice);
    when(vcsdao.listByPhysicalNetwork(anyLong())).thenReturn(devices);
    final DeleteNetworkAnswer answer = mock(DeleteNetworkAnswer.class);
    when(answer.getResult()).thenReturn(true);
    when(agentmgr.easySend(eq(NETWORK_ID), (Command) any())).thenReturn(answer);
    when(vcsdao.remove((long) anyInt())).thenReturn(true);
    final boolean result = guru.trash(network, offering);
    assertTrue(result == true);
    verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command) any());
}
Also used : PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) DeleteNetworkAnswer(com.cloud.agent.api.DeleteNetworkAnswer) NetworkOffering(com.cloud.offering.NetworkOffering) BrocadeVcsNetworkVlanMappingVO(com.cloud.network.BrocadeVcsNetworkVlanMappingVO) ArrayList(java.util.ArrayList) HostVO(com.cloud.host.HostVO) BrocadeVcsDeviceVO(com.cloud.network.BrocadeVcsDeviceVO) Test(org.junit.Test)

Example 40 with NetworkOffering

use of com.cloud.offering.NetworkOffering in project cloudstack by apache.

the class ApiResponseHelper method createNetworkResponse.

@Override
public NetworkResponse createNetworkResponse(ResponseView view, Network network) {
    // need to get network profile in order to retrieve dns information from
    // there
    NetworkProfile profile = ApiDBUtils.getNetworkProfile(network.getId());
    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.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()))) {
        String[] guestVmCidrPair = network.getCidr().split("\\/");
        String[] guestCidrPair = network.getNetworkCidr().split("\\/");
        Long guestVmCidrSize = Long.valueOf(guestVmCidrPair[1]);
        Long guestCidrSize = Long.valueOf(guestCidrPair[1]);
        String[] guestVmIpRange = NetUtils.getIpRangeFromCidr(guestVmCidrPair[0], guestVmCidrSize);
        String[] guestIpRange = NetUtils.getIpRangeFromCidr(guestCidrPair[0], guestCidrSize);
        long startGuestIp = NetUtils.ip2Long(guestIpRange[0]);
        long endGuestIp = NetUtils.ip2Long(guestIpRange[1]);
        long startVmIp = NetUtils.ip2Long(guestVmIpRange[0]);
        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);
    // return vlan information only to Root admin
    if (network.getBroadcastUri() != null && view == ResponseView.Full) {
        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;
        }
        // return vlan information only to Root admin
        response.setVlan(vlan);
    }
    DataCenter zone = ApiDBUtils.findZoneById(network.getDataCenterId());
    if (zone != null) {
        response.setZoneId(zone.getUuid());
        response.setZoneName(zone.getName());
    }
    if (network.getPhysicalNetworkId() != null) {
        PhysicalNetworkVO pnet = ApiDBUtils.findPhysicalNetworkById(network.getPhysicalNetworkId());
        response.setPhysicalNetworkId(pnet.getUuid());
    }
    // populate network offering information
    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());
    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
    Map<Service, Map<Capability, String>> serviceCapabilitiesMap = ApiDBUtils.getNetworkCapabilities(network.getId(), network.getDataCenterId());
    List<ServiceResponse> serviceResponses = new ArrayList<ServiceResponse>();
    if (serviceCapabilitiesMap != null) {
        for (Map.Entry<Service, Map<Capability, String>> entry : serviceCapabilitiesMap.entrySet()) {
            Service service = entry.getKey();
            ServiceResponse serviceResponse = new ServiceResponse();
            // skip gateway service
            if (service == Service.Gateway) {
                continue;
            }
            serviceResponse.setName(service.getName());
            // set list of capabilities for the service
            List<CapabilityResponse> capabilityResponses = new ArrayList<CapabilityResponse>();
            Map<Capability, String> serviceCapabilities = entry.getValue();
            if (serviceCapabilities != null) {
                for (Map.Entry<Capability, String> ser_cap_entries : serviceCapabilities.entrySet()) {
                    Capability capability = ser_cap_entries.getKey();
                    CapabilityResponse capabilityResponse = new CapabilityResponse();
                    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
        Pair<Long, Boolean> domainNetworkDetails = ApiDBUtils.getDomainNetworkDetails(network.getId());
        if (domainNetworkDetails.first() != null) {
            Domain domain = ApiDBUtils.findDomainById(domainNetworkDetails.first());
            if (domain != null) {
                response.setDomainId(domain.getUuid());
            }
        }
        response.setSubdomainAccess(domainNetworkDetails.second());
    }
    Long dedicatedDomainId = ApiDBUtils.getDedicatedNetworkDomain(network.getId());
    if (dedicatedDomainId != null) {
        Domain domain = ApiDBUtils.findDomainById(dedicatedDomainId);
        if (domain != null) {
            response.setDomainId(domain.getUuid());
            response.setDomainName(domain.getName());
        }
    }
    response.setSpecifyIpRanges(network.getSpecifyIpRanges());
    if (network.getVpcId() != null) {
        Vpc vpc = ApiDBUtils.findVpcById(network.getVpcId());
        if (vpc != null) {
            response.setVpcId(vpc.getUuid());
        }
    }
    response.setCanUseForDeploy(ApiDBUtils.canUseForDeploy(network));
    // set tag information
    List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Network, network.getId());
    List<ResourceTagResponse> tagResponses = new ArrayList<ResourceTagResponse>();
    for (ResourceTag tag : tags) {
        ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
        CollectionUtils.addIgnoreNull(tagResponses, tagResponse);
    }
    response.setTags(tagResponses);
    if (network.getNetworkACLId() != null) {
        NetworkACL acl = ApiDBUtils.findByNetworkACLId(network.getNetworkACLId());
        if (acl != null) {
            response.setAclId(acl.getUuid());
        }
    }
    response.setStrechedL2Subnet(network.isStrechedL2Network());
    if (network.isStrechedL2Network()) {
        Set<String> networkSpannedZones = new HashSet<String>();
        List<VMInstanceVO> vmInstances = new ArrayList<VMInstanceVO>();
        vmInstances.addAll(ApiDBUtils.listUserVMsByNetworkId(network.getId()));
        vmInstances.addAll(ApiDBUtils.listDomainRoutersByNetworkId(network.getId()));
        for (VirtualMachine vm : vmInstances) {
            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(org.apache.cloudstack.api.response.CapabilityResponse) ServiceResponse(org.apache.cloudstack.api.response.ServiceResponse) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) ResourceTagResponse(org.apache.cloudstack.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) UsageService(org.apache.cloudstack.usage.UsageService) VMInstanceVO(com.cloud.vm.VMInstanceVO) NetworkProfile(com.cloud.network.NetworkProfile) DataCenter(com.cloud.dc.DataCenter) ResourceTag(com.cloud.server.ResourceTag) NetworkResponse(org.apache.cloudstack.api.response.NetworkResponse) PhysicalNetworkResponse(org.apache.cloudstack.api.response.PhysicalNetworkResponse) Domain(com.cloud.domain.Domain) Map(java.util.Map) HashMap(java.util.HashMap) VirtualMachine(com.cloud.vm.VirtualMachine)

Aggregations

NetworkOffering (com.cloud.offering.NetworkOffering)94 Network (com.cloud.network.Network)51 Account (com.cloud.user.Account)41 Test (org.junit.Test)34 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)27 ArrayList (java.util.ArrayList)24 DataCenter (com.cloud.dc.DataCenter)23 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)23 NetworkVO (com.cloud.network.dao.NetworkVO)22 DeployDestination (com.cloud.deploy.DeployDestination)18 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)18 HostVO (com.cloud.host.HostVO)17 ReservationContext (com.cloud.vm.ReservationContext)17 Domain (com.cloud.domain.Domain)16 IPAddressVO (com.cloud.network.dao.IPAddressVO)13 List (java.util.List)13 NicProfile (com.cloud.vm.NicProfile)12 DeploymentPlan (com.cloud.deploy.DeploymentPlan)11 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)11 NiciraNvpDeviceVO (com.cloud.network.NiciraNvpDeviceVO)11