Search in sources :

Example 1 with Route

use of com.att.cdp.zones.model.Route in project AJSC by att.

the class OpenStackNetworkService method createSubnet.

@Override
public Subnet createSubnet(Subnet subnet) throws ZoneException {
    connect();
    Context context = getContext();
    trackRequest();
    RequestState.put(RequestState.SUBNET, subnet.getName());
    RequestState.put(RequestState.SERVICE, "Network");
    RequestState.put(RequestState.SERVICE_URL, quantumConnector.getEndpoint());
    try {
        Quantum client = quantumConnector.getClient();
        com.woorea.openstack.quantum.model.Subnet subnetToCreate = new com.woorea.openstack.quantum.model.Subnet();
        subnetToCreate.setName(subnet.getName());
        subnetToCreate.setNetworkId(subnet.getNetwork());
        subnetToCreate.setCidr(subnet.getRouting());
        subnetToCreate.setGw(subnet.getGatewayIp());
        subnetToCreate.setEnableDHCP(subnet.isDhcp());
        subnetToCreate.setDnsNames(subnet.getDns());
        if (subnet.isIpv4()) {
            subnetToCreate.setIpversion(IpVersion.IPV4);
        } else {
            subnetToCreate.setIpversion(IpVersion.IPV6);
        }
        if (!subnet.getHostRoutes().isEmpty()) {
            List<com.woorea.openstack.quantum.model.Route> routesToCreate = new ArrayList<>();
            List<Route> routes = subnet.getHostRoutes();
            for (Route route : routes) {
                com.woorea.openstack.quantum.model.Route newRoute = new com.woorea.openstack.quantum.model.Route();
                newRoute.setDestination(route.getDestination());
                newRoute.setNexthop(route.getNexthop());
                routesToCreate.add(newRoute);
            }
            subnetToCreate.setHostRoutes(routesToCreate);
        }
        com.woorea.openstack.quantum.model.Subnet openstackSubnet = client.subnets().create(subnetToCreate).execute();
        return new OpenStackSubnet(context, openstackSubnet);
    } catch (OpenStackBaseException e) {
        ExceptionMapper.mapException(e);
    }
    return null;
}
Also used : Context(com.att.cdp.zones.Context) OpenStackContext(com.att.cdp.openstack.OpenStackContext) OpenStackBaseException(com.woorea.openstack.base.client.OpenStackBaseException) ArrayList(java.util.ArrayList) OpenStackSubnet(com.att.cdp.openstack.model.OpenStackSubnet) Quantum(com.woorea.openstack.quantum.Quantum) OpenStackSubnet(com.att.cdp.openstack.model.OpenStackSubnet) Subnet(com.att.cdp.zones.model.Subnet) Route(com.att.cdp.zones.model.Route)

Example 2 with Route

use of com.att.cdp.zones.model.Route in project AJSC by att.

the class TestNetworkService method createSubnetWithHostRoutes.

/**
 * Verifies that we can create a subnet with a specified set of host routes on a provider
 *
 * @throws ZoneException
 *             If the connection fails, user is not authorized, or the provider cannot perform the operation.
 */
@Test
@Ignore
public void createSubnetWithHostRoutes() throws ZoneException {
    Context context = connect();
    NetworkService service = context.getNetworkService();
    try {
        // verify test network exists
        verifyTestNetworkHelper();
        List<Network> networks = service.getNetworksByName("CDP_Test_Network");
        assertNotNull(networks);
        assertFalse(networks.isEmpty());
        Network testNetwork = networks.get(0);
        Subnet subnetWithGateway = new Subnet();
        subnetWithGateway.setName("CDP_Test_IPV4_Subnet_With_Host_Routes");
        subnetWithGateway.setNetwork(testNetwork.getId());
        subnetWithGateway.setIpv4(true);
        subnetWithGateway.setRouting("10.10.40.0/24");
        subnetWithGateway.setGatewayIp("10.10.40.1");
        List<Route> hostRoutes = new ArrayList<Route>();
        Route newRoute1 = new Route();
        Route newRoute2 = new Route();
        newRoute1.setDestination("10.10.10.0/24");
        newRoute1.setNexthop("10.10.20.1");
        newRoute2.setDestination("10.10.30.0/24");
        newRoute2.setNexthop("10.10.40.1");
        hostRoutes.add(newRoute1);
        hostRoutes.add(newRoute2);
        subnetWithGateway.setHostRoutes(hostRoutes);
        service.createSubnet(subnetWithGateway);
        List<Subnet> subnets = service.getSubnetsByName("CDP_Test_IPV4_Subnet_With_Host_Routes");
        assertFalse(subnets.isEmpty());
        for (Subnet subnet : subnets) {
            assertTrue(subnet.getRouting().equalsIgnoreCase("10.10.40.0/24"));
            assertTrue(subnet.getGatewayIp().equalsIgnoreCase("10.10.40.1"));
            assertFalse(subnet.getHostRoutes().isEmpty());
            assertTrue(subnet.getHostRoutes().contains(newRoute1));
            assertTrue(subnet.getHostRoutes().contains(newRoute2));
        }
    } catch (ZoneException ze) {
        ze.printStackTrace();
        fail("Failed to create the ipv4 test subnet with host routes");
    }
}
Also used : Context(com.att.cdp.zones.Context) ZoneException(com.att.cdp.exceptions.ZoneException) Network(com.att.cdp.zones.model.Network) ArrayList(java.util.ArrayList) NetworkService(com.att.cdp.zones.NetworkService) Subnet(com.att.cdp.zones.model.Subnet) Route(com.att.cdp.zones.model.Route) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Context (com.att.cdp.zones.Context)2 Route (com.att.cdp.zones.model.Route)2 Subnet (com.att.cdp.zones.model.Subnet)2 ArrayList (java.util.ArrayList)2 ZoneException (com.att.cdp.exceptions.ZoneException)1 OpenStackContext (com.att.cdp.openstack.OpenStackContext)1 OpenStackSubnet (com.att.cdp.openstack.model.OpenStackSubnet)1 NetworkService (com.att.cdp.zones.NetworkService)1 Network (com.att.cdp.zones.model.Network)1 OpenStackBaseException (com.woorea.openstack.base.client.OpenStackBaseException)1 Quantum (com.woorea.openstack.quantum.Quantum)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1