diff options
Diffstat (limited to 'sdnvpn/lib/openstack_utils.py')
-rw-r--r-- | sdnvpn/lib/openstack_utils.py | 82 |
1 files changed, 47 insertions, 35 deletions
diff --git a/sdnvpn/lib/openstack_utils.py b/sdnvpn/lib/openstack_utils.py index f0b9ba7..5fc1e49 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,10 +1404,52 @@ def delete_user(keystone_client, user_id): # ********************************************* # HEAT # ********************************************* -def get_resource(heat_client, stack_id, resource): +def create_stack(conn, **kwargs): + try: + 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(orchestration)]: %s" % e) + return None + + +def update_stack(conn, stack_id, **kwargs): + try: + conn.orchestration.update_stack(stack_id, **kwargs) + return True + except Exception as e: + logger.error("Error [update_stack(orchestration)]: %s" % e) + return False + + +def delete_stack(conn, stack_id): try: - resources = heat_client.resources.get(stack_id, resource) - return resources + conn.orchestration.delete_stack(stack_id) + return True except Exception as e: - logger.error("Error [get_resource]: %s" % e) + logger.error("Error [delete_stack(orchestration)]: %s" % e) + return False + + +def list_stacks(conn, **kwargs): + try: + result = conn.orchestration.stacks(**kwargs) + return result + except Exception as e: + logger.error("Error [list_stack(orchestration)]: %s" % e) return None + + +def get_output(conn, stack_id, output_key): + try: + 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 |