1818OPERATOR_MAPPING = {
1919 '=' : 'any_of' ,
2020 '!=' : 'not_any_of' ,
21+ 'is-not' : 'is_not' ,
2122 'contains' : 'contains' ,
2223 'does-not-contain' : 'not_contains' ,
2324 'starts-with' : 'starts_with' ,
@@ -34,9 +35,9 @@ class InvalidLabelsFilterRuleFormat(CloudifyCliError):
3435 def __init__ (self , labels_filter_value ):
3536 super (CloudifyCliError , self ).__init__ (
3637 'The labels filter rule `{0}` is not in the right format. It must '
37- 'be one of: <key>=<value>, <key>!=<value>, <key> is null, '
38- '<key> is not null. <value> can be a single string or a list of '
39- 'strings of the form [<value1>,<value2>,...]. '
38+ 'be one of: <key>=<value>, <key>!=<value>, <key> is-not <value>, '
39+ ' <key> is null, <key> is not null. <value> can be a single '
40+ 'string or a list of strings of the form [<value1>,<value2>,...]. '
4041 '<value> cannot contain control characters, plus, any comma and '
4142 'colon in <value> must be escaped with `\\ `. <key> can '
4243 'contain only letters, digits and the characters '
@@ -94,16 +95,15 @@ def __init__(self, key, values, operator):
9495
9596 @classmethod
9697 def from_string (cls , str_filter_rule ):
97- match_equal = re .match (r'^([\w\-\.]+)(=)([^\n\t\"]+)$' ,
98- str_filter_rule )
99- match_not_equal = re .match (r'^([\w\-\.]+)(!=)([^\n\t\"]+)$' ,
100- str_filter_rule )
101- equal_matching = match_equal or match_not_equal
102- if equal_matching :
103- key = equal_matching .group (1 ).lower ()
104- operator = equal_matching .group (2 )
105- values = cls ._get_rule_values (equal_matching .group (3 ))
106- return cls (key , values , OPERATOR_MAPPING [operator ])
98+ for operator in ['!=' , '=' , ' is-not ' ]:
99+ matching = re .match (
100+ r'^([\w\-\.]+)({0})([^\n\t\"]+)$' .format (operator ),
101+ str_filter_rule )
102+ if matching :
103+ key = matching .group (1 ).lower ()
104+ operator = matching .group (2 )
105+ values = cls ._get_rule_values (matching .group (3 ))
106+ return cls (key , values , OPERATOR_MAPPING [operator .strip ()])
107107
108108 match_null = re .match (r'^([\w\-\.]+) (is null)$' , str_filter_rule )
109109 match_not_null = re .match (r'^([\w\-\.]+) (is not null)$' ,
@@ -122,6 +122,8 @@ def __str__(self):
122122 cli_operator = REVERSED_OPERATOR_MAPPING [self ['operator' ]]
123123 if self ['operator' ] in ('is_null' , 'is_not_null' ):
124124 return '"{0} {1}"' .format (self ['key' ], cli_operator )
125+ if cli_operator == 'is-not' :
126+ cli_operator = ' is-not '
125127 self ['values' ] = [val .replace (',' , '\\ ,' ).replace (':' , '\\ :' )
126128 .replace ('$' , '\\ $' ) for val in self ['values' ]]
127129 return super (LabelsFilterRule , self ).__str__ (cli_operator )
0 commit comments