Esempio n. 1
0
 def classify_role(self, role):
     if not role:
         return role, None
     elif role in olist(self.resource_roles()):
         return self.canonize(role, self.resource_roles()), 'role'
     elif role.isdigit():
         return role, 'instance'
     return role, None
Esempio n. 2
0
 def classify_action(self, action):
     if not action:
         return action, None
     elif action in olist(self.resource_actions()):
         return self.canonize(action, self.resource_actions()), 'action'
     elif action.isdigit():
         return action, 'instance'
     return action, None
Esempio n. 3
0
 def classify_action(self, action):
     if not action:
         return action, None
     elif action in olist(self.resource_actions()):
         return self.canonize(action, self.resource_actions()), 'action'
     elif action.isdigit():
         return action, 'instance'
     return action, None
Esempio n. 4
0
 def classify_role(self, role):
     if not role:
         return role, None
     elif role in olist(self.resource_roles()):
         return self.canonize(role, self.resource_roles()), 'role'
     elif role.isdigit():
         return role, 'instance'
     return role, None
Esempio n. 5
0
def test_olist():
    lst = utils.olist(['B', 'C', 'A'])
    lst.append('f')
    lst.append('aA')
    lst.append('_')
    assert 'aa' in lst
    assert 'a' in lst
    assert list(lst) == ['b', 'c', 'a', 'f', 'aa', '_']
Esempio n. 6
0
 def match_arguments(self, out, names):
     """matches [<name> <n>=<v> <n>=<v> ...]
     adds the nvpairs to dicts named out.<name>
     """
     names = olist(names)
     while self.has_tokens() and (self.current_token() in names):
         for name in names:
             for n, v in self.try_match_nvpairs(name):
                 getattr(out, name)[n] = v
Esempio n. 7
0
 def match_arguments(self, out, names):
     """matches [<name> <n>=<v> <n>=<v> ...]
     adds the nvpairs to dicts named out.<name>
     """
     names = olist(names)
     while self.has_tokens() and (self.current_token() in names):
         for name in names:
             for n, v in self.try_match_nvpairs(name):
                 getattr(out, name)[n] = v
Esempio n. 8
0
 def validate_score(self, score, noattr=False):
     if not noattr and score in olist(vars.score_types):
         return vars.score_types[score.lower()]
     elif re.match("^[+-]?(inf(inity)?|INF(INITY)?|[0-9]+)$", score):
         score = re.sub("inf(inity)?|INF(INITY)?", "INFINITY", score)
         return ["score", score]
     if noattr:
         # orders have the special kind attribute
         kind = self.validation.canonize(score, self.validation.rsc_order_kinds())
         if not kind:
             self.err("Invalid kind: " + score)
         return ['kind', kind]
     else:
         return ['score-attribute', score]
Esempio n. 9
0
 def validate_score(self, score, noattr=False):
     if not noattr and score in olist(vars.score_types):
         return vars.score_types[score.lower()]
     elif re.match("^[+-]?(inf(inity)?|INF(INITY)?|[0-9]+)$", score):
         score = re.sub("inf(inity)?|INF(INITY)?", "INFINITY", score)
         return ["score", score]
     if noattr:
         # orders have the special kind attribute
         kind = self.validation.canonize(score,
                                         self.validation.rsc_order_kinds())
         if not kind:
             self.err("Invalid kind: " + score)
         return ['kind', kind]
     else:
         return ['score-attribute', score]
Esempio n. 10
0
 def match_date(self):
     """
     returns: [['operation', <op>], (n, v), (n, v)]
     """
     self.match('(%s)$' % ('|'.join(self.validation.date_ops())))
     op = self.matched(1)
     if op in olist(vars.simple_date_ops):
         val = self.match_any()
         if keyword_cmp(op, 'lt'):
             return [['operation', op], ('end', val)]
         return [['operation', op], ('start', val)]
     elif op == 'in_range':
         nv = self.match_nvpairs(minpairs=2)
         if not keyword_cmp(nv[0][0], 'start'):
             self.err("Expected start=<start>")
         return [['operation', op]] + nv
     else:  # lt, gt, date_spec, ?
         return [['operation', op]] + self.match_nvpairs(minpairs=1)
Esempio n. 11
0
 def match_date(self):
     """
     returns: [['operation', <op>], (n, v), (n, v)]
     """
     self.match('(%s)$' % ('|'.join(self.validation.date_ops())))
     op = self.matched(1)
     if op in olist(vars.simple_date_ops):
         val = self.match_any()
         if keyword_cmp(op, 'lt'):
             return [['operation', op], ('end', val)]
         return [['operation', op], ('start', val)]
     elif op == 'in_range':
         nv = self.match_nvpairs(minpairs=2)
         if not keyword_cmp(nv[0][0], 'start'):
             self.err("Expected start=<start>")
         return [['operation', op]] + nv
     else:  # lt, gt, date_spec, ?
         return [['operation', op]] + self.match_nvpairs(minpairs=1)
