def cli_acl_spec2_format(xml_spec, v): key_f = clidisplay.keyword(xml_spec) if xml_spec == "xpath": (shortcut, spec_l) = find_acl_shortcut(v) if shortcut: key_f = clidisplay.keyword(shortcut) v_f = ':'.join([clidisplay.attr_value(x) for x in spec_l]) else: v_f = clidisplay.attr_value(quote_wrap(v)) else: # ref, type and attr v_f = clidisplay.attr_value(v) return v_f and '%s:%s' % (key_f, v_f) or key_f
def acl_spec_format(xml_spec, v): key_f = clidisplay.keyword(constants.acl_spec_map[xml_spec]) if xml_spec == "xpath": (shortcut, spec_l) = find_acl_shortcut(v) if shortcut: key_f = clidisplay.keyword(shortcut) v_f = ':'.join([clidisplay.attr_value(x) for x in spec_l]) else: v_f = clidisplay.attr_value(quote_wrap(v)) elif xml_spec == "ref": v_f = '%s' % clidisplay.attr_value(v) else: # tag and attribute v_f = '%s' % clidisplay.attr_value(v) return v_f and '%s:%s' % (key_f, v_f) or key_f
def cli_acl_rule(node, format=1): l = [] acl_rule_name = node.tag l.append(clidisplay.keyword(acl_rule_name)) for xml_spec in constants.acl_spec_map: v = node.get(xml_spec) if v: l.append(acl_spec_format(xml_spec, v)) return ' '.join(l)
def cli_op(node): "CLI format for an <op> tag" action, pl = xmlutil.op2list(node) if not action: return "" ret = ["%s %s" % (clidisplay.keyword("op"), action)] ret += [nvpair_format(n, v) for n, v in pl] ret += [cli_nvpair(v) for v in op_instattr(node)] return ' '.join(ret)
def cli_acl_permission(node): s = [clidisplay.keyword(node.get('kind'))] #if node.get('id'): # s.append(head_id_format(node.get('id'))) if node.get('description'): s.append(nvpair_format('description', node.get('description'))) for attrname, cliname in constants.acl_spec_map_2_rev: if attrname in node.attrib: s.append(cli_acl_spec2_format(cliname, node.get(attrname))) return ' '.join(s)
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)
def cli_exprs(node): bool_op = node.get("boolean-op") if not bool_op: bool_op = "and" exp = [] for c in node.iterchildren(): if c.tag == "date_expression": exp.append(date_exp2cli(c)) elif c.tag == "expression": exp.append(exp2cli(c)) return (" %s " % clidisplay.keyword(bool_op)).join(exp)
def cli_operations(node, break_lines=True): l = [] node_id = node.get("id") s = '' if node_id: s = nvpair_format('$id', node_id) idref = node.get("id-ref") if idref: s = '%s %s' % (s, nvpair_format('$id-ref', idref)) if s: l.append("%s %s" % (clidisplay.keyword("operations"), s)) for c in node.iterchildren(): if c.tag == "op": l.append(cli_op(c)) return cli_format(l, break_lines=break_lines)
def binary_op_format(op): l = op.split(':') if len(l) == 2: return "%s:%s" % (l[0], clidisplay.keyword(l[1])) else: return clidisplay.keyword(op)
def cli_acl_roleref(node, format=1): return "%s:%s" % (clidisplay.keyword("role"), clidisplay.attr_value(node.get("id")))