Command doc: policy
Also tweaked a bunch of the code to not show 'blob', but 'rules' instead. Change-Id: I6db798d272ff416a77f169c0e912d2096fa02504
This commit is contained in:
parent
a7a1a576e0
commit
673e0d88ff
95
doc/source/command-objects/policy.rst
Normal file
95
doc/source/command-objects/policy.rst
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
======
|
||||||
|
policy
|
||||||
|
======
|
||||||
|
|
||||||
|
Identity v3
|
||||||
|
|
||||||
|
policy create
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Create new policy
|
||||||
|
|
||||||
|
.. program:: policy create
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
os policy create
|
||||||
|
[--type <type>]
|
||||||
|
<filename>
|
||||||
|
|
||||||
|
.. option:: --type <type>
|
||||||
|
|
||||||
|
New MIME type of the policy rules file (defaults to application/json)
|
||||||
|
|
||||||
|
.. describe:: <filename>
|
||||||
|
|
||||||
|
New serialized policy rules file
|
||||||
|
|
||||||
|
policy delete
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Delete policy
|
||||||
|
|
||||||
|
.. program:: policy delete
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
os policy delete
|
||||||
|
<policy>
|
||||||
|
|
||||||
|
.. describe:: <policy>
|
||||||
|
|
||||||
|
Policy to delete
|
||||||
|
|
||||||
|
policy list
|
||||||
|
-----------
|
||||||
|
|
||||||
|
List policies
|
||||||
|
|
||||||
|
.. program:: policy list
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
os policy list
|
||||||
|
[--long]
|
||||||
|
|
||||||
|
.. option:: --long
|
||||||
|
|
||||||
|
List additional fields in output
|
||||||
|
|
||||||
|
policy set
|
||||||
|
----------
|
||||||
|
|
||||||
|
Set policy properties
|
||||||
|
|
||||||
|
.. program:: policy set
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
os policy set
|
||||||
|
[--type <type>]
|
||||||
|
[--rules <filename>]
|
||||||
|
<policy>
|
||||||
|
|
||||||
|
.. option:: --type <type>
|
||||||
|
|
||||||
|
New MIME type of the policy rules file
|
||||||
|
|
||||||
|
.. describe:: --rules <filename>
|
||||||
|
|
||||||
|
New serialized policy rules file
|
||||||
|
|
||||||
|
.. describe:: <policy>
|
||||||
|
|
||||||
|
Policy to modify
|
||||||
|
|
||||||
|
policy show
|
||||||
|
-----------
|
||||||
|
|
||||||
|
Display policy details
|
||||||
|
|
||||||
|
.. program:: policy show
|
||||||
|
.. code:: bash
|
||||||
|
|
||||||
|
os policy show
|
||||||
|
<policy>
|
||||||
|
|
||||||
|
.. describe:: <policy>
|
||||||
|
|
||||||
|
Policy to display
|
@ -98,7 +98,7 @@ referring to both Compute and Volume quotas.
|
|||||||
* ``module``: internal - installed Python modules in the OSC process
|
* ``module``: internal - installed Python modules in the OSC process
|
||||||
* ``network``: Network - a virtual network for connecting servers and other resources
|
* ``network``: Network - a virtual network for connecting servers and other resources
|
||||||
* ``object``: (**Object Store**) a single file in the Object Store
|
* ``object``: (**Object Store**) a single file in the Object Store
|
||||||
* ``policy``: Identity - determines authorization
|
* ``policy``: (**Identity**) determines authorization
|
||||||
* ``project``: (**Identity**) owns a group of resources
|
* ``project``: (**Identity**) owns a group of resources
|
||||||
* ``quota``: (**Compute**, **Volume**) resource usage restrictions
|
* ``quota``: (**Compute**, **Volume**) resource usage restrictions
|
||||||
* ``region``: (**Identity**) a subset of an OpenStack deployment
|
* ``region``: (**Identity**) a subset of an OpenStack deployment
|
||||||
|
@ -27,7 +27,7 @@ from openstackclient.common import utils
|
|||||||
|
|
||||||
|
|
||||||
class CreatePolicy(show.ShowOne):
|
class CreatePolicy(show.ShowOne):
|
||||||
"""Create policy command"""
|
"""Create new policy"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.CreatePolicy')
|
log = logging.getLogger(__name__ + '.CreatePolicy')
|
||||||
|
|
||||||
@ -35,20 +35,21 @@ class CreatePolicy(show.ShowOne):
|
|||||||
parser = super(CreatePolicy, self).get_parser(prog_name)
|
parser = super(CreatePolicy, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--type',
|
'--type',
|
||||||
metavar='<policy-type>',
|
metavar='<type>',
|
||||||
default="application/json",
|
default="application/json",
|
||||||
help='New MIME type of the policy blob - i.e.: application/json',
|
help='New MIME type of the policy rules file '
|
||||||
|
'(defaults to application/json)',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'blob_file',
|
'rules',
|
||||||
metavar='<blob-file>',
|
metavar='<filename>',
|
||||||
help='New policy rule set itself, as a serialized blob, in a file',
|
help='New serialized policy rules file',
|
||||||
)
|
)
|
||||||
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)
|
||||||
blob = utils.read_blob_file_contents(parsed_args.blob_file)
|
blob = utils.read_blob_file_contents(parsed_args.rules)
|
||||||
|
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
policy = identity_client.policies.create(
|
policy = identity_client.policies.create(
|
||||||
@ -56,11 +57,12 @@ class CreatePolicy(show.ShowOne):
|
|||||||
)
|
)
|
||||||
|
|
||||||
policy._info.pop('links')
|
policy._info.pop('links')
|
||||||
|
policy._info.update({'rules': policy._info.pop('blob')})
|
||||||
return zip(*sorted(six.iteritems(policy._info)))
|
return zip(*sorted(six.iteritems(policy._info)))
|
||||||
|
|
||||||
|
|
||||||
class DeletePolicy(command.Command):
|
class DeletePolicy(command.Command):
|
||||||
"""Delete policy command"""
|
"""Delete policy"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.DeletePolicy')
|
log = logging.getLogger(__name__ + '.DeletePolicy')
|
||||||
|
|
||||||
@ -68,8 +70,8 @@ class DeletePolicy(command.Command):
|
|||||||
parser = super(DeletePolicy, self).get_parser(prog_name)
|
parser = super(DeletePolicy, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'policy',
|
'policy',
|
||||||
metavar='<policy-id>',
|
metavar='<policy>',
|
||||||
help='ID of policy to delete',
|
help='Policy to delete',
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -81,28 +83,30 @@ class DeletePolicy(command.Command):
|
|||||||
|
|
||||||
|
|
||||||
class ListPolicy(lister.Lister):
|
class ListPolicy(lister.Lister):
|
||||||
"""List policy command"""
|
"""List policies"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.ListPolicy')
|
log = logging.getLogger(__name__ + '.ListPolicy')
|
||||||
|
|
||||||
def get_parser(self, prog_name):
|
def get_parser(self, prog_name):
|
||||||
parser = super(ListPolicy, self).get_parser(prog_name)
|
parser = super(ListPolicy, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--include-blob',
|
'--long',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='Additional fields are listed in output',
|
help='List additional fields in output',
|
||||||
)
|
)
|
||||||
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)
|
||||||
if parsed_args.include_blob:
|
if parsed_args.long:
|
||||||
columns = ('ID', 'Type', 'Blob')
|
columns = ('ID', 'Type', 'Blob')
|
||||||
|
column_headers = ('ID', 'Type', 'Rules')
|
||||||
else:
|
else:
|
||||||
columns = ('ID', 'Type')
|
columns = ('ID', 'Type')
|
||||||
|
column_headers = columns
|
||||||
data = self.app.client_manager.identity.policies.list()
|
data = self.app.client_manager.identity.policies.list()
|
||||||
return (columns,
|
return (column_headers,
|
||||||
(utils.get_item_properties(
|
(utils.get_item_properties(
|
||||||
s, columns,
|
s, columns,
|
||||||
formatters={},
|
formatters={},
|
||||||
@ -110,7 +114,7 @@ class ListPolicy(lister.Lister):
|
|||||||
|
|
||||||
|
|
||||||
class SetPolicy(command.Command):
|
class SetPolicy(command.Command):
|
||||||
"""Set policy command"""
|
"""Set policy properties"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.SetPolicy')
|
log = logging.getLogger(__name__ + '.SetPolicy')
|
||||||
|
|
||||||
@ -118,18 +122,18 @@ class SetPolicy(command.Command):
|
|||||||
parser = super(SetPolicy, self).get_parser(prog_name)
|
parser = super(SetPolicy, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'policy',
|
'policy',
|
||||||
metavar='<policy-id>',
|
metavar='<policy>',
|
||||||
help='ID of policy to change',
|
help='Policy to modify',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--type',
|
'--type',
|
||||||
metavar='<policy-type>',
|
metavar='<type>',
|
||||||
help='New MIME Type of the policy blob - i.e.: application/json',
|
help='New MIME type of the policy rules file',
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--blob-file',
|
'--rules',
|
||||||
metavar='<blob_file>',
|
metavar='<filename>',
|
||||||
help='New policy rule set itself, as a serialized blob, in a file',
|
help='New serialized policy rules file',
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -138,8 +142,8 @@ class SetPolicy(command.Command):
|
|||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
blob = None
|
blob = None
|
||||||
|
|
||||||
if parsed_args.blob_file:
|
if parsed_args.rules:
|
||||||
blob = utils.read_blob_file_contents(parsed_args.blob_file)
|
blob = utils.read_blob_file_contents(parsed_args.rules)
|
||||||
|
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if blob:
|
if blob:
|
||||||
@ -148,14 +152,14 @@ class SetPolicy(command.Command):
|
|||||||
kwargs['type'] = parsed_args.type
|
kwargs['type'] = parsed_args.type
|
||||||
|
|
||||||
if not kwargs:
|
if not kwargs:
|
||||||
sys.stdout.write("Policy not updated, no arguments present \n")
|
sys.stdout.write('Policy not updated, no arguments present \n')
|
||||||
return
|
return
|
||||||
identity_client.policies.update(parsed_args.policy, **kwargs)
|
identity_client.policies.update(parsed_args.policy, **kwargs)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
class ShowPolicy(show.ShowOne):
|
class ShowPolicy(show.ShowOne):
|
||||||
"""Show policy command"""
|
"""Display policy details"""
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.ShowPolicy')
|
log = logging.getLogger(__name__ + '.ShowPolicy')
|
||||||
|
|
||||||
@ -163,8 +167,8 @@ class ShowPolicy(show.ShowOne):
|
|||||||
parser = super(ShowPolicy, self).get_parser(prog_name)
|
parser = super(ShowPolicy, self).get_parser(prog_name)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'policy',
|
'policy',
|
||||||
metavar='<policy-id>',
|
metavar='<policy>',
|
||||||
help='ID of policy to display',
|
help='Policy to display',
|
||||||
)
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
@ -175,4 +179,5 @@ class ShowPolicy(show.ShowOne):
|
|||||||
parsed_args.policy)
|
parsed_args.policy)
|
||||||
|
|
||||||
policy._info.pop('links')
|
policy._info.pop('links')
|
||||||
|
policy._info.update({'rules': policy._info.pop('blob')})
|
||||||
return zip(*sorted(six.iteritems(policy._info)))
|
return zip(*sorted(six.iteritems(policy._info)))
|
||||||
|
Loading…
Reference in New Issue
Block a user