Working with Policies

Working with Policies

Creating a Policy

A policy contains the set of rules that are checked/enforced before or after certain cluster operations are performed. The detailed specification of a specific policy type is provided as the spec of a policy object when it is created. The following is a sample spec for a deletion policy:

# Sample deletion policy that can be attached to a cluster.
type: senlin.policy.deletion
version: 1.0
description: A policy for choosing victim node(s) from a cluster for deletion.
properties:
  # The valid values include:
  # OLDEST_FIRST, OLDEST_PROFILE_FIRST, YOUNGEST_FIRST, RANDOM
  criteria: OLDEST_FIRST

  # Whether deleted node should be destroyed 
  destroy_after_deletion: True

  # Length in number of seconds before the actual deletion happens
  # This param buys an instance some time before deletion
  grace_period: 60

  # Whether the deletion will reduce the desired capacity of
  # the cluster as well
  reduce_desired_capacity: False

Note

The above source file can be found in senlin source tree at /examples/policies/deletion_policy.yaml.

To create a policy object using this specification (spec for short):

$ cd $SENLIN_ROOT/examples/policies
$ senlin policy-create -s deletion_policy.yaml dp01

To verify the policy creation, you can do:

$ senlin policy-list
$ senlin policy-show dp01

Attaching a Policy

The enforce a policy on a cluster, attach a policy to it:

$ senlin cluster-policy-attach -p dp01 mycluster

To verify the policy attach operation, do the following:

$ senlin cluster-policy-list mycluster
$ senlin cluster-policy-show -p dp01 mycluster

Verifying a Policy

To verify the deletion policy attached to the cluster mycluster, you can try expanding the cluster, followed by shrinking it:

$ senlin cluster-node-list mycluster
$ senlin cluster-scale-out mycluster
$ senlin cluster-node-list mycluster
$ senlin cluster-scale-in mycluster
$ senlin cluster-node-list mycluster

After the scale-in operation is completed, you will find that the oldest node from the cluster is removed. If you want to remove the youngest node instead, you can create a different deletion policy with a different specification.

For more details about policy types and policy management, check the Policy Types section and the Policies section in the User Reference documentation respectively. You may also want to check the Cluster-Policy Bindings section in the User Reference for more details on managing the cluster-policy relationship.

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.