|
15 | 15 | Managing Policies |
16 | 16 | ================= |
17 | 17 |
|
18 | | -.. TODO(Qiming): Implement this guide |
| 18 | +A **policy type** can be treated as the meta-type of a `Policy` object. A |
| 19 | +registry of policy types is built when the Cluster service starts. When |
| 20 | +creating a `Policy` object, you will indicate the policy type used in its |
| 21 | +`spec` property. |
| 22 | + |
| 23 | + |
| 24 | +List Policies |
| 25 | +~~~~~~~~~~~~~ |
| 26 | + |
| 27 | +To examine the list of policies: |
| 28 | + |
| 29 | +.. literalinclude:: ../../examples/cluster/policy.py |
| 30 | + :pyobject: list_policys |
| 31 | + |
| 32 | +When listing policies, you can specify the sorting option using the ``sort`` |
| 33 | +parameter and you can do pagination using the ``limit`` and ``marker`` |
| 34 | +parameters. |
| 35 | + |
| 36 | +Full example: `manage policy`_ |
| 37 | + |
| 38 | + |
| 39 | +Create Policy |
| 40 | +~~~~~~~~~~~~~ |
| 41 | + |
| 42 | +When creating a policy, you will provide a dictionary with keys and values |
| 43 | +according to the policy type referenced. |
| 44 | + |
| 45 | +.. literalinclude:: ../../examples/cluster/policy.py |
| 46 | + :pyobject: create_policy |
| 47 | + |
| 48 | +Optionally, you can specify a ``metadata`` keyword argument that contains some |
| 49 | +key-value pairs to be associated with the policy. |
| 50 | + |
| 51 | +Full example: `manage policy`_ |
| 52 | + |
| 53 | + |
| 54 | +Find Policy |
| 55 | +~~~~~~~~~~~ |
| 56 | + |
| 57 | +To find a policy based on its name or ID: |
| 58 | + |
| 59 | +.. literalinclude:: ../../examples/cluster/policy.py |
| 60 | + :pyobject: find_policy |
| 61 | + |
| 62 | +Full example: `manage policy`_ |
| 63 | + |
| 64 | + |
| 65 | +Get Policy |
| 66 | +~~~~~~~~~~ |
| 67 | + |
| 68 | +To get a policy based on its name or ID: |
| 69 | + |
| 70 | +.. literalinclude:: ../../examples/cluster/policy.py |
| 71 | + :pyobject: get_policy |
| 72 | + |
| 73 | +Full example: `manage policy`_ |
| 74 | + |
| 75 | + |
| 76 | +Update Policy |
| 77 | +~~~~~~~~~~~~~ |
| 78 | + |
| 79 | +After a policy is created, most of its properties are immutable. Still, you |
| 80 | +can update a policy's ``name`` and/or ``metadata``. |
| 81 | + |
| 82 | +.. literalinclude:: ../../examples/cluster/policy.py |
| 83 | + :pyobject: update_policy |
| 84 | + |
| 85 | +The Cluster service doesn't allow updating the ``spec`` of a policy. The only |
| 86 | +way to achieve that is to create a new policy. |
| 87 | + |
| 88 | +Full example: `manage policy`_ |
| 89 | + |
| 90 | + |
| 91 | +Delete Policy |
| 92 | +~~~~~~~~~~~~~ |
| 93 | + |
| 94 | +A policy can be deleted after creation, provided that it is not referenced |
| 95 | +by any active clusters or nodes. If you attempt to delete a policy that is |
| 96 | +still in use, you will get an error message. |
| 97 | + |
| 98 | +.. literalinclude:: ../../examples/cluster/policy.py |
| 99 | + :pyobject: delete_policy |
| 100 | + |
| 101 | + |
| 102 | +.. _manage policy: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/cluster/policy.py |
0 commit comments