Search in sources :

Example 1 with Subnet

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

the class SubnetProducerTest method setUp.

@Before
public void setUp() {
    producer = new SubnetProducer(endpoint, client);
    when(subnetService.create(any(Subnet.class))).thenReturn(testOSsubnet);
    when(subnetService.get(anyString())).thenReturn(testOSsubnet);
    List<Subnet> getAllList = new ArrayList<>();
    getAllList.add(testOSsubnet);
    getAllList.add(testOSsubnet);
    doReturn(getAllList).when(subnetService).list();
    dummySubnet = createSubnet();
    when(testOSsubnet.getName()).thenReturn(dummySubnet.getName());
    when(testOSsubnet.getNetworkId()).thenReturn(dummySubnet.getNetworkId());
    when(testOSsubnet.getId()).thenReturn(UUID.randomUUID().toString());
}
Also used : ArrayList(java.util.ArrayList) Subnet(org.openstack4j.model.network.Subnet) SubnetProducer(org.apache.camel.component.openstack.neutron.producer.SubnetProducer) Before(org.junit.Before)

Example 2 with Subnet

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

the class SubnetTests method getSubnetIpV6.

@Test
public void getSubnetIpV6() throws Exception {
    respondWith(JSON_GET_SUBNET);
    Subnet n = osv3().networking().subnet().get(SUBNET_ID);
    server.takeRequest();
    assertEquals(n.getName(), SUBNET_NAME);
    assertEquals(n.getIpv6AddressMode(), Ipv6AddressMode.DHCPV6_STATEFUL);
    assertEquals(n.getIpv6RaMode(), Ipv6RaMode.DHCPV6_STATEFUL);
}
Also used : Subnet(org.openstack4j.model.network.Subnet) AbstractTest(org.openstack4j.api.AbstractTest) Test(org.testng.annotations.Test)

Example 3 with Subnet

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

the class OpenstackIntfImpl method createServer.

@Override
public Server createServer(String serverName, String imageId, String flavorId, String keyPairName) {
    try {
        Server newServer = null;
        String networkId = null;
        // Adhering to openstack format of subnet names 'subnet-<name>'.
        String networkName = "subnet-" + properties.getProperty(Constants.OS_NETWORK_NAME);
        for (Subnet net : os.networking().subnet().list()) {
            if (net.getName().equals(networkName)) {
                networkId = net.getNetworkId();
                logger.info("Using network " + networkName + " with ID: " + networkId);
                break;
            }
        }
        if (networkId != null) {
            List<String> srvNet = new LinkedList<String>();
            srvNet.add(networkId);
            ServerCreate sc = Builders.server().name(serverName).flavor(flavorId).image(imageId).networks(srvNet).keypairName(keyPairName).build();
            // Boot the Server
            newServer = os.compute().servers().boot(sc);
            logger.info("New server created with ID: " + newServer.getId());
        } else {
            logger.error("Network with name " + networkName + " not found.");
        }
        return newServer;
    } catch (Exception ex) {
        ex.printStackTrace();
        // TODO: Check with the team on how to handle exceptions.
        logger.error("Failed to create server.");
        return null;
    }
}
Also used : Server(org.openstack4j.model.compute.Server) ServerCreate(org.openstack4j.model.compute.ServerCreate) Subnet(org.openstack4j.model.network.Subnet) LinkedList(java.util.LinkedList) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with Subnet

use of org.openstack4j.model.network.Subnet 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 5 with Subnet

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

Aggregations

Subnet (org.openstack4j.model.network.Subnet)13 FileNotFoundException (java.io.FileNotFoundException)5 Network (org.openstack4j.model.network.Network)3 Router (org.openstack4j.model.network.Router)2 RouterInterface (org.openstack4j.model.network.RouterInterface)2 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)1 CloudNetworks (com.sequenceiq.cloudbreak.cloud.model.CloudNetworks)1 OpenStackResourceException (com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException)1 KeystoneCredentialView (com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView)1 NeutronNetworkView (com.sequenceiq.cloudbreak.cloud.openstack.view.NeutronNetworkView)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 Set (java.util.Set)1 CloudInterface (org.apache.airavata.cloud.intf.CloudInterface)1 OpenstackIntfImpl (org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl)1 Message (org.apache.camel.Message)1