Search in sources :

Example 1 with Network

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

the class NetworkProducer method messageToNetwork.

private Network messageToNetwork(Message message) {
    Network network = message.getBody(Network.class);
    if (network == null) {
        Map headers = message.getHeaders();
        NetworkBuilder builder = Builders.network();
        ObjectHelper.notEmpty(message.getHeader(OpenstackConstants.NAME, String.class), "Name");
        builder.name(message.getHeader(OpenstackConstants.NAME, String.class));
        if (headers.containsKey(NeutronConstants.ADMIN_STATE_UP)) {
            builder.adminStateUp(message.getHeader(NeutronConstants.ADMIN_STATE_UP, Boolean.class));
        }
        if (headers.containsKey(NeutronConstants.NETWORK_TYPE)) {
            builder.networkType(message.getHeader(NeutronConstants.NETWORK_TYPE, NetworkType.class));
        }
        if (headers.containsKey(NeutronConstants.IS_SHARED)) {
            builder.isShared(message.getHeader(NeutronConstants.IS_SHARED, Boolean.class));
        }
        if (headers.containsKey(NeutronConstants.IS_ROUTER_EXTERNAL)) {
            builder.isRouterExternal(message.getHeader(NeutronConstants.IS_ROUTER_EXTERNAL, Boolean.class));
        }
        if (headers.containsKey(NeutronConstants.TENANT_ID)) {
            builder.tenantId(message.getHeader(NeutronConstants.TENANT_ID, String.class));
        }
        if (headers.containsKey(NeutronConstants.PHYSICAL_NETWORK)) {
            builder.physicalNetwork(message.getHeader(NeutronConstants.PHYSICAL_NETWORK, String.class));
        }
        if (headers.containsKey(NeutronConstants.SEGMENT_ID)) {
            builder.segmentId(message.getHeader(NeutronConstants.SEGMENT_ID, String.class));
        }
        network = builder.build();
    }
    return network;
}
Also used : NetworkBuilder(org.openstack4j.model.network.builder.NetworkBuilder) NetworkType(org.openstack4j.model.network.NetworkType) Network(org.openstack4j.model.network.Network) Map(java.util.Map)

Example 2 with Network

use of org.openstack4j.model.network.Network 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 Network

use of org.openstack4j.model.network.Network in project openstack4j by ContainX.

the class NetworkTests method getNetwork.

@Test
public void getNetwork() throws Exception {
    respondWith(JSON_NETWORK);
    Network n = osv3().networking().network().get(NETWORK_ID);
    server.takeRequest();
    assertEquals(n.getName(), NETWORK_NAME);
    assertEquals(n.getStatus(), State.ACTIVE);
    assertEquals(n.isRouterExternal(), false);
}
Also used : Network(org.openstack4j.model.network.Network) Test(org.testng.annotations.Test) AbstractTest(org.openstack4j.api.AbstractTest)

Example 4 with Network

use of org.openstack4j.model.network.Network in project openstack4j by ContainX.

the class NetworkTests method createNetworkWithZone.

@Test
public void createNetworkWithZone() throws Exception {
    respondWith(JSON_NETWORK_ZONE);
    Network n = osv3().networking().network().create(Builders.network().name(NETWORK_NAME).isRouterExternal(true).adminStateUp(true).addAvailabilityZoneHints("nova").build());
    server.takeRequest();
    assertEquals(n.getName(), NETWORK_NAME);
    assertEquals(n.getStatus(), State.ACTIVE);
    assertEquals(n.getAvailabilityZoneHints().get(0), "nova");
}
Also used : Network(org.openstack4j.model.network.Network) Test(org.testng.annotations.Test) AbstractTest(org.openstack4j.api.AbstractTest)

Example 5 with Network

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

the class NetworkProducer method doCreate.

private void doCreate(Exchange exchange) {
    final Network in = messageToNetwork(exchange.getIn());
    final Network out = os.networking().network().create(in);
    exchange.getIn().setBody(out);
}
Also used : Network(org.openstack4j.model.network.Network)

Aggregations

Network (org.openstack4j.model.network.Network)15 FileNotFoundException (java.io.FileNotFoundException)5 AbstractTest (org.openstack4j.api.AbstractTest)3 Subnet (org.openstack4j.model.network.Subnet)3 Test (org.testng.annotations.Test)3 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Message (org.apache.camel.Message)2 NetworkProducer (org.apache.camel.component.openstack.neutron.producer.NetworkProducer)2 Test (org.junit.Test)2 Router (org.openstack4j.model.network.Router)2 AvailabilityZone (com.sequenceiq.cloudbreak.cloud.model.AvailabilityZone)1 CloudIpPool (com.sequenceiq.cloudbreak.cloud.model.CloudIpPool)1 CloudIpPools (com.sequenceiq.cloudbreak.cloud.model.CloudIpPools)1 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)1 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)1 Region (com.sequenceiq.cloudbreak.cloud.model.Region)1 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)1