Required parameters

The minimum parameters to create a rule are --selector and --label.

Create a rule that configures 2 replicas for volumes with the label env=prod:

$ storageos rule create --namespace default --selector 'env==prod' --label replicator

Optional parameters

Rules also accept the optional parameters --action and --weight.

-a, --action string Rule action (add|remove) (default "add")

Where multiple rules apply to the same label, a weight is used to determine the order of evaluation. Rules are evaluated starting at the lowest weight.

-w, --weight int Rule weight determines processing order, any integer

Using rules

To create a rule that configures 2 replicas for volumes with the label env=prod:

$ storageos rule create --namespace default --selector 'env==prod' --action add --label replicator

View rules:

$ storageos rule ls
default/dev-marker   !   add     env=dev
default/prod-marker>1  add     env=prod
default/replicator   env==prod                 add
default/uat-marker<2  add     env=uat

Inspect a rule:

$ storageos rule inspect default/replicator
        "id": "9db3252a-bd14-885b-0d0a-b0da1dd2d4a1",
        "name": "replicator",
        "namespace": "default",
        "description": "",
        "active": true,
        "weight": 5,
        "action": "add",
        "selector": "env==prod",
        "labels": {
            "": "2"

Then, create a volume:

storageos volume create -n default -s 1 --label env=prod prodVolume

Once it’s created, inspect it:

storageos volume inspect default/prodvolume

You should see that it has two replicas provisioned and additional labels attached:

"labels": {
        "env": "prod",
        "storageos.driver": "filesystem",
        "": "2"

Delete a rule:

$ storageos rule rm default/replicator

Using advanced selectors

Let’s create several rules that instead of adding feature label it would read it’s value and based on it would label volumes with dev/uat/prod env values.

First, create a rule to label dev environments:

storageos rule create --namespace default --selector '!' --action add --label env=dev dev-marker

This rule will be matching volumes that do not have (!) label and will add env=dev label. Now, create a second rule to select volumes that have 1 replica (< 2) and add uat env label to them:

storageos rule create --namespace default --selector '<2' --action add --label env=uat uat-marker

Create new volume with 1 replica:

storageos volume create --namespace default --label uat-volume

Inspect it:

storageos volume inspect default/uat-volume

Labels should look like:

"labels": {
    "env": "uat",
    "storageos.driver": "filesystem",
    "": "1"

Finally, create a rule that will mark volumes as prod if they have 2 or more (gt) configured replicas:

storageos rule create --namespace default --selector '>1' --label env=prod prod-marker

Volumes created with 2 or more replicas should get env=prod label.