Search in sources :

Example 1 with RouterInterface

use of org.openstack4j.model.network.RouterInterface in project airavata by apache.

the class OpenstackIntfImpl method createRouterSubnetInterface.

@Override
public Object createRouterSubnetInterface(String routerName, String subnetName) {
    String subnetId = null, routerId = null;
    RouterInterface iface = null;
    try {
        // get subnetid from name
        for (Subnet subnet : os.networking().subnet().list()) {
            if (subnet.getName().equals(subnetName)) {
                subnetId = subnet.getId();
            }
        }
        // get routerid from name
        for (Router router : os.networking().router().list()) {
            if (router.getName().equals(routerName)) {
                routerId = router.getId();
            }
        }
        if (routerId != null && subnetId != null) {
            // attach external interface to gateway
            iface = os.networking().router().attachInterface(routerId, AttachInterfaceType.SUBNET, subnetId);
            logger.info("Attached external interface to router : " + iface);
        } else {
            logger.error("Either router or network is not found. Kindly re-check and try again.");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
        // TODO: Check with the team on how to handle exceptions.
        logger.error("Failed to create subnet-router interface. Exception: " + ex.getMessage(), ex);
    }
    return iface;
}
Also used : RouterInterface(org.openstack4j.model.network.RouterInterface) Router(org.openstack4j.model.network.Router) Subnet(org.openstack4j.model.network.Subnet) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with RouterInterface

use of org.openstack4j.model.network.RouterInterface in project airavata by apache.

the class CloudIntfTest method jetstreamCreateDeleteNetworkTest.

/**
 * Jetstream create delete network test.
 */
@Test
@Ignore
public void jetstreamCreateDeleteNetworkTest() {
    try {
        CloudInterface cloudIntf = new OpenstackIntfImpl("jetstream_openrc.properties");
        /* fetch sample data from properties file */
        String networkName = properties.getProperty("jetstream_network_name");
        String subnetCIDR = properties.getProperty("jetstream_subnet_cidr");
        Integer ipVersion = Integer.valueOf(properties.getProperty("jetstream_ip_version", Constants.OS_IP_VERSION_DEFAULT.toString()));
        String externalGateway = properties.getProperty("jetstream_public_network_name");
        /* build router and subnet names */
        String subnetName = "subnet-" + networkName;
        String routerName = "router-" + networkName;
        /*  create network */
        logger.info("Creating network with name = " + networkName);
        Network network = (Network) cloudIntf.createNetwork(networkName);
        assertTrue(network != null && network.getName().equals(networkName));
        /* create subnet for network */
        logger.info("Creating subnet with name = " + subnetName + ", and CIDR = " + subnetCIDR + ", and version = " + ipVersion);
        Subnet subnet = (Subnet) cloudIntf.createSubnet(subnetName, networkName, subnetCIDR, ipVersion);
        assertTrue(subnet != null && subnet.getName().equals(subnetName) && subnet.getCidr().equals(subnetCIDR) && subnet.getIpVersion().getVersion() == ipVersion.intValue());
        /* create router for external gateway */
        logger.info("Creating router with name = " + routerName + ", and external gateway = " + externalGateway);
        Router router = (Router) cloudIntf.createRouter(routerName, externalGateway);
        assertTrue(router != null && router.getName().equals(routerName));
        /* create router-subnet interface */
        logger.info("Creating interface between router = " + routerName + ", and subnet = " + subnetName);
        RouterInterface iface = (RouterInterface) cloudIntf.createRouterSubnetInterface(routerName, subnetName);
        assertTrue(iface != null && iface.getSubnetId().equals(subnet.getId()));
        /* delete router-subnet interface */
        logger.info("Deleting interface between router = " + routerName + ", and subnet = " + subnetName);
        cloudIntf.deleteRouterSubnetInterface(routerName, subnetName);
        /* delete router for external gateway */
        logger.info("Creating router with name = " + routerName);
        cloudIntf.deleteRouter(routerName);
        /* delete subnet for network */
        logger.info("Creating subnet with name = " + subnetName);
        cloudIntf.deleteSubnet(subnetName);
        /* delete network */
        logger.info("Deleting network with name = " + networkName);
        cloudIntf.deleteNetwork(networkName);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail();
    }
}
Also used : CloudInterface(org.apache.airavata.cloud.intf.CloudInterface) OpenstackIntfImpl(org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl) Network(org.openstack4j.model.network.Network) Router(org.openstack4j.model.network.Router) RouterInterface(org.openstack4j.model.network.RouterInterface) Subnet(org.openstack4j.model.network.Subnet) FileNotFoundException(java.io.FileNotFoundException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with RouterInterface

use of org.openstack4j.model.network.RouterInterface in project camel by apache.

the class RouterProducer method doAttach.

private void doAttach(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String routerId = msg.getHeader(NeutronConstants.ROUTER_ID, String.class);
    final String subnetPortId = msg.getHeader(NeutronConstants.SUBNET_ID, msg.getHeader(NeutronConstants.PORT_ID), String.class);
    final AttachInterfaceType type = msg.getHeader(NeutronConstants.ITERFACE_TYPE, AttachInterfaceType.class);
    ObjectHelper.notEmpty(routerId, "Router ID");
    ObjectHelper.notEmpty(subnetPortId, "Subnet/Port ID");
    ObjectHelper.notNull(type, "AttachInterfaceType ");
    RouterInterface routerInterface = os.networking().router().attachInterface(routerId, type, subnetPortId);
    msg.setBody(routerInterface);
}
Also used : Message(org.apache.camel.Message) RouterInterface(org.openstack4j.model.network.RouterInterface) AttachInterfaceType(org.openstack4j.model.network.AttachInterfaceType)

Example 4 with RouterInterface

use of org.openstack4j.model.network.RouterInterface in project camel by apache.

the class RouterProducer method doDetach.

private void doDetach(Exchange exchange) {
    final Message msg = exchange.getIn();
    final String routerId = msg.getHeader(NeutronConstants.ROUTER_ID, String.class);
    final String subnetId = msg.getHeader(NeutronConstants.SUBNET_ID, String.class);
    final String portId = msg.getHeader(NeutronConstants.PORT_ID, String.class);
    ObjectHelper.notEmpty(routerId, "Router ID");
    RouterInterface iface = os.networking().router().detachInterface(routerId, subnetId, portId);
    msg.setBody(iface);
}
Also used : Message(org.apache.camel.Message) RouterInterface(org.openstack4j.model.network.RouterInterface)

Example 5 with RouterInterface

use of org.openstack4j.model.network.RouterInterface in project camel by apache.

the class RouterProducerTest method detachTest.

@Test
public void detachTest() throws Exception {
    final String routerID = "myRouterID";
    final String portId = "port";
    final String subnetId = "subnet";
    final RouterInterface ifce = new NeutronRouterInterface(subnetId, portId);
    when(routerService.detachInterface(anyString(), anyString(), anyString())).thenReturn(ifce);
    msg.setHeader(OpenstackConstants.OPERATION, NeutronConstants.DETACH_INTERFACE);
    msg.setHeader(NeutronConstants.ROUTER_ID, routerID);
    msg.setHeader(NeutronConstants.SUBNET_ID, subnetId);
    msg.setHeader(NeutronConstants.PORT_ID, portId);
    producer.process(exchange);
    ArgumentCaptor<String> routerC = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> portC = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> subnetC = ArgumentCaptor.forClass(String.class);
    verify(routerService).detachInterface(routerC.capture(), subnetC.capture(), portC.capture());
    assertEquals(routerID, routerC.getValue());
    assertEquals(subnetId, subnetC.getValue());
    assertEquals(portId, portC.getValue());
    assertEquals(ifce, msg.getBody(RouterInterface.class));
}
Also used : RouterInterface(org.openstack4j.model.network.RouterInterface) NeutronRouterInterface(org.openstack4j.openstack.networking.domain.NeutronRouterInterface) Matchers.anyString(org.mockito.Matchers.anyString) NeutronRouterInterface(org.openstack4j.openstack.networking.domain.NeutronRouterInterface) Test(org.junit.Test)

Aggregations

RouterInterface (org.openstack4j.model.network.RouterInterface)6 Test (org.junit.Test)3 FileNotFoundException (java.io.FileNotFoundException)2 Message (org.apache.camel.Message)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AttachInterfaceType (org.openstack4j.model.network.AttachInterfaceType)2 Router (org.openstack4j.model.network.Router)2 Subnet (org.openstack4j.model.network.Subnet)2 NeutronRouterInterface (org.openstack4j.openstack.networking.domain.NeutronRouterInterface)2 CloudInterface (org.apache.airavata.cloud.intf.CloudInterface)1 OpenstackIntfImpl (org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl)1 Ignore (org.junit.Ignore)1 Network (org.openstack4j.model.network.Network)1