Criteria¶
A Criteria object holds a collection of criteria, which specify what conditions a file must meet to be selected
for the parent Rule
.
The following files attributes are supported for criteria:
|
|
|
|
The following short attributes are also supported:
- access - days since the file was last accessed
- change - days since the file was last changed
- creation - days since the file was created
- modification - days since the file was last modified
- size - synonym for file_size
- user - synonym for user_id
- group - synonym for group_id
- fileset - synonym for fileset_name
- pool - synonym for pool_name
- path - synonym for path_name
Attribute names are case insensitive, though the values of those attributes may not be.
Description¶
-
class
arcapix.fs.gpfs.criteria.
Criteria
¶ Criteria are conditions that a file must match to be selected (or excluded) in a policy
-
new
(*criterion)¶ Create a new Criterion
Multiple new criteria can be created at once
-
destroy
(criterion)¶ Delete a Criterion
-
clear
()¶ Delete all existing criteria
-
static
Or
(*criterion)¶ Combine multiple criteria with OR
-
static
Not
(criterion)¶ Negate a criterion.
-
static
like
(attr, pattern, exclude=False, caseInsensitive=False, sql_wildcards=None)¶ Match a file attribute to a (string) pattern
Parameters: - attr – file atribute to compare
- pattern (str) – pattern to compare attribute against
- exclude (bool) – exclude any files with attribute which matches pattern
- caseInsensitive (bool) – ignore case when comparing attribute
- sql_wildcards (bool) – use SQL wildcards ‘%’ and ‘_’ if True, or POSIX wildcards ‘?’ and ‘*’ if False
Deprecated since version 0.16:
sql_wildcard
is None by default. This uses the legacy behaviour of replacing POSIX wildcards with SQL wildcards, and leaving ‘%’ and ‘_’ unchangedNote
If the pattern contains a single quote, it will be automatically escaped. This means the quote will be doubled up, e.g.
single'quote
->single''quote
-
static
eq
(attr, value, exclude=False)¶ Match a file attribute to a (integer) value
Parameters: - attr – file atribute to compare
- value – value to compare attribute against
- exclude – exclude any files with attribute which matches pattern
-
static
gt
(attr, value)¶ Compare a file attribute to a (integer) value
Parameters: - attr – file atribute to compare
- value – value to compare attribute against
-
static
lt
(attr, value)¶ Compare a file attribute to a (interger) value
Parameters: - attr – file atribute to compare
- value – value to compare attribute against
-
static
regex
(attr, pattern, exclude=False)¶ Match a file attribute to a regular expression
Parameters:
-
static
comment
(string)¶ Create a criteria comment
-
validate
(macros=None)¶ Check that the criteria file attributes are valid
-
toGpfsString
(excludeComments=False, excludeDisabled=False)¶ Returns a GPFS policy file string of the collected criteria
-
Examples¶
Create a rule that deletes temporary files that haven’t been accessed in over 30 days¶
>>> from arcapix.fs.gpfs import DeleteRule, Criteria
>>>
>>> # Create new rule
... myrule = Rule(DeleteRule, name='del-temp', source='pool_1')
>>>
>>> # Set access age criteria
... myrule.criteria.new(Criteria.gt("access", 30))
>>>
>>> # Set criteria for filename OR directory match
... myrule.criteria.new(Criteria.Or(Criteria.like('name', '*.tmp', caseInsensitive=True), Criteria.like('path', '*/tmp/*')))
>>>
>>> print(myrule.toGpfsString())
RULE 'del-temp' DELETE FROM POOL 'pool_1'
WHERE DAYS(CURRENT_TIMESTAMP) – DAYS(ACCESS_TIME) > 30
AND (lower(NAME) LIKE '%.tmp' OR PATH_NAME LIKE '%/tmp/%')
Create a rule with multiple options and two criteria created at once¶
>>> from arcapix.fs.gpfs import MigrateRule, Criteria
>>>
>>> # Create a migrate Rule
... r = Rule(MigrateRule, name="year-old", source="pool_x", target="pool_zz")
>>>
>>> # Set additional rule options
... r.change(threshold=(90, 50), sort='KB_ALLOCATED')
>>>
>>> # Add criteria
... r.criteria.new(Criteria.gt("access", 365), Criteria.eq("user", 0, exclude=True))
>>>
>>> # Print GPFS string
... print(r.toGpfsString())
RULE 'year-old' MIGRATE FROM POOL 'pool_x' TO POOL 'pool_zz'
THRESHOLD(90,50)
WEIGHT(KB_ALLOCATED)
WHERE DAYS(CURRENT_TIMESTAMP) – DAYS(ACCESS_TIME) > 365
AND NOT USER_ID=0