Repository: airavata
Updated Branches:
  refs/heads/develop d721666ed -> 79a9f1db7


Adding methods to create network, subnet, router, interface

Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/ebae1a77
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/ebae1a77
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/ebae1a77

Branch: refs/heads/develop
Commit: ebae1a77b4e153716ca2c288a473c3b737895980
Parents: 4a1e79f
Author: Gourav Shenoy <[email protected]>
Authored: Fri Apr 22 04:23:40 2016 -0400
Committer: Gourav Shenoy <[email protected]>
Committed: Fri Apr 22 04:23:40 2016 -0400

----------------------------------------------------------------------
 modules/cloud/cloud-provisioning/README         |  20 +-
 .../airavata/cloud/intf/CloudInterface.java     | 229 ++++--
 .../cloud/intf/impl/OpenstackIntfImpl.java      | 748 ++++++++++++-------
 .../apache/airavata/cloud/util/Constants.java   |  92 ++-
 .../main/resources/jetstream_openrc.properties  |  66 +-
 .../airavata/cloud/test/CloudIntfTest.java      | 331 ++++----
 .../src/test/resources/test_data.properties     |  58 +-
 7 files changed, 957 insertions(+), 587 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/ebae1a77/modules/cloud/cloud-provisioning/README
----------------------------------------------------------------------
diff --git a/modules/cloud/cloud-provisioning/README 
b/modules/cloud/cloud-provisioning/README
index dc4a7a6..0e16d0b 100644
--- a/modules/cloud/cloud-provisioning/README
+++ b/modules/cloud/cloud-provisioning/README
@@ -1,7 +1,13 @@
-This is the initial project created as an interface to various clouds.
-Currently supporting, Openstack on Jetstream using Openstack4j.
-
-To Test Run:-
-1) Replace the credentials in src/main/resources/jetstream_openrc.properties 
with the Jetstream credentials.
-2) Update the publicKeyFile, jetstream_imageId, jetstream_flavorId to the 
local path in src/test/resources/test_data.properties. This are the parameters 
used by the unit tests.
-3) Run JUnit Test org.apache.airavata.cloud.test.CloudIntfTest.
+This is the initial project created as an interface to various clouds.
+Currently supporting, Openstack on Jetstream using Openstack4j.
+
+To Test Run:-
+1) Replace the credentials in src/main/resources/jetstream_openrc.properties 
with the Jetstream credentials.
+2) Update the publicKeyFile, jetstream_imageId, jetstream_flavorId to the 
local path in src/test/resources/test_data.properties. This are the parameters 
used by the unit tests.
+3) Run JUnit Test org.apache.airavata.cloud.test.CloudIntfTest.
+
+## NETWORK CREATION STEPS
+1. Create a network.
+2. Create a subnet for the network.
+3. Create a router attached to public network. 
+4. Create an interface between router and the subnet.

http://git-wip-us.apache.org/repos/asf/airavata/blob/ebae1a77/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/CloudInterface.java
----------------------------------------------------------------------
diff --git 
a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/CloudInterface.java
 
