def cli_nvpair(nvp): 'Converts an nvpair tag or a (name, value) pair to CLI syntax' from cibconfig import cib_factory nodeid = nvp.get('id') idref = nvp.get('id-ref') name = nvp.get('name') value = nvp.get('value') if idref is not None: if name is not None: return '@%s:%s' % (idref, name) return '@%s' % (idref) elif nodeid is not None and cib_factory.is_id_refd(nvp.tag, nodeid): return '$%s:%s' % (nodeid, nvpair_format(name, value)) return nvpair_format(name, value)
def cli_rule(node): from cibconfig import cib_factory s = [] node_id = node.get("id") if node_id and cib_factory.is_id_refd(node.tag, node_id): s.append(nvpair_format('$id', node_id)) else: idref = node.get("id-ref") if idref: return nvpair_format('$id-ref', idref) rsc_role = node.get("role") if rsc_role: s.append(nvpair_format('$role', rsc_role)) score = cli_rule_score(node) if score: s.append("%s:" % (clidisplay.score(score))) s.append(cli_exprs(node)) return ' '.join(s)