summaryrefslogtreecommitdiffstats
path: root/sdnvpn/lib/openstack_utils.py
diff options
context:
space:
mode:
authorStamatis Katsaounis <mokats@intracom-telecom.com>2018-10-15 10:18:27 +0300
committernikoskarandreas <nick@intracom-telecom.com>2018-10-15 14:58:45 +0300
commit90780e7d12b9003955cfbb8ff0155baf75b26323 (patch)
treeec874d93b0a228ea0d5d56c1dfa62677c48f83e6 /sdnvpn/lib/openstack_utils.py
parentcfcb04c938abdcddd76bcdd2375b4a81ea28fa51 (diff)
Replace heat client calls with openstack sdk
JIRA: SDNVPN-220 This patch replaces all calls of heat client with openstack sdk. Change-Id: I75571e8de8c06d144204af787ce240c99faea6d3 Signed-off-by: Stamatis Katsaounis <mokats@intracom-telecom.com>
Diffstat (limited to 'sdnvpn/lib/openstack_utils.py')
-rw-r--r--sdnvpn/lib/openstack_utils.py74
1 files changed, 23 insertions, 51 deletions
diff --git a/sdnvpn/lib/openstack_utils.py b/sdnvpn/lib/openstack_utils.py
index 3fa17e6..cfacfa8 100644
--- a/sdnvpn/lib/openstack_utils.py
+++ b/sdnvpn/lib/openstack_utils.py
@@ -18,19 +18,17 @@ import urllib
from keystoneauth1 import loading
from keystoneauth1 import session
-from cinderclient import client as cinderclient
-from heatclient import client as heatclient
from keystoneclient import client as keystoneclient
from neutronclient.neutron import client as neutronclient
from openstack import connection
from openstack import cloud as os_cloud
+from openstack.exceptions import ResourceNotFound
from functest.utils import env
logger = logging.getLogger(__name__)
DEFAULT_API_VERSION = '2'
-DEFAULT_HEAT_API_VERSION = '1'
# *********************************************
@@ -165,20 +163,6 @@ def get_keystone_client(other_creds={}):
interface=os.getenv('OS_INTERFACE', 'admin'))
-def get_cinder_client_version():
- api_version = os.getenv('OS_VOLUME_API_VERSION')
- if api_version is not None:
- logger.info("OS_VOLUME_API_VERSION is set in env as '%s'",
- api_version)
- return api_version
- return DEFAULT_API_VERSION
-
-
-def get_cinder_client(other_creds={}):
- sess = get_session(other_creds)
- return cinderclient.Client(get_cinder_client_version(), session=sess)
-
-
def get_neutron_client_version():
api_version = os.getenv('OS_NETWORK_API_VERSION')
if api_version is not None:
@@ -193,20 +177,6 @@ def get_neutron_client(other_creds={}):
return neutronclient.Client(get_neutron_client_version(), session=sess)
-def get_heat_client_version():
- api_version = os.getenv('OS_ORCHESTRATION_API_VERSION')
- if api_version is not None:
- logger.info("OS_ORCHESTRATION_API_VERSION is set in env as '%s'",
- api_version)
- return api_version
- return DEFAULT_HEAT_API_VERSION
-
-
-def get_heat_client(other_creds={}):
- sess = get_session(other_creds)
- return heatclient.Client(get_heat_client_version(), session=sess)
-
-
def download_url(url, dest_path):
"""
Download a file to a destination path given a URL
@@ -1434,50 +1404,52 @@ def delete_user(keystone_client, user_id):
# *********************************************
# HEAT
# *********************************************
-def get_resource(heat_client, stack_id, resource):
+def get_resource(conn, stack_id, resource):
try:
- resources = heat_client.resources.get(stack_id, resource)
- return resources
+ resource = conn.orchestration.resources(stack_id, id=resource).next()
+ return resource
except Exception as e:
- logger.error("Error [get_resource]: %s" % e)
+ logger.error("Error [get_resource(orchestration)]: %s" % e)
return None
-def create_stack(heat_client, **kwargs):
+def create_stack(conn, **kwargs):
try:
- stack = heat_client.stacks.create(**kwargs)
- stack_id = stack['stack']['id']
+ stack = conn.orchestration.create_stack(**kwargs)
+ stack_id = stack.id
if stack_id is None:
logger.error("Stack create start failed")
raise SystemError("Stack create start failed")
return stack_id
except Exception as e:
- logger.error("Error [create_stack]: %s" % e)
+ logger.error("Error [create_stack(orchestration)]: %s" % e)
return None
-def delete_stack(heat_client, stack_id):
+def delete_stack(conn, stack_id):
try:
- heat_client.stacks.delete(stack_id)
+ conn.orchestration.delete_stack(stack_id)
return True
except Exception as e:
- logger.error("Error [delete_stack]: %s" % e)
+ logger.error("Error [delete_stack(orchestration)]: %s" % e)
return False
-def list_stack(heat_client, **kwargs):
+def list_stacks(conn, **kwargs):
try:
- result = heat_client.stacks.list(**kwargs)
+ result = conn.orchestration.stacks(**kwargs)
return result
except Exception as e:
- logger.error("Error [list_stack]: %s" % e)
+ logger.error("Error [list_stack(orchestration)]: %s" % e)
return None
-def get_output(heat_client, stack_id, output_key):
+def get_output(conn, stack_id, output_key):
try:
- output = heat_client.stacks.output_show(stack_id, output_key)
- return output
- except Exception as e:
- logger.error("Error [get_output]: %s" % e)
- return None
+ stack = conn.orchestration.get_stack(stack_id)
+ for output in stack.outputs:
+ if output['output_key'] == output_key:
+ return output
+ except ResourceNotFound as e:
+ logger.error("Error [get_output(orchestration)]: %s" % e)
+ return None