b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/CloudInterface.java
index f64e11a..9d0fc5e 100644
--- 
a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/CloudInterface.java
+++ 
b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/CloudInterface.java
@@ -1,78 +1,151 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.airavata.cloud.intf;
-
-import org.openstack4j.model.compute.Keypair;
-import org.openstack4j.model.compute.Server;
-
-public interface CloudInterface {
-
-       /**
-        * Method to create Server.
-        * @param serverName
-        * @param imageId
-        * @param flavorId
-        * @param networkId
-        * @param keyPairName
-        * @return Server object.
-        */
-       public Server createServer(String serverName, String imageId, String 
flavorId, String keyPairName);
-
-       /**
-        * Returns the Server object pertaining to the serverId.
-        * @param serverId
-        * @return
-        */
-       public Server getServer(String serverId);
-
-       /**
-        * Method to delete Server.
-        * @param serverId
-        * @return
-        */
-       public void deleteServer(String serverId);
-
-       /**
-        * Creates a public key pair on the cloud
-        * @param publicKey
-        */
-       public Keypair createKeyPair(String keyPairName, String publicKey);
-
-       /**
-        * Returns the keypair object associated to the keyPairName.
-        * @param keyPairName
-        * @return
-        */
-       public Keypair getKeyPair(String keyPairName);
-
-       /**
-        * Deletes a public key pair on the cloud
-        * @param publicKey
-        */
-       public void deleteKeyPair(String keyPairName);
-
-       /**
-        * Associates a floating ip to the instance indicated by serverId.
-        * @param serverId
-        */
-       public void addFloatingIP(String serverId);
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.cloud.intf;
+
+/**
+ * The Interface CloudInterface.
+ */
+public interface CloudInterface {
+
+       /**
+        * Method to create Server.
+        *
+        * @param serverName the server name
+        * @param imageId the image id
+        * @param flavorId the flavor id
+        * @param keyPairName the key pair name
+        * @return Server object.
+        */
+       public Object createServer(String serverName, String imageId, String 
flavorId, String keyPairName);
+
+       /**
+        * Returns the Server object pertaining to the serverId.
+        *
+        * @param serverId the server id
+        * @return the server
+        */
+       public Object getServer(String serverId);
+
+       /**
+        * Method to delete Server.
+        *
+        * @param serverId the server id
+        */
+       public void deleteServer(String serverId);
+
+       /**
+        * Creates a public key pair on the cloud.
+        *
+        * @param keyPairName the key pair name
+        * @param publicKey the public key
+        * @return the keypair
+        */
+       public Object createKeyPair(String keyPairName, String publicKey);
+
+       /**
+        * Returns the keypair object associated to the keyPairName.
+        *
+        * @param keyPairName the key pair name
+        * @return the key pair
+        */
+       public Object getKeyPair(String keyPairName);
+
+       /**
+        * Deletes a public key pair on the cloud.
+        *
+        * @param keyPairName the key pair name
+        */
+       public void deleteKeyPair(String keyPairName);
+
+       /**
+        * Associates a floating ip to the instance indicated by serverId.
+        *
+        * @param serverId the server id
+        */
+       public void addFloatingIP(String serverId);
+       
+       /**
+        * Creates the router.
+        *
+        * @param routerName the router name
+        * @param externalGatewayName the external gateway name
+        * @return the object
+        */
+       public Object createRouter(String routerName, String 
externalGatewayName);
+       
+       /**
+        * Creates the subnet.
+        *
+        * @param subnetName the subnet name
+        * @param networkName the network name
+        * @param subnetCIDR the subnet cidr
+        * @param ipVersion the ip version
+        * @return the object
+        */
+       public Object createSubnet(String subnetName, String networkName, 
String subnetCIDR, int ipVersion);
+       
+       /**
+        * Creates the network.
+        *
+        * @param networkName the network name
+        * @return the object
+        */
+       public Object createNetwork(String networkName);
+       
+       /**
+        * Creates the router subnet interface.
+        *
+        * @param routerName the router name
+        * @param subnetName the subnet name
+        * @return the object
+        */
+       public Object createRouterSubnetInterface(String routerName, String 
subnetName);
+       
+       /**
+        * Delete router subnet interface.
+        *
+        * @param routerName the router name
+        * @param subnetName the subnet name
+        */
+       public void deleteRouterSubnetInterface(String routerName, String 
subnetName);
+       
+       /**
+        * Delete subnet.
+        *
+        * @param subnetName the subnet name
+        */
+       public void deleteSubnet(String subnetName);
+       
+       /**
+        * Delete router.
+        *
+        * @param routerName the router name
+        */
+       public void deleteRouter(String routerName);
+       
+       /**
+        * Delete network.
+        *
+        * @param networkName the network name
+        */
+       public void deleteNetwork(String networkName);
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/ebae1a77/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/impl/OpenstackIntfImpl.java
----------------------------------------------------------------------
diff --git 
a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/impl/OpenstackIntfImpl.java
 
b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/impl/OpenstackIntfImpl.java
index a4c4ed6..109df9d 100644
--- 
a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/impl/OpenstackIntfImpl.java
+++ 
b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/intf/impl/OpenstackIntfImpl.java
@@ -1,276 +1,472 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.airavata.cloud.intf.impl;
-
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
-
-import org.apache.airavata.cloud.intf.CloudInterface;
-import org.apache.airavata.cloud.openstack.OS4JClientProvider;
-import org.apache.airavata.cloud.util.Constants;
-import org.apache.airavata.cloud.util.IPType;
-import org.openstack4j.api.Builders;
-import org.openstack4j.api.OSClient;
-import org.openstack4j.model.compute.ActionResponse;
-import org.openstack4j.model.compute.Address;
-import org.openstack4j.model.compute.FloatingIP;
-import org.openstack4j.model.compute.Keypair;
-import org.openstack4j.model.compute.Server;
-import org.openstack4j.model.compute.ServerCreate;
-import org.openstack4j.model.network.Subnet;
-import org.openstack4j.openstack.compute.domain.NovaAddresses.NovaAddress;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class OpenstackIntfImpl implements CloudInterface {
-
-       /** The properties. */
-       private String propertiesFile;
-       private Properties properties;
-
-       // Initializing Logger
-       private Logger logger = 
LoggerFactory.getLogger(OpenstackIntfImpl.class);
-
-       OSClient os = null;
-
-       /**
-        * Default Constructor
-        * Initializing the properties.
-        */
-       public OpenstackIntfImpl(String propFile) {
-               try {
-
-                       this.propertiesFile = propFile;
-                       InputStream inputStream = getClass().getClassLoader()
-                                       .getResourceAsStream(propertiesFile);
-
-                       if(inputStream != null) {
-                               properties = new Properties();
-                               properties.load(inputStream);
-                       }
-                       else {
-                               throw new FileNotFoundException("property file: 
" + propertiesFile + " not found!");
-                       }
-
-                       // Initialize the OSClient.
-                       os = OS4JClientProvider.getOSClient(properties);
-               }
-               catch(Exception ex) {
-                       ex.printStackTrace();
-                       // TODO: Check with the team on how to handle 
exceptions.
-               }
-       }
-
-       @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_SUBNET_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;
-               }
-       }
-
-       @Override
-       public Server getServer(String serverId) {
-               try {
-
-                       Server server = os.compute().servers().get(serverId);
-
-                       logger.info("Server retrieved successfully for ID: " + 
serverId);
-
-                       return server;
-               }
-               catch( Exception ex ) {
-                       ex.printStackTrace();
-                       // TODO: Check with the team on how to handle 
exceptions.
-                       logger.error("Failed to retrieve server for ID: " + 
serverId);
-                       return null;
-               }
-       }
-
-       @Override
-       public void deleteServer(String serverId) {
-               try {
-
-                       Server server = this.getServer(serverId);
-
-                       // Get Floating IP if there is one associated.
-                       String floatingIpAddr = null;
-                       for(Address novaAddress : 
server.getAddresses().getAddresses().get(properties.getProperty(Constants.OS_SUBNET_NAME)))
 {
-                               novaAddress = (NovaAddress) novaAddress;
-                               
if(novaAddress.getType().equals(IPType.FLOATING.toString())) {
-                                       floatingIpAddr = novaAddress.getAddr();
-                                       break;
-                               }
-                       }
-
-                       if(server != null) {
-                               os.compute().servers().delete(serverId);
-
-                               // Deallocating Floating IP.
-                               if(floatingIpAddr != null) {
-                                       for(FloatingIP floatIp : 
os.compute().floatingIps().list()) {
-                                               
if(floatIp.getFloatingIpAddress().equals(floatingIpAddr)) {
-                                                       
os.compute().floatingIps().deallocateIP(floatIp.getId());
-                                               }
-                                       }
-                               }
-
-                               logger.info("Server deleted successfully for 
ID: " + serverId);
-                       }
-
-               }
-               catch( Exception ex ) {
-                       ex.printStackTrace();
-                       // TODO: Check with the team on how to handle 
exceptions.
-                       logger.error("Failed to delete server with ID: " + 
serverId);
-               }
-       }
-
-       @Override
-       public Keypair createKeyPair(String keyPairName, String publicKey) {
-               try {
-
-                       Keypair keyp = 
os.compute().keypairs().create(keyPairName, publicKey);
-
-                       logger.info("Keypair created successfully: " + 
keyp.getName());
-
-                       return keyp;
-               }
-               catch( Exception ex ) {
-                       ex.printStackTrace();
-                       // TODO: Check with the team on how to handle 
exceptions.
-                       logger.error("Failed to create keypair: " + 
keyPairName);
-                       return null;
-               }
-       }
-
-       @Override
-       public Keypair getKeyPair(String keyPairName) {
-               try {
-
-                       Keypair keyp = os.compute().keypairs().get(keyPairName);
-
-                       if(keyp != null){
-                               logger.info("Keypair retrieved successfully: " 
+ keyp.getName());                               
-                       }
-
-                       return keyp;
-               }
-               catch( Exception ex ) {
-                       ex.printStackTrace();
-                       // TODO: Check with the team on how to handle 
exceptions.
-                       logger.error("Failed to retrieve keypair: " + 
keyPairName);
-                       return null;
-               }
-       }
-
-       @Override
-       public void deleteKeyPair(String keyPairName) {
-               try {
-
-                       os.compute().keypairs().delete(keyPairName);
-
-                       logger.info("Keypair deleted successfully: " + 
keyPairName);
-               }
-               catch( Exception ex ) {
-                       ex.printStackTrace();
-                       // TODO: Check with the team on how to handle 
exceptions.
-                       logger.error("Failed to delete keypair: " + 
keyPairName);
-               }
-       }
-
-       @Override
-       public void addFloatingIP(String serverId) {
-
-               try {
-                       Server server = this.getServer(serverId);
-
-                       if(server != null) {
-                               FloatingIP floatIp = 
os.compute().floatingIps().allocateIP(properties.getProperty(Constants.OS_FLOATING_IP_POOL));
-
-                               if(floatIp != null) {
-                                       String ipAddr = 
floatIp.getFloatingIpAddress();
-
-                                       if(ipAddr != null) {
-                                               ActionResponse response = 
os.compute().floatingIps().addFloatingIP(server, ipAddr);
-                                               
logger.info(response.isSuccess() + ":" + response.getCode() + ":" + 
response.getFault() + ":" + response.toString());
-
-                                               logger.info("Floating IP "+ 
ipAddr + " assigned successfully to server with ID: " + serverId);
-                                       }
-                               }
-                               else {
-                                       logger.error("Failed to associate 
Floating IP.");
-                               }
-                       }
-               }
-               catch( Exception ex ) {
-                       ex.printStackTrace();
-                       // TODO: Check with the team on how to handle 
exceptions.
-                       logger.error("Failed to associate floating IP to server 
with ID: " + serverId);
-               }
-       }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.cloud.intf.impl;
+
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Properties;
+
+import org.apache.airavata.cloud.intf.CloudInterface;
+import org.apache.airavata.cloud.openstack.OS4JClientProvider;
+import org.apache.airavata.cloud.util.Constants;
+import org.apache.airavata.cloud.util.IPType;
+import org.openstack4j.api.Builders;
+import org.openstack4j.api.OSClient;
+import org.openstack4j.model.compute.ActionResponse;
+import org.openstack4j.model.compute.Address;
+import org.openstack4j.model.compute.FloatingIP;
+import org.openstack4j.model.compute.Keypair;
+import org.openstack4j.model.compute.Server;
+import org.openstack4j.model.compute.ServerCreate;
+import org.openstack4j.model.network.AttachInterfaceType;
+import org.openstack4j.model.network.IPVersionType;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.Router;
+import org.openstack4j.model.network.RouterInterface;
+import org.openstack4j.model.network.Subnet;
+import org.openstack4j.openstack.compute.domain.NovaAddresses.NovaAddress;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OpenstackIntfImpl implements CloudInterface {
+
+       /** The properties. */
+       private String propertiesFile;
+       private Properties properties;
+
+       // Initializing Logger
+       private Logger logger = 
LoggerFactory.getLogger(OpenstackIntfImpl.class);
+
+       OSClient os = null;
+
+       /**
+        * Default Constructor
+        * Initializing the properties.
+        */
+       public OpenstackIntfImpl(String propFile) {
+               try {
+
+                       this.propertiesFile = propFile;
+                       InputStream inputStream = getClass().getClassLoader()
+                                       .getResourceAsStream(propertiesFile);
+
+                       if(inputStream != null) {
+                               properties = new Properties();
+                               properties.load(inputStream);
+                       }
+                       else {
+                               throw new FileNotFoundException("property file: 
" + propertiesFile + " not found!");
+                       }
+
+                       // Initialize the OSClient.
+                       os = OS4JClientProvider.getOSClient(properties);
+               }
+               catch(Exception ex) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+               }
+       }
+
+       @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;
+               }
+       }
+
+       @Override
+       public Server getServer(String serverId) {
+               try {
+
+                       Server server = os.compute().servers().get(serverId);
+
+                       logger.info("Server retrieved successfully for ID: " + 
serverId);
+
+                       return server;
+               }
+               catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to retrieve server for ID: " + 
serverId);
+                       return null;
+               }
+       }
+
+       @Override
+       public void deleteServer(String serverId) {
+               try {
+
+                       Server server = this.getServer(serverId);
+
+                       // Get Floating IP if there is one associated.
+                       String floatingIpAddr = null;
+                       for(Address novaAddress : 
server.getAddresses().getAddresses().get(properties.getProperty(Constants.OS_NETWORK_NAME)))
 {
+                               novaAddress = (NovaAddress) novaAddress;
+                               
if(novaAddress.getType().equals(IPType.FLOATING.toString())) {
+                                       floatingIpAddr = novaAddress.getAddr();
+                                       break;
+                               }
+                       }
+
+                       if(server != null) {
+                               os.compute().servers().delete(serverId);
+
+                               // Deallocating Floating IP.
+                               if(floatingIpAddr != null) {
+                                       for(FloatingIP floatIp : 
os.compute().floatingIps().list()) {
+                                               
if(floatIp.getFloatingIpAddress().equals(floatingIpAddr)) {
+                                                       
os.compute().floatingIps().deallocateIP(floatIp.getId());
+                                               }
+                                       }
+                               }
+
+                               logger.info("Server deleted successfully for 
ID: " + serverId);
+                       }
+
+               }
+               catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to delete server with ID: " + 
serverId);
+               }
+       }
+
+       @Override
+       public Keypair createKeyPair(String keyPairName, String publicKey) {
+               try {
+
+                       Keypair keyp = 
os.compute().keypairs().create(keyPairName, publicKey);
+
+                       logger.info("Keypair created successfully: " + 
keyp.getName());
+
+                       return keyp;
+               }
+               catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to create keypair: " + 
keyPairName);
+                       return null;
+               }
+       }
+
+       @Override
+       public Keypair getKeyPair(String keyPairName) {
+               try {
+
+                       Keypair keyp = os.compute().keypairs().get(keyPairName);
+
+                       if(keyp != null){
+                               logger.info("Keypair retrieved successfully: " 
+ keyp.getName());                               
+                       }
+
+                       return keyp;
+               }
+               catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to retrieve keypair: " + 
keyPairName);
+                       return null;
+               }
+       }
+
+       @Override
+       public void deleteKeyPair(String keyPairName) {
+               try {
+
+                       os.compute().keypairs().delete(keyPairName);
+
+                       logger.info("Keypair deleted successfully: " + 
keyPairName);
+               }
+               catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to delete keypair: " + 
keyPairName);
+               }
+       }
+
+       @Override
+       public void addFloatingIP(String serverId) {
+
+               try {
+                       Server server = this.getServer(serverId);
+
+                       if(server != null) {
+                               FloatingIP floatIp = 
os.compute().floatingIps().allocateIP(properties.getProperty(Constants.OS_FLOATING_IP_POOL));
+
+                               if(floatIp != null) {
+                                       String ipAddr = 
floatIp.getFloatingIpAddress();
+
+                                       if(ipAddr != null) {
+                                               ActionResponse response = 
os.compute().floatingIps().addFloatingIP(server, ipAddr);
+                                               
logger.info(response.isSuccess() + ":" + response.getCode() + ":" + 
response.getFault() + ":" + response.toString());
+
+                                               logger.info("Floating IP "+ 
ipAddr + " assigned successfully to server with ID: " + serverId);
+                                       }
+                               }
+                               else {
+                                       logger.error("Failed to associate 
Floating IP.");
+                               }
+                       }
+               }
+               catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to associate floating IP to server 
with ID: " + serverId);
+               }
+       }
+
+       @Override
+       public Object createNetwork(String networkName) {
+               Network network = null;
+               try {
+                       network = 
os.networking().network().create(Builders.network()
+                                       .name(networkName)
+                                       .adminStateUp(true)
+                                       .build());
+                       logger.info("Created a new network : " + network);
+               } catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to create network: " + networkName 
+ ". Exception: " + ex.getMessage(), ex);
+               }
+               return network;
+       }
+
+       @Override
+       public Object createRouter(String routerName, String 
externalGatewayName) {
+               String publicNetId = null;
+               Router router = null;
+               try {
+                       for(Network net : os.networking().network().list()) {
+                               if(net.getName().equals(externalGatewayName)) {
+                                       publicNetId = net.getId();
+                               }
+                       }
+                       if(publicNetId != null) {
+                               router = 
os.networking().router().create(Builders.router()
+                                                                               
                        .name(routerName)
+                                                                               
                        .adminStateUp(true)
+                                                                               
                        .externalGateway(publicNetId)
+                                                                               
                        .build());
+                               logger.info("Created a new router " + router + 
" for external gateway : [" + externalGatewayName + "]");
+                       } else {
+                               logger.error("Failed to create router because 
external gateway [ " + externalGatewayName + "] is not found!");
+                       }       
+               } catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to create network: " + routerName 
+ ". Exception: " + ex.getMessage(), ex);
+               }
+               return router;
+       }
+
+       @Override
+       public Object createSubnet(String subnetName, String networkName, 
String subnetCIDR, int ipVersion) {
+               String networkId = null;
+               Subnet subnet = null;
+               try {
+                       // get network id
+                       for(Network network : os.networking().network().list()) 
{
+                               if(network.getName().equals(networkName)) {
+                                       networkId = network.getId();
+                               }
+                       }
+                       
+                       if(networkId != null) {
+                               subnet = 
os.networking().subnet().create(Builders.subnet()
+                                                                               
                                                        .enableDHCP(true)
+                                                                               
                                        .name(subnetName)
+                                                                               
                                        .networkId(networkId)
+                                                                               
                                        
.ipVersion(IPVersionType.valueOf(ipVersion))
+                                                                               
                                        .cidr(subnetCIDR)
+                                                                               
                                        .build());
+                               logger.info("Created a subnet : " + subnetName 
+ " for network [ " + networkName + "]");
+                       } else {
+                               logger.error("Failed to create subnet because 
network [ " + networkName + "] is not found!");
+                       }
+               } catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to create subnet: " + subnetName + 
". Exception: " + ex.getMessage(), ex);
+               }
+               return subnet;
+       }
+
+       @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;
+       }
+
+       @Override
+       public void deleteRouterSubnetInterface(String routerName, String 
subnetName) {
+               String routerId = null, subnetId = null;
+               try {
+                       // get subnet id
+                       for(Subnet subnet : os.networking().subnet().list()) {
+                               if(subnet.getName().equals(subnetName)) {
+                                       subnetId = subnet.getId();
+                               }
+                       }
+                       // get router id
+                       for(Router router : os.networking().router().list()) {
+                               if(router.getName().equals(routerName)) {
+                                       routerId = router.getId();
+                               }
+                       }
+                       // detach the interface
+                       if(routerId != null && subnetId != null) {
+                               
os.networking().router().detachInterface(routerId, subnetId, null);
+                       } else {
+                               logger.error("Failed to delete router subnet 
interface. Either router/subnet not found.");
+                       }
+               } catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to delete subnet: " + subnetName + 
". Exception: " + ex.getMessage(), ex);
+               }
+       }
+
+       @Override
+       public void deleteSubnet(String subnetName) {
+               try {
+                       for(Subnet subnet : os.networking().subnet().list()) {
+                               if(subnet.getName().equals(subnetName)) {
+                                       
os.networking().subnet().delete(subnet.getId());
+                                       logger.info("Deleted Subnet [" + 
subnet.getName() + "] Successfully.");
+                               }
+                       }
+               } catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to delete subnet: " + subnetName + 
". Exception: " + ex.getMessage(), ex);
+               }
+               
+       }
+
+       @Override
+       public void deleteRouter(String routerName) {
+               try {
+                       for(Router router : os.networking().router().list()) {
+                               if(router.getName().equals(routerName)) {
+                                       
os.networking().router().delete(router.getId());
+                                       logger.info("Deleted Router [" + 
router.getName() + "] Successfully.");
+                               }
+                       }
+               } catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to delete router: " + routerName + 
". Exception: " + ex.getMessage(), ex);
+               }
+               
+       }
+
+       @Override
+       public void deleteNetwork(String networkName) {
+               try {
+                       for(Network network : os.networking().network().list()) 
{
+                               if(network.getName().equals(networkName)) {
+                                       
os.networking().network().delete(network.getId());
+                                       logger.info("Deleted Network [" + 
network.getName() + "] Successfully.");
+                               }
+                       }
+               } catch( Exception ex ) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+                       logger.error("Failed to delete network: " + networkName 
+ ". Exception: " + ex.getMessage(), ex);
+               }
+       }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/ebae1a77/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/Constants.java
----------------------------------------------------------------------
diff --git 
a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/Constants.java
 
