A policy type can be treated as the meta-type of a Policy object. A registry of policy types is built when the Cluster service starts. When creating a Policy object, you will indicate the policy type used in its spec property.
To examine the list of policies:
def list_policies(conn):
print("List Policies:")
for policy in conn.cluster.policies():
print(policy.to_dict())
for policy in conn.cluster.policies(sort='name:asc'):
print(policy.to_dict())
When listing policies, you can specify the sorting option using the sort
parameter and you can do pagination using the limit
and marker
parameters.
Full example: manage policy
When creating a policy, you will provide a dictionary with keys and values according to the policy type referenced.
def create_policy(conn):
print("Create Policy:")
spec = {
'policy': 'senlin.policy.deletion',
'version': 1.0,
'properties': {
'criteria': 'oldest_first',
'destroy_after_deletion': True,
}
}
policy = conn.cluster.create_policy('dp01', spec)
print(policy.to_dict())
Optionally, you can specify a metadata
keyword argument that contains some
key-value pairs to be associated with the policy.
Full example: manage policy
To find a policy based on its name or ID:
def find_policy(conn):
print("Find Policy:")
policy = conn.cluster.find_policy('dp01')
print(policy.to_dict())
Full example: manage policy
To get a policy based on its name or ID:
def get_policy(conn):
print("Get Policy:")
policy = conn.cluster.get_policy('dp01')
print(policy.to_dict())
Full example: manage policy
After a policy is created, most of its properties are immutable. Still, you
can update a policy’s name
and/or metadata
.
def update_policy(conn):
print("Update Policy:")
policy = conn.cluster.update_policy('dp01', name='dp02')
print(policy.to_dict())
The Cluster service doesn’t allow updating the spec
of a policy. The only
way to achieve that is to create a new policy.
Full example: manage policy
A policy can be deleted after creation, provided that it is not referenced by any active clusters or nodes. If you attempt to delete a policy that is still in use, you will get an error message.
def delete_policy(conn):
print("Delete Policy:")
conn.cluster.delete_policy('dp01')
print("Policy deleted.")
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.