#
 # http://www.apache.org/licenses/LICENSE-2.0
 #
+import os
 import sys
 import time
 import requests
 
 import functest.utils.functest_logger as ft_logger
 import functest.utils.openstack_utils as os_utils
+from opnfv.deployment.factory import Factory as DeploymentFactory
 
 from sdnvpn.lib import config as sdnvpn_config
 
     return (u1 + u2)
 
 
+def get_installerHandler():
+    installer_type = str(os.environ['INSTALLER_TYPE'].lower())
+    installer_ip = get_installer_ip()
+
+    if installer_type not in ["fuel", "apex"]:
+        raise ValueError("%s is not supported" % installer_type)
+    else:
+        if installer_type in ["apex"]:
+            developHandler = DeploymentFactory.get_handler(
+                installer_type,
+                installer_ip,
+                'root',
+                pkey_file="/root/.ssh/id_rsa")
+
+        if installer_type in ["fuel"]:
+            developHandler = DeploymentFactory.get_handler(
+                installer_type,
+                installer_ip,
+                'root',
+                'r00tme')
+        return developHandler
+
+
+def get_nodes():
+    developHandler = get_installerHandler()
+    return developHandler.get_nodes()
+
+
+def get_installer_ip():
+    return str(os.environ['INSTALLER_IP'])
+
+
 def wait_for_instance(instance):
     logger.info("Waiting for instance %s to get a DHCP lease..." % instance.id)
     # The sleep this function replaced waited for 80s
 
 
 from sdnvpn.lib.results import Results
 
-from opnfv.deployment.factory import Factory as DeploymentFactory
-
 
 COMMON_CONFIG = sdnvpn_config.CommonConfig()
 TESTCASE_CONFIG = sdnvpn_config.TestcaseConfig("testcase_3")
     results.add_to_summary(2, "STATUS", "SUBTEST")
     results.add_to_summary(0, "=")
 
-    # TODO unhardcode this to work with apex
-    deploymentHandler = DeploymentFactory.get_handler(
-        'fuel',
-        '10.20.0.2',
-        'root',
-        'r00tme')
-
-    openstack_nodes = deploymentHandler.get_nodes()
+    openstack_nodes = test_utils.get_nodes()
 
     controllers = [node for node in openstack_nodes
                    if node.is_odl()]
     msg = ("Verify that OpenDaylight can start/communicate with zrpcd/Quagga")
     results.record_action(msg)
     results.add_to_summary(0, "-")
-
     if not controllers:
         msg = ("Controller (ODL) list is empty. Skipping rest of tests.")
         logger.info(msg)
         # TODO here we need the external ip of the controller
         start_quagga = "odl:configure-bgp -op start-bgp-server " \
                        "--as-num 100 --router-id {0}".format(controller.ip)
-
         test_utils.run_odl_cmd(controller, start_quagga)
 
         logger.info("Checking if bgpd is running"
                     " on the controller node")
 
         # Check if there is a non-zombie bgpd process
-        output_bgpd = controller.run_cmd("ps --no-headers -C bgpd -o state")
+        output_bgpd = controller.run_cmd("ps --no-headers -C "
+                                         "bgpd -o state")
         states = output_bgpd.split()
         running = any([s != 'Z' for s in states])
 
         # logger.info("Checking if bgpd is still running"
         #             " on the controller node")
 
-        # output_bgpd = controller.run_cmd("ps --no-headers -C bgpd -o state")
+        # output_bgpd = controller.run_cmd("ps --no-headers -C " \
+        #                                  "bgpd -o state")
         # states = output_bgpd.split()
         # running = any([s != 'Z' for s in states])