Merge "Add ALL-IN operator to extra spec ops"
This commit is contained in:
commit
441ddd0471
@ -61,9 +61,10 @@ There are some standard filter classes to use (:mod:`nova.scheduler.filters`):
|
|||||||
* s<= (less than or equal to as a string)
|
* s<= (less than or equal to as a string)
|
||||||
* s< (less than as a string)
|
* s< (less than as a string)
|
||||||
* <in> (substring)
|
* <in> (substring)
|
||||||
|
* <all-in> (all elements contained in collection)
|
||||||
* <or> (find one of these)
|
* <or> (find one of these)
|
||||||
|
|
||||||
Examples are: ">= 5", "s== 2.1.0", "<in> gcc", and "<or> fpu <or> gpu"
|
Examples are: ">= 5", "s== 2.1.0", "<in> gcc", "<all-in> aes mmx", and "<or> fpu <or> gpu"
|
||||||
|
|
||||||
* |AggregateInstanceExtraSpecsFilter| - checks that the aggregate metadata
|
* |AggregateInstanceExtraSpecsFilter| - checks that the aggregate metadata
|
||||||
satisfies any extra specifications associated with the instance type (that
|
satisfies any extra specifications associated with the instance type (that
|
||||||
|
@ -16,12 +16,13 @@
|
|||||||
import operator
|
import operator
|
||||||
|
|
||||||
# 1. The following operations are supported:
|
# 1. The following operations are supported:
|
||||||
# =, s==, s!=, s>=, s>, s<=, s<, <in>, <or>, ==, !=, >=, <=
|
# =, s==, s!=, s>=, s>, s<=, s<, <in>, <all-in>, <or>, ==, !=, >=, <=
|
||||||
# 2. Note that <or> is handled in a different way below.
|
# 2. Note that <or> is handled in a different way below.
|
||||||
# 3. If the first word in the extra_specs is not one of the operators,
|
# 3. If the first word in the extra_specs is not one of the operators,
|
||||||
# it is ignored.
|
# it is ignored.
|
||||||
_op_methods = {'=': lambda x, y: float(x) >= float(y),
|
_op_methods = {'=': lambda x, y: float(x) >= float(y),
|
||||||
'<in>': lambda x, y: y in x,
|
'<in>': lambda x, y: y in x,
|
||||||
|
'<all-in>': lambda x, y: all(val in x for val in y),
|
||||||
'==': lambda x, y: float(x) == float(y),
|
'==': lambda x, y: float(x) == float(y),
|
||||||
'!=': lambda x, y: float(x) != float(y),
|
'!=': lambda x, y: float(x) != float(y),
|
||||||
'>=': lambda x, y: float(x) >= float(y),
|
'>=': lambda x, y: float(x) >= float(y),
|
||||||
@ -59,7 +60,8 @@ def match(value, req):
|
|||||||
break
|
break
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if words and method(value, words[0]):
|
if words:
|
||||||
return True
|
if op == '<all-in>': # requires a list not a string
|
||||||
|
return method(value, words)
|
||||||
|
return method(value, words[0])
|
||||||
return False
|
return False
|
||||||
|
@ -198,3 +198,38 @@ class ExtraSpecsOpsTestCase(test.NoDBTestCase):
|
|||||||
value='2',
|
value='2',
|
||||||
req='>= 3',
|
req='>= 3',
|
||||||
matches=False)
|
matches=False)
|
||||||
|
|
||||||
|
def test_extra_specs_matches_all_with_op_allin(self):
|
||||||
|
values = ['aes', 'mmx', 'aux']
|
||||||
|
self._do_extra_specs_ops_test(
|
||||||
|
value=str(values),
|
||||||
|
req='<all-in> aes mmx',
|
||||||
|
matches=True)
|
||||||
|
|
||||||
|
def test_extra_specs_matches_one_with_op_allin(self):
|
||||||
|
values = ['aes', 'mmx', 'aux']
|
||||||
|
self._do_extra_specs_ops_test(
|
||||||
|
value=str(values),
|
||||||
|
req='<all-in> mmx',
|
||||||
|
matches=True)
|
||||||
|
|
||||||
|
def test_extra_specs_fails_with_op_allin(self):
|
||||||
|
values = ['aes', 'mmx', 'aux']
|
||||||
|
self._do_extra_specs_ops_test(
|
||||||
|
value=str(values),
|
||||||
|
req='<all-in> txt',
|
||||||
|
matches=False)
|
||||||
|
|
||||||
|
def test_extra_specs_fails_all_with_op_allin(self):
|
||||||
|
values = ['aes', 'mmx', 'aux']
|
||||||
|
self._do_extra_specs_ops_test(
|
||||||
|
value=str(values),
|
||||||
|
req='<all-in> txt 3dnow',
|
||||||
|
matches=False)
|
||||||
|
|
||||||
|
def test_extra_specs_fails_match_one_with_op_allin(self):
|
||||||
|
values = ['aes', 'mmx', 'aux']
|
||||||
|
self._do_extra_specs_ops_test(
|
||||||
|
value=str(values),
|
||||||
|
req='<all-in> txt aes',
|
||||||
|
matches=False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user