Merge "Add --or-show support for v3 identity resources"
This commit is contained in:
@@ -22,8 +22,10 @@ import sys
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
from cliff import show
|
||||||
|
from keystoneclient.openstack.common.apiclient import exceptions as ksc_exc
|
||||||
|
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
|
from openstackclient.i18n import _ # noqa
|
||||||
|
|
||||||
|
|
||||||
class CreateDomain(show.ShowOne):
|
class CreateDomain(show.ShowOne):
|
||||||
@@ -55,16 +57,30 @@ class CreateDomain(show.ShowOne):
|
|||||||
dest='enabled',
|
dest='enabled',
|
||||||
action='store_false',
|
action='store_false',
|
||||||
help='Disable domain')
|
help='Disable domain')
|
||||||
|
parser.add_argument(
|
||||||
|
'--or-show',
|
||||||
|
action='store_true',
|
||||||
|
help=_('Return existing domain'),
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
|
|
||||||
|
try:
|
||||||
domain = identity_client.domains.create(
|
domain = identity_client.domains.create(
|
||||||
name=parsed_args.name,
|
name=parsed_args.name,
|
||||||
description=parsed_args.description,
|
description=parsed_args.description,
|
||||||
enabled=parsed_args.enabled,
|
enabled=parsed_args.enabled,
|
||||||
)
|
)
|
||||||
|
except ksc_exc.Conflict as e:
|
||||||
|
if parsed_args.or_show:
|
||||||
|
domain = utils.find_resource(identity_client.domains,
|
||||||
|
parsed_args.name)
|
||||||
|
self.log.info('Returning existing domain %s', domain.name)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
domain._info.pop('links')
|
domain._info.pop('links')
|
||||||
return zip(*sorted(six.iteritems(domain._info)))
|
return zip(*sorted(six.iteritems(domain._info)))
|
||||||
|
@@ -22,8 +22,10 @@ import sys
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
from cliff import show
|
||||||
|
from keystoneclient.openstack.common.apiclient import exceptions as ksc_exc
|
||||||
|
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
|
from openstackclient.i18n import _ # noqa
|
||||||
from openstackclient.identity import common
|
from openstackclient.identity import common
|
||||||
|
|
||||||
|
|
||||||
@@ -122,7 +124,11 @@ class CreateGroup(show.ShowOne):
|
|||||||
'--domain',
|
'--domain',
|
||||||
metavar='<group-domain>',
|
metavar='<group-domain>',
|
||||||
help='References the domain ID or name which owns the group')
|
help='References the domain ID or name which owns the group')
|
||||||
|
parser.add_argument(
|
||||||
|
'--or-show',
|
||||||
|
action='store_true',
|
||||||
|
help=_('Return existing group'),
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@@ -133,10 +139,20 @@ class CreateGroup(show.ShowOne):
|
|||||||
parsed_args.domain).id
|
parsed_args.domain).id
|
||||||
else:
|
else:
|
||||||
domain = None
|
domain = None
|
||||||
|
|
||||||
|
try:
|
||||||
group = identity_client.groups.create(
|
group = identity_client.groups.create(
|
||||||
name=parsed_args.name,
|
name=parsed_args.name,
|
||||||
domain=domain,
|
domain=domain,
|
||||||
description=parsed_args.description)
|
description=parsed_args.description)
|
||||||
|
except ksc_exc.Conflict as e:
|
||||||
|
if parsed_args.or_show:
|
||||||
|
group = utils.find_resource(identity_client.groups,
|
||||||
|
parsed_args.name,
|
||||||
|
domain_id=domain)
|
||||||
|
self.log.info('Returning existing group %s', group.name)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
group._info.pop('links')
|
group._info.pop('links')
|
||||||
return zip(*sorted(six.iteritems(group._info)))
|
return zip(*sorted(six.iteritems(group._info)))
|
||||||
|
@@ -21,9 +21,11 @@ import six
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
from cliff import show
|
||||||
|
from keystoneclient.openstack.common.apiclient import exceptions as ksc_exc
|
||||||
|
|
||||||
from openstackclient.common import parseractions
|
from openstackclient.common import parseractions
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
|
from openstackclient.i18n import _ # noqa
|
||||||
from openstackclient.identity import common
|
from openstackclient.identity import common
|
||||||
|
|
||||||
|
|
||||||
@@ -67,6 +69,11 @@ class CreateProject(show.ShowOne):
|
|||||||
help='Property to add for this project '
|
help='Property to add for this project '
|
||||||
'(repeat option to set multiple properties)',
|
'(repeat option to set multiple properties)',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--or-show',
|
||||||
|
action='store_true',
|
||||||
|
help=_('Return existing project'),
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@@ -86,6 +93,7 @@ class CreateProject(show.ShowOne):
|
|||||||
if parsed_args.property:
|
if parsed_args.property:
|
||||||
kwargs = parsed_args.property.copy()
|
kwargs = parsed_args.property.copy()
|
||||||
|
|
||||||
|
try:
|
||||||
project = identity_client.projects.create(
|
project = identity_client.projects.create(
|
||||||
name=parsed_args.name,
|
name=parsed_args.name,
|
||||||
domain=domain,
|
domain=domain,
|
||||||
@@ -93,6 +101,14 @@ class CreateProject(show.ShowOne):
|
|||||||
enabled=enabled,
|
enabled=enabled,
|
||||||
**kwargs
|
**kwargs
|
||||||
)
|
)
|
||||||
|
except ksc_exc.Conflict as e:
|
||||||
|
if parsed_args.or_show:
|
||||||
|
project = utils.find_resource(identity_client.projects,
|
||||||
|
parsed_args.name,
|
||||||
|
domain_id=domain)
|
||||||
|
self.log.info('Returning existing project %s', project.name)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
project._info.pop('links')
|
project._info.pop('links')
|
||||||
return zip(*sorted(six.iteritems(project._info)))
|
return zip(*sorted(six.iteritems(project._info)))
|
||||||
|
@@ -22,8 +22,10 @@ import sys
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
from cliff import show
|
||||||
|
from keystoneclient.openstack.common.apiclient import exceptions as ksc_exc
|
||||||
|
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
|
from openstackclient.i18n import _ # noqa
|
||||||
|
|
||||||
|
|
||||||
class AddRole(command.Command):
|
class AddRole(command.Command):
|
||||||
@@ -149,13 +151,26 @@ class CreateRole(show.ShowOne):
|
|||||||
metavar='<role-name>',
|
metavar='<role-name>',
|
||||||
help='New role name',
|
help='New role name',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--or-show',
|
||||||
|
action='store_true',
|
||||||
|
help=_('Return existing role'),
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)', parsed_args)
|
self.log.debug('take_action(%s)', parsed_args)
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
|
|
||||||
|
try:
|
||||||
role = identity_client.roles.create(name=parsed_args.name)
|
role = identity_client.roles.create(name=parsed_args.name)
|
||||||
|
except ksc_exc.Conflict as e:
|
||||||
|
if parsed_args.or_show:
|
||||||
|
role = utils.find_resource(identity_client.roles,
|
||||||
|
parsed_args.name)
|
||||||
|
self.log.info('Returning existing role %s', role.name)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
role._info.pop('links')
|
role._info.pop('links')
|
||||||
return zip(*sorted(six.iteritems(role._info)))
|
return zip(*sorted(six.iteritems(role._info)))
|
||||||
|
@@ -21,8 +21,10 @@ import six
|
|||||||
from cliff import command
|
from cliff import command
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
from cliff import show
|
from cliff import show
|
||||||
|
from keystoneclient.openstack.common.apiclient import exceptions as ksc_exc
|
||||||
|
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
|
from openstackclient.i18n import _ # noqa
|
||||||
from openstackclient.identity import common
|
from openstackclient.identity import common
|
||||||
|
|
||||||
|
|
||||||
@@ -80,6 +82,11 @@ class CreateUser(show.ShowOne):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help='Disable user',
|
help='Disable user',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--or-show',
|
||||||
|
action='store_true',
|
||||||
|
help=_('Return existing user'),
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@@ -106,6 +113,7 @@ class CreateUser(show.ShowOne):
|
|||||||
if parsed_args.password_prompt:
|
if parsed_args.password_prompt:
|
||||||
parsed_args.password = utils.get_password(self.app.stdin)
|
parsed_args.password = utils.get_password(self.app.stdin)
|
||||||
|
|
||||||
|
try:
|
||||||
user = identity_client.users.create(
|
user = identity_client.users.create(
|
||||||
name=parsed_args.name,
|
name=parsed_args.name,
|
||||||
domain=domain_id,
|
domain=domain_id,
|
||||||
@@ -115,6 +123,14 @@ class CreateUser(show.ShowOne):
|
|||||||
description=parsed_args.description,
|
description=parsed_args.description,
|
||||||
enabled=enabled
|
enabled=enabled
|
||||||
)
|
)
|
||||||
|
except ksc_exc.Conflict as e:
|
||||||
|
if parsed_args.or_show:
|
||||||
|
user = utils.find_resource(identity_client.users,
|
||||||
|
parsed_args.name,
|
||||||
|
domain_id=domain_id)
|
||||||
|
self.log.info('Returning existing user %s', user.name)
|
||||||
|
else:
|
||||||
|
raise e
|
||||||
|
|
||||||
user._info.pop('links')
|
user._info.pop('links')
|
||||||
return zip(*sorted(six.iteritems(user._info)))
|
return zip(*sorted(six.iteritems(user._info)))
|
||||||
|
Reference in New Issue
Block a user