diff --git a/senlinclient/common/exc.py b/senlinclient/common/exc.py index a9eabac..dd62bb9 100644 --- a/senlinclient/common/exc.py +++ b/senlinclient/common/exc.py @@ -12,8 +12,8 @@ import six -from oslo_serialization import jsonutils from openstack import exceptions as sdkexc +from oslo_serialization import jsonutils from senlinclient.common.i18n import _ @@ -64,7 +64,8 @@ class HTTPException(BaseException): {'message': message, 'traceback': traceback}) else: code = self.error['error'].get('code', 'Unknown') - return _('ERROR(%s): %s') % (code, message) + return _('ERROR(%(code)s): %(message)s') % {'code': code, + 'message': message} class ClientError(HTTPException): @@ -238,7 +239,7 @@ def parse_exception(exc): record['error']['code'] = code except KeyError as err: print(_('Malformed exception record, missing field "%s"') % err) - print(_('Original error record: %s' % record)) + print(_('Original error record: %s') % record) return if code in _EXCEPTION_MAP: diff --git a/senlinclient/common/sdk.py b/senlinclient/common/sdk.py index a311cce..7540bd5 100644 --- a/senlinclient/common/sdk.py +++ b/senlinclient/common/sdk.py @@ -15,17 +15,16 @@ 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 openstack import user_preference from senlinclient.common import exc # Alias here for consistency prop = base.prop + class UserPreferenceAction(argparse.Action): - ''' - A custom action to parse user preferences as key=value pairs + '''A custom action to parse user preferences as key=value pairs Stores results in users preferences object. ''' @@ -77,16 +76,14 @@ class UserPreferenceAction(argparse.Action): class Resource(base.Resource): - ''' - Senlin version of resource. + '''Senlin version of resource. These classes are here because the OpenStack SDK base version is making some assumptions about operations that cannot be satisfied in Senlin. ''' @classmethod def list_short(cls, session, path_args=None, **params): - ''' - Return a generator that will page through results of GET requests. + '''Return a generator that will page through results of GET requests. This method bypasses the DB session support and retrieves list that is directly exposed by server. @@ -108,8 +105,8 @@ class Resource(base.Resource): yield value def create(self, session): - ''' - Overriden version of the create method. + '''Overriden version of the create method. + We want to know more about the object being created, so the response should not be just thrown away ''' diff --git a/senlinclient/shell.py b/senlinclient/shell.py index 8374551..39ebe4a 100644 --- a/senlinclient/shell.py +++ b/senlinclient/shell.py @@ -33,7 +33,7 @@ from senlinclient.common import sdk from senlinclient.common import utils osprofiler_profiler = importutils.try_import("osprofiler.profiler") -USER_AGENT='python-senlinclient' +USER_AGENT = 'python-senlinclient' LOG = logging.getLogger(__name__) @@ -164,19 +164,19 @@ class SenlinShell(object): 'user ID for authentication') print(_('WARNING: %s') % msg) - if (args.username and not args.user_id) and (not - args.user_domain_id or args.user_domain_name): - msg = _('Either user domain ID (--user-domain-id / ' - 'env[OS_USER_DOMAIN_ID]) or user domain name ' - '(--user-domain-name / env[OS_USER_DOMAIN_NAME ' - 'must be specified, because user name may not be ' - 'unique.') - raise exc.CommandError(msg) + if (args.username and not args.user_id): + if not (args.user_domain_id or args.user_domain_name): + msg = _('Either user domain ID (--user-domain-id / ' + 'env[OS_USER_DOMAIN_ID]) or user domain name ' + '(--user-domain-name / env[OS_USER_DOMAIN_NAME ' + 'must be specified, because user name may not be ' + 'unique.') + raise exc.CommandError(msg) # password is needed if username or user_id is present if (args.username or args.user_id) and not (args.password): msg = _('You must provide a password for user %s') % ( - args.username or args.user_id) + args.username or args.user_id) raise exc.CommandError(msg) # project name or ID is needed, or else sdk may find the wrong project diff --git a/senlinclient/v1/client.py b/senlinclient/v1/client.py index cff466c..b34f7d4 100644 --- a/senlinclient/v1/client.py +++ b/senlinclient/v1/client.py @@ -12,7 +12,6 @@ import inspect import json -import uuid from openstack import exceptions as exc from openstack.identity import identity_service @@ -20,6 +19,7 @@ from openstack.network.v2 import thin as thins from openstack import transport as trans from senlinclient.common import exc as client_exc + class Client(object): def __init__(self, session): self.session = session diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index a8b9ae1..16de644 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -16,7 +16,6 @@ from oslo_serialization import jsonutils from senlinclient.common import exc from senlinclient.common.i18n import _ -from senlinclient.common import sdk from senlinclient.common import utils from senlinclient.v1 import models @@ -557,8 +556,10 @@ def do_node_create(sc, args): } node, resp = sc.create(models.Node, params) - print(_('Action NODE_CREATE(%s) scheduled for ' - 'node %s') % (resp['action_id'], resp['id'])) + print(_('Action NODE_CREATE(%(action)s) scheduled for ' + 'node %(node)s') % { + 'action': resp['action_id'], + 'node': resp['id']}) @utils.arg('id', metavar='<NODE ID>', @@ -590,7 +591,7 @@ def do_node_delete(sc, args): try: query = {'id': nid} sc.delete(models.Node, query) - except exc.HTTPNotFound as ex: + except exc.HTTPNotFound: failure_count += 1 print('Node id "%s" not found' % nid) if failure_count == len(args.id):