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.
  # The valid values include:
  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


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
$ openstack cluster policy create --spec-file deletion_policy.yaml dp01

To verify the policy creation, you can do:

$ openstack cluster policy list
$ openstack cluster policy show dp01

Attaching a Policy

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

$ openstack cluster policy attach --policy dp01 mycluster

To verify the policy attach operation, do the following:

$ openstack cluster policy binding list mycluster
$ openstack cluster policy binding show --policy 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:

$ openstack cluster members list mycluster
$ openstack cluster expand mycluster
$ openstack cluster members list mycluster
$ openstack cluster shrink mycluster
$ openstack cluster members 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 3 User References documentation respectively. You may also want to check the Cluster-Policy Bindings section in the 3 User References section for more details on managing the cluster-policy relationship.