Esempio n. 12
0
def date_exp2cli(node):
    kwmap = {'in_range': 'in', 'date_spec': 'spec'}
    l = []
    operation = node.get("operation")
    l.append(clidisplay.keyword("date"))
    l.append(clidisplay.keyword(kwmap.get(operation, operation)))
    if operation in utils.olist(constants.simple_date_ops):
        value = node.get(utils.keyword_cmp(operation, 'lt') and "end" or "start")
        l.append(clidisplay.attr_value(quote_wrap(value)))
    else:
        if operation == 'in_range':
            for name in constants.in_range_attrs:
                if name in node.attrib:
                    l.append(nvpair_format(name, node.attrib[name]))
        for c in node.iterchildren():
            if c.tag in ("duration", "date_spec"):
                l.extend([nvpair_format(name, c.get(name))
                          for name in c.keys() if name != 'id'])
    return ' '.join(l)
Esempio n. 13
0
def date_exp2cli(node):
    kwmap = {'in_range': 'in', 'date_spec': 'spec'}
    l = []
    operation = node.get("operation")
    l.append(clidisplay.keyword("date"))
    l.append(clidisplay.keyword(kwmap.get(operation, operation)))
    if operation in utils.olist(constants.simple_date_ops):
        value = node.get(utils.keyword_cmp(operation, 'lt') and "end" or "start")
        l.append(clidisplay.attr_value(quote_wrap(value)))
    else:
        if operation == 'in_range':
            for name in constants.in_range_attrs:
                if name in node.attrib:
                    l.append(nvpair_format(name, node.attrib[name]))
        for c in node.iterchildren():
            if c.tag in ("duration", "date_spec"):
                l.extend([nvpair_format(name, c.get(name))
                          for name in c.keys() if name != 'id'])
    return ' '.join(l)
Esempio n. 14
0
    def match_arguments(self, out, names):
        """
        [<name> attr_list]
        [operations id_spec]
        [op op_type [<attribute>=<value> ...] ...]

        attr_list :: [$id=<id>] <attr>=<val> [<attr>=<val>...] | $id-ref=<id>
        id_spec :: $id=<id> | $id-ref=<id>
        op_type :: start | stop | monitor
        """
        names = olist(names)
        while self.has_tokens() and self.current_token() in names:
            t = self.current_token()
            if t == 'operations':
                self.match_operations(out)
            elif t.lower() == 'op':
                self.match_op(out)
            else:
                for name in names:
                    if self.match_attr_list(name, out):
                        break
Esempio n. 15
0
    def match_arguments(self, out, names):
        """
        [<name> attr_list]
        [operations id_spec]
        [op op_type [<attribute>=<value> ...] ...]

        attr_list :: [$id=<id>] <attr>=<val> [<attr>=<val>...] | $id-ref=<id>
        id_spec :: $id=<id> | $id-ref=<id>
        op_type :: start | stop | monitor
        """
        names = olist(names)
        while self.has_tokens() and self.current_token() in names:
            t = self.current_token()
            if t == 'operations':
                self.match_operations(out)
            elif t.lower() == 'op':
                self.match_op(out)
            else:
                for name in names:
                    if self.match_attr_list(name, out):
                        break
Esempio n. 16
0
def date_exp2cli(node):
    l = []
    operation = node.get("operation")
    l.append(cli_display.keyword("date"))
    l.append(cli_display.keyword(operation))
    if operation in utils.olist(vars.simple_date_ops):
        value = node.get(utils.keyword_cmp(operation, 'lt') and "end" or "start")
        l.append('"%s"' % cli_display.attr_value(value))
    else:
        if operation == 'in_range':
            for name in vars.in_range_attrs:
                v = node.get(name)
                if v:
                    l.append(nvpair_format(name, v))
        for c in node.iterchildren():
            if c.tag in ("duration", "date_spec"):
                pl = []
                for name in c.keys():
                    if name != "id":
                        pl.append([name, c.get(name)])
                l.append(cli_pairs(pl))
    return ' '.join(l)
Esempio n. 17
0
def date_exp2cli(node):
    l = []
    operation = node.get("operation")
    l.append(cli_display.keyword("date"))
    l.append(cli_display.keyword(operation))
    if operation in utils.olist(vars.simple_date_ops):
        value = node.get(
            utils.keyword_cmp(operation, 'lt') and "end" or "start")
        l.append('"%s"' % cli_display.attr_value(value))
    else:
        if operation == 'in_range':
            for name in vars.in_range_attrs:
                v = node.get(name)
                if v:
                    l.append(nvpair_format(name, v))
        for c in node.iterchildren():
            if c.tag in ("duration", "date_spec"):
                pl = []
                for name in c.keys():
                    if name != "id":
                        pl.append([name, c.get(name)])
                l.append(cli_pairs(pl))
    return ' '.join(l)
Esempio n. 18
0
def is_constraint_cli(s):
    return s in olist(constants.constraint_cli_names)
Esempio n. 19
0
def is_resource_cli(s):
    return s in olist(constants.resource_cli_names)
Esempio n. 20
0
def is_resource_cli(s):
    return s in olist(vars.resource_cli_names)
Esempio n. 21
0
def is_resource_cli(s):
    return s in olist(vars.resource_cli_names)
Esempio n. 22
0
def is_constraint_cli(s):
    return s in olist(vars.constraint_cli_names)
Esempio n. 23
0
def is_constraint_cli(s):
    return s in olist(vars.constraint_cli_names)
Esempio n. 24
0
def is_constraint_cli(s):
    return s in olist(constants.constraint_cli_names)
Esempio n. 25
0
def is_resource_cli(s):
    return s in olist(constants.resource_cli_names)