Rules

The Rules Object is a container of the Rule Objects for the associated policy.

Rules is typically accessed and instantiated via the Policy Object.

Description

class arcapix.fs.gpfs.rules.Rules

The rules class holds a collection of policy rules

new(ruleType, *args, **kwargs)

Create a new Rule

Parameters:
Returns:

Newly created Rule

Return type:

Rule

destroy(rule)

Destroy an unwanted rule

Parameters:rule (Rule or str) – The rule to destroy
addComment(comment)

Deprecated since version 0.6: Use new() instead

Add a new comment line to the policy

Parameters:comment – Comment string to add
addMacro(variableName, expression)

Deprecated since version 0.6: Use new() instead

Add a new macro to the policy

Parameters:
  • variableName – Name of the macro you’d like to define
  • expression – A SQL expression
macros()

Returns a list of user-defined macros

Return type:dict of Macro
comments()

Returns a list of comments

Return type:dict of str
defaultPlacement

Returns the default placement rule if one exists, else None

Return type:Rule
swap(rule1, rule2)

Switch the order of two rules

Param:Two Rules to swap
Type:Rule or str
insert(rule, index=-1)

Insert a new rule at the given index

Parameters:
  • rule (Rule) – rule to insert
  • index (int) – position at which to insert the rule

Examples

Creating a default Placement Policy

>>> from arcapix.fs.gpfs import Filesystem, SetPoolRule
>>>
>>> # Get the placement policy object for Filesystem 'mmfs1'
... mypolicy = Filesystem('mmfs1').policy
>>>
>>> # Create a new 'Set Pool' rule
... mypolicy.rules.new(SetPoolRule, name='default', target='system')
>>>
>>> # Validate
... mypolicy.validate()
>>>
>>> # Apply policy to parent filesystem
... mypolicy.save()

Create a policy with comments, macros and includes

>>> from arcapix.fs.gpfs import ManagementPolicy, Criteria,
>>> from arcapix.fs.gpfs.rule import DeleteRule, Comment, Macro, Include
>>>
>>> # Get the placement policy object for Filesystem 'mmfs1'
... mypolicy = ManagementPolicy()
>>>
>>> # add include
... mypolicy.rules.new(Include, "/mmfs1/policies/SA/pixit_excludes.m4")
>>>
>>> # Add a comment
... mypolicy.rules.new(Comment, "Macro Definitions")
>>>
>>> # Add a macro
... mypolicy.rules.new(Macro, "LAST_ACCESS", "(DAYS(CURRENT_TIMESTAMP) - DAYS(ACCESS_TIME))")
>>>
>>> # Add another comment
... mypolicy.rules.new(Comment, "Policy Rules")
>>>
>>> # Add new rule
... r = mypolicy.rules.new(DeleteRule, source="sata1")
>>>
>>> # Add criteria using macro
... r.criteria.new(Criteria.lt("LAST_ACCESS", 30))
>>>
>>> # Print rule string
... for x in mypolicy.rules.values():
...    print(x.toGpfsString() + "\n")
...
include(/mmfs1/policies/SA/pixit_excludes.m4)

/* Macro Definitions */

define(LAST_ACCESS,(DAYS(CURRENT_TIMESTAMP) - DAYS(ACCESS_TIME)))

/* Policy Rules */

RULE DELETE FROM POOL sata1
 WHERE LAST_ACCESS < 30

Iterating Rule from the Rules Object

>>> from arcapix.fs.gpfs import Filesystem
>>>
>>> # Get the placement policy object for Filesystem 'mmfs1'
... mypolicy = Filesystem('mmfs1').policy
>>>
>>> # Print the names and types of all rules in the management policy of 'mmfs1'
>>> for r in mypolicy.rules.values():
...     print("{0}\t\t{1}".format(r.name, r.type))
...
del1            DELETE
year-old        MIGRATE
3month-old      MIGRATE

Switch the order of two rules

>>> from arcapix.fs.gpfs import ManagementPolicy, DeleteRule
>>>
>>> # Create a new Management Policy
... mypolicy = ManagementPolicy()
>>>
>>> # Create new rules
... mypolicy.rules.new(DeleteRule, name="del1")
... mypolicy.rules.new(DeleteRule, name="year-old")
... mypolicy.rules.new(DeleteRule, name="3month-old")
>>>
>>> # Current order
... print(mypolicy.rules)
Rules: ('del1', 'year-old', '3month-old')
>>>
>>> # Swap del1 and year-old
... mypolicy.rules.swap('del1', 'year-old')
>>>
>>> # New order
... print(mypolicy.rules)
Rules: ('year-old', 'del1', '3month-old')