From a8beb00ca3ebaf5c11b33f459ecd766eb08b8e20 Mon Sep 17 00:00:00 2001 From: tengqm Date: Sun, 25 Jan 2015 18:58:11 +0800 Subject: [PATCH] Added function to create connection via SDK Connection creation may invole SDK layer exception throwing, we wrap this exception handling into a utility function. --- senlinclient/common/sdk.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/senlinclient/common/sdk.py b/senlinclient/common/sdk.py index d5bb2a71..a311cce2 100644 --- a/senlinclient/common/sdk.py +++ b/senlinclient/common/sdk.py @@ -14,9 +14,11 @@ import argparse import os from openstack import connection +from openstack import exceptions from openstack import user_preference from openstack.identity import identity_service from openstack import resource as base +from senlinclient.common import exc # Alias here for consistency prop = base.prop @@ -115,3 +117,14 @@ class Resource(base.Resource): self._attrs[self.id_attribute] = resp[self.id_attribute] self._reset_dirty() return self, resp + + +def create_connection(preferences, user_agent, **kwargs): + try: + conn = connection.Connection(preference=preferences, + user_agent=user_agent, + **kwargs) + except exceptions.HttpException as ex: + exc.parse_exception(ex.details) + + return conn