Skip to content

Commit 7934570

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Cluster user guide - part 2"
2 parents 6595202 + f72662a commit 7934570

4 files changed

Lines changed: 219 additions & 2 deletions

File tree

doc/source/users/guides/cluster/policy.rst

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,88 @@
1515
Managing Policies
1616
=================
1717

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

doc/source/users/guides/cluster/policy_type.rst

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,31 @@
1515
Working with Policy Types
1616
=========================
1717

18-
.. TODO(Qiming): Implement this guide
18+
A **policy** is a template that encodes the information needed for specifying
19+
the rules that are checked/enforced before/after certain actions are performed
20+
on a cluster. The rules are encoded in a property named ``spec``.
21+
22+
23+
List Policy Types
24+
~~~~~~~~~~~~~~~~~
25+
26+
To examine the known policy types:
27+
28+
.. literalinclude:: ../../examples/cluster/policy_type.py
29+
:pyobject: list_policy_types
30+
31+
Full example: `manage policy type`_
32+
33+
34+
Get Policy Type
35+
~~~~~~~~~~~~~~~
36+
37+
To retrieve the details about a policy type, you need to provide the name of
38+
it.
39+
40+
.. literalinclude:: ../../examples/cluster/policy_type.py
41+
:pyobject: get_policy_type
42+
43+
Full example: `manage policy type`_
44+
45+
.. _manage profile type: http://git.openstack.org/cgit/openstack/python-openstacksdk/tree/examples/cluster/policy_type.py

examples/cluster/policy.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
"""
14+
Managing policies in the Cluster service.
15+
16+
For a full guide see
17+
http://developer.openstack.org/sdks/python/openstacksdk/users/guides/cluster.html
18+
"""
19+
20+
21+
def list_policies(conn):
22+
print("List Policies:")
23+
24+
for policy in conn.cluster.policies():
25+
print(policy.to_dict())
26+
27+
for policy in conn.cluster.policies(sort='name:asc'):
28+
print(policy.to_dict())
29+
30+
31+
def create_policy(conn):
32+
print("Create Policy:")
33+
34+
spec = {
35+
'policy': 'senlin.policy.deletion',
36+
'version': 1.0,
37+
'properties': {
38+
'criteria': 'oldest_first',
39+
'destroy_after_deletion': True,
40+
}
41+
}
42+
43+
policy = conn.cluster.create_policy('dp01', spec)
44+
print(policy.to_dict())
45+
46+
47+
def get_policy(conn):
48+
print("Get Policy:")
49+
50+
policy = conn.cluster.get_policy('dp01')
51+
print(policy.to_dict())
52+
53+
54+
def find_policy(conn):
55+
print("Find Policy:")
56+
57+
policy = conn.cluster.find_policy('dp01')
58+
print(policy.to_dict())
59+
60+
61+
def update_policy(conn):
62+
print("Update Policy:")
63+
64+
policy = conn.cluster.update_policy('dp01', name='dp02')
65+
print(policy.to_dict())
66+
67+
68+
def delete_policy(conn):
69+
print("Delete Policy:")
70+
71+
conn.cluster.delete_policy('dp01')
72+
73+
print("Policy deleted.")

examples/cluster/policy_type.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
"""
14+
Managing policy types in the Cluster service.
15+
16+
For a full guide see
17+
http://developer.openstack.org/sdks/python/openstacksdk/users/guides/cluster.html
18+
"""
19+
20+
21+
def list_policy_types(conn):
22+
print("List Policy Types:")
23+
24+
for pt in conn.cluster.policy_types():
25+
print(pt.to_dict())
26+
27+
28+
def get_policy_type(conn):
29+
print("Get Policy Type:")
30+
31+
pt = conn.cluster.get_policy_type('senlin.policy.deletion-1.0')
32+
33+
print(pt.to_dict())

0 commit comments

Comments
 (0)