Merge "Move session creation up to shell"

This commit is contained in:
Jenkins 2014-11-20 20:13:32 +00:00 committed by Gerrit Code Review
commit 14803b7ef0
2 changed files with 40 additions and 24 deletions

View File

@ -27,31 +27,11 @@ from designateclient.v1 import Client
@six.add_metaclass(abc.ABCMeta)
class Command(CliffCommand):
def run(self, parsed_args):
kwargs = {
'endpoint': self.app.options.os_endpoint,
'username': self.app.options.os_username,
'user_id': self.app.options.os_user_id,
'user_domain_id': self.app.options.os_user_domain_id,
'user_domain_name': self.app.options.os_user_domain_name,
'password': self.app.options.os_password,
'tenant_name': self.app.options.os_tenant_name,
'tenant_id': self.app.options.os_tenant_id,
'domain_name': self.app.options.os_domain_name,
'domain_id': self.app.options.os_domain_id,
'project_name': self.app.options.os_project_name,
'project_id': self.app.options.os_project_id,
'project_domain_name': self.app.options.os_project_domain_name,
'project_domain_id': self.app.options.os_project_domain_id,
'auth_url': self.app.options.os_auth_url,
'token': self.app.options.os_token,
'endpoint_type': self.app.options.os_endpoint_type,
'service_type': self.app.options.os_service_type,
'insecure': self.app.options.insecure,
}
self.client = Client(**kwargs)
self.client = Client(
region_name=self.app.options.os_region_name,
service_type=self.app.options.os_service_type,
session=self.app.session)
try:
return super(Command, self).run(parsed_args)

View File

@ -20,6 +20,8 @@ import traceback
from cliff.app import App
from cliff.commandmanager import CommandManager
from keystoneclient.auth.identity import generic
from keystoneclient import session as ks_session
from designateclient.version import version_info as version
@ -202,6 +204,40 @@ class DesignateShell(App):
# --debug forces traceback
self.dump_stack_trace = True
def initialize_app(self, argv):
super(DesignateShell, self).initialize_app(argv)
self.session = self.get_session()
def get_session(self):
session = ks_session.Session()
auth_args = {
'auth_url': self.options.os_auth_url,
'domain_id': self.options.os_domain_id,
'domain_name': self.options.os_domain_name,
'project_id': self.options.os_project_id,
'project_name': self.options.os_project_name,
'project_domain_name': self.options.os_project_domain_name,
'project_domain_id': self.options.os_project_domain_id,
'tenant_id': self.options.os_tenant_id,
'tenant_name': self.options.os_tenant_name,
}
if self.options.os_token:
auth_args['token'] = self.options.os_token
session.auth = generic.Token(**auth_args)
else:
password_args = {
'username': self.options.os_username,
'user_id': self.options.os_user_id,
'user_domain_id': self.options.os_user_domain_id,
'user_domain_name': self.options.os_user_domain_name,
'password': self.options.os_password
}
auth_args.update(password_args)
session.auth = generic.Password(**auth_args)
return session
def run(self, argv):
try:
return super(DesignateShell, self).run(argv)