b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/Constants.java
index e2b9ad1..24b1729 100644
--- 
a/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/Constants.java
+++ 
b/modules/cloud/cloud-provisioning/src/main/java/org/apache/airavata/cloud/util/Constants.java
@@ -1,36 +1,56 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with tproperties.getProperty("OS_PROJECT_DOMAIN_NAME")his work 
for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.airavata.cloud.util;
-
-public class Constants {
-
-       // OpenStack openrc string constants.
-       public static final String OS_AUTH_URL = "OS_AUTH_URL";
-       public static final String OS_IDENTITY_API_VERSION = 
"OS_IDENTITY_API_VERSION";
-       public static final String OS_USERNAME = "OS_USERNAME";
-       public static final String OS_PASSWORD = "OS_PASSWORD";
-       public static final String OS_USER_DOMAIN_NAME = "OS_USER_DOMAIN_NAME";
-       public static final String OS_PROJECT_DOMAIN_NAME = 
"OS_PROJECT_DOMAIN_NAME";
-       public static final String OS_FLOATING_IP_POOL = "OS_FLOATING_IP_POOL";
-       public static final String OS_SUBNET_NAME = "OS_SUBNET_NAME";
-
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with tproperties.getProperty("OS_PROJECT_DOMAIN_NAME")his work 
for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.cloud.util;
+
+/**
+ * The Class Constants.
+ */
+public class Constants {
+
+       /** The Constant OS_AUTH_URL. */
+       // OpenStack openrc string constants.
+       public static final String OS_AUTH_URL = "OS_AUTH_URL";
+       
+       /** The Constant OS_IDENTITY_API_VERSION. */
+       public static final String OS_IDENTITY_API_VERSION = 
"OS_IDENTITY_API_VERSION";
+       
+       /** The Constant OS_USERNAME. */
+       public static final String OS_USERNAME = "OS_USERNAME";
+       
+       /** The Constant OS_PASSWORD. */
+       public static final String OS_PASSWORD = "OS_PASSWORD";
+       
+       /** The Constant OS_USER_DOMAIN_NAME. */
+       public static final String OS_USER_DOMAIN_NAME = "OS_USER_DOMAIN_NAME";
+       
+       /** The Constant OS_PROJECT_DOMAIN_NAME. */
+       public static final String OS_PROJECT_DOMAIN_NAME = 
"OS_PROJECT_DOMAIN_NAME";
+       
+       /** The Constant OS_FLOATING_IP_POOL. */
+       public static final String OS_FLOATING_IP_POOL = "OS_FLOATING_IP_POOL";
+       
+       /** The Constant OS_NETWORK_NAME. */
+       public static final String OS_NETWORK_NAME = "OS_NETWORK_NAME";
+       
+       /** The Constant OS_IP_VERSION_DEFAULT. */
+       public static final Integer OS_IP_VERSION_DEFAULT = 4;
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/ebae1a77/modules/cloud/cloud-provisioning/src/main/resources/jetstream_openrc.properties
----------------------------------------------------------------------
diff --git 
a/modules/cloud/cloud-provisioning/src/main/resources/jetstream_openrc.properties
 
b/modules/cloud/cloud-provisioning/src/main/resources/jetstream_openrc.properties
index cda2bec..a2c0414 100644
--- 
a/modules/cloud/cloud-provisioning/src/main/resources/jetstream_openrc.properties
+++ 
b/modules/cloud/cloud-provisioning/src/main/resources/jetstream_openrc.properties
@@ -1,33 +1,33 @@
-#
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-# Authentication properties
-OS_PROJECT_DOMAIN_NAME=scigap
-OS_USER_DOMAIN_NAME=tacc
-OS_PROJECT_NAME=scigap
-OS_TENANT_NAME=scigap
-OS_USERNAME=scigap
-OS_PASSWORD=xxxxxxxx
-OS_AUTH_URL=https://jblb.jetstream-cloud.org:35357/v3
-OS_IDENTITY_API_VERSION=3
-
-# Network Properties
-OS_FLOATING_IP_POOL=public
-OS_SUBNET_NAME=airavata
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Authentication properties
+OS_PROJECT_DOMAIN_NAME=scigap
+OS_USER_DOMAIN_NAME=tacc
+OS_PROJECT_NAME=scigap
+OS_TENANT_NAME=scigap
+OS_USERNAME=scigap
+OS_PASSWORD=xxxxxxxxxxx
+OS_AUTH_URL=https://jblb.jetstream-cloud.org:35357/v3
+OS_IDENTITY_API_VERSION=3
+
+# Network Properties
+OS_FLOATING_IP_POOL=public
+OS_NETWORK_NAME=airavata
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/ebae1a77/modules/cloud/cloud-provisioning/src/test/java/org/apache/airavata/cloud/test/CloudIntfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/cloud/cloud-provisioning/src/test/java/org/apache/airavata/cloud/test/CloudIntfTest.java
 
b/modules/cloud/cloud-provisioning/src/test/java/org/apache/airavata/cloud/test/CloudIntfTest.java
index c48c694..a77725b 100644
--- 
a/modules/cloud/cloud-provisioning/src/test/java/org/apache/airavata/cloud/test/CloudIntfTest.java
+++ 
b/modules/cloud/cloud-provisioning/src/test/java/org/apache/airavata/cloud/test/CloudIntfTest.java
@@ -1,131 +1,200 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-package org.apache.airavata.cloud.test;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-import java.util.Properties;
-import java.util.Scanner;
-
-import org.apache.airavata.cloud.intf.CloudInterface;
-import org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl;
-import org.junit.Test;
-import org.openstack4j.model.compute.Keypair;
-import org.openstack4j.model.compute.Server;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class CloudIntfTest {
-
-       /** The properties. */
-       private String propertiesFile = "test_data.properties";
-       private Properties properties;
-
-       // Initializing Logger
-       private Logger logger = LoggerFactory.getLogger(CloudIntfTest.class);
-
-       public CloudIntfTest() {
-               try {
-
-                       InputStream inputStream = getClass().getClassLoader()
-                                       .getResourceAsStream(propertiesFile);
-
-                       if(inputStream != null) {
-                               properties = new Properties();
-                               properties.load(inputStream);
-                       }
-                       else {
-                               throw new FileNotFoundException("property file: 
" + propertiesFile + " not found!");
-                       }
-
-               }
-               catch(Exception ex) {
-                       ex.printStackTrace();
-                       // TODO: Check with the team on how to handle 
exceptions.
-               }
-       }
-
-       /**
-        * Test that will create keypair, create server with keypair, delete 
server, delete keypair.
-        */
-       @Test
-       public void jetstreamCreateDeleteServerTest() {
-               try {
-                       CloudInterface cloudIntf = new 
OpenstackIntfImpl("jetstream_openrc.properties");
-                       // Sample data. This can be determined by the inputs 
from Airavata.
-                       String imageId = 
properties.getProperty("jetstream_imageId");
-                       String flavorId = 
properties.getProperty("jetstream_flavorId");
-
-                       // Delay in milliseconds used for waiting for server 
create and delete.
-                       Integer delay = 30000;
-
-                       /* Create Keypair */
-                       String publicKeyFile = 
properties.getProperty("publicKeyFile");
-                       String keyPairName = "testKey";
-
-                       Scanner fileScan = new Scanner(new 
FileInputStream(publicKeyFile));
-                       String publicKey = fileScan.nextLine();
-
-                       Keypair kp = cloudIntf.getKeyPair(keyPairName);
-                       if(kp == null) {
-                               kp = cloudIntf.createKeyPair(keyPairName, 
publicKey);
-                       }
-
-                       logger.info("Keypair created/ retrieved: " + 
kp.getFingerprint());
-
-                       /* Create Server */
-                       Server newServer = 
cloudIntf.createServer("AiravataTest", imageId, flavorId, kp.getName());
-                       logger.info("Server Created: " + newServer.getId());
-
-                       /* Wait 30 seconds until server is active */
-                       logger.info("Waiting for instance to go ACTIVE...");
-                       Thread.sleep(delay);
-
-                       /* Associate floating ip */
-                       cloudIntf.addFloatingIP(newServer.getId());
-
-                       /* Delete Server */
-                       cloudIntf.deleteServer(newServer.getId());
-                       logger.info("Server deleted: " + newServer.getId());
-
-                       /* Wait 30 seconds until server is terminated */
-                       logger.info("Waiting for instance to terminate...");
-                       Thread.sleep(delay);
-
-                       /* Delete Keypair */
-                       cloudIntf.deleteKeyPair(kp.getName());
-                       logger.info("Keypair deleted: " + kp.getName());
-
-                       Server deleted = cloudIntf.getServer(newServer.getId());
-
-                       assertTrue(newServer != null && deleted == null);
-               }
-               catch( Exception ex ) {
-                       ex.printStackTrace();
-                       fail();
-               }
-       }
-}
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.cloud.test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.Scanner;
+
+import org.apache.airavata.cloud.intf.CloudInterface;
+import org.apache.airavata.cloud.intf.impl.OpenstackIntfImpl;
+import org.apache.airavata.cloud.util.Constants;
+import org.junit.Test;
+import org.openstack4j.model.compute.Keypair;
+import org.openstack4j.model.compute.Server;
+import org.openstack4j.model.network.Network;
+import org.openstack4j.model.network.Router;
+import org.openstack4j.model.network.RouterInterface;
+import org.openstack4j.model.network.Subnet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CloudIntfTest {
+
+       /** The properties. */
+       private String propertiesFile = "test_data.properties";
+       private Properties properties;
+
+       // Initializing Logger
+       private Logger logger = LoggerFactory.getLogger(CloudIntfTest.class);
+
+       public CloudIntfTest() {
+               try {
+
+                       InputStream inputStream = getClass().getClassLoader()
+                                       .getResourceAsStream(propertiesFile);
+
+                       if(inputStream != null) {
+                               properties = new Properties();
+                               properties.load(inputStream);
+                       }
+                       else {
+                               throw new FileNotFoundException("property file: 
" + propertiesFile + " not found!");
+                       }
+
+               }
+               catch(Exception ex) {
+                       ex.printStackTrace();
+                       // TODO: Check with the team on how to handle 
exceptions.
+               }
+       }
+
+       /**
+        * Test that will create keypair, create server with keypair, delete 
server, delete keypair.
+        */
+       @Test
+       public void jetstreamCreateDeleteServerTest() {
+               try {
+                       CloudInterface cloudIntf = new 
OpenstackIntfImpl("jetstream_openrc.properties");
+                       // Sample data. This can be determined by the inputs 
from Airavata.
+                       String imageId = 
properties.getProperty("jetstream_imageId");
+                       String flavorId = 
properties.getProperty("jetstream_flavorId");
+
+                       // Delay in milliseconds used for waiting for server 
create and delete.
+                       Integer delay = 30000;
+
+                       /* Create Keypair */
+                       String publicKeyFile = 
properties.getProperty("publicKeyFile");
+                       String keyPairName = "testKey";
+
+                       Scanner fileScan = new Scanner(new 
FileInputStream(publicKeyFile));
+                       String publicKey = fileScan.nextLine();
+
+                       Keypair kp = (Keypair) 
cloudIntf.getKeyPair(keyPairName);
+                       if(kp == null) {
+                               kp = (Keypair) 
cloudIntf.createKeyPair(keyPairName, publicKey);
+                       }
+
+                       logger.info("Keypair created/ retrieved: " + 
kp.getFingerprint());
+
+                       /* Create Server */
+                       Server newServer = (Server) 
cloudIntf.createServer("AiravataTest", imageId, flavorId, kp.getName());
+                       logger.info("Server Created: " + newServer.getId());
+
+                       /* Wait 30 seconds until server is active */
+                       logger.info("Waiting for instance to go ACTIVE...");
+                       Thread.sleep(delay);
+
+                       /* Associate floating ip */
+                       cloudIntf.addFloatingIP(newServer.getId());
+
+                       /* Delete Server */
+                       cloudIntf.deleteServer(newServer.getId());
+                       logger.info("Server deleted: " + newServer.getId());
+
+                       /* Wait 30 seconds until server is terminated */
+                       logger.info("Waiting for instance to terminate...");
+                       Thread.sleep(delay);
+
+                       /* Delete Keypair */
+                       cloudIntf.deleteKeyPair(kp.getName());
+                       logger.info("Keypair deleted: " + kp.getName());
+
+                       Server deleted = (Server) 
cloudIntf.getServer(newServer.getId());
+
+                       assertTrue(newServer != null && deleted == null);
+               }
+               catch( Exception ex ) {
+                       ex.printStackTrace();
+                       fail();
+               }
+       }
+       
+       /**
+        * Jetstream create delete network test.
+        */
+       @Test
+       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();
+               }
+               
+       }
+}

http://git-wip-us.apache.org/repos/asf/airavata/blob/ebae1a77/modules/cloud/cloud-provisioning/src/test/resources/test_data.properties
----------------------------------------------------------------------
diff --git 
a/modules/cloud/cloud-provisioning/src/test/resources/test_data.properties 
b/modules/cloud/cloud-provisioning/src/test/resources/test_data.properties
index df87b8e..5be93b1 100644
--- a/modules/cloud/cloud-provisioning/src/test/resources/test_data.properties
+++ b/modules/cloud/cloud-provisioning/src/test/resources/test_data.properties
@@ -1,26 +1,32 @@
-#
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-#
-
-# Common properties
-publicKeyFile=/path/id_rsa.pub
-
-# Jetstream properties
-jetstream_imageId=7048bb41-bbbbb-4caa-9370-xxxxxxxxxxx
-jetstream_flavorId=3
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Common properties
+publicKeyFile=/path/id_rsa.pub
+
+# Jetstream properties
+jetstream_imageId=7048bb41-bbbbb-4caa-9370-xxxxxxxxxxx
+jetstream_flavorId=3
+
+# Jetstream network related data
+jetstream_network_name=test-network
+jetstream_public_network_name=public
+jetstream_subnet_cidr=192.168.7.0/24
+jetstream_ip_version=4
\ No newline at end of file

Reply via email to