Esempio n. 1
0
def nvset_append_new(
    parent_element: _Element,
    id_provider: IdProvider,
    nvset_tag: NvsetTag,
    nvpair_dict: Mapping[str, str],
    nvset_options: Mapping[str, str],
    nvset_rule: Optional[RuleRoot] = None,
) -> _Element:
    """
    Create new nvset and append it to CIB

    parent_element -- the created nvset will be appended into this element
    id_provider -- elements' ids generator
    nvset_tag -- type and actual tag of the nvset
    nvpair_dict -- nvpairs to be put into the new nvset
    nvset_options -- additional attributes of the created nvset
    nvset_rule -- optional rule describing when the created nvset applies
    """
    nvset_options = dict(nvset_options)  # make a copy which we can modify
    if "id" not in nvset_options or not nvset_options["id"]:
        nvset_options["id"] = create_subelement_id(parent_element, nvset_tag,
                                                   id_provider)

    nvset_el = etree.SubElement(parent_element, nvset_tag)
    for name, value in nvset_options.items():
        if value != "":
            nvset_el.attrib[name] = value
    if nvset_rule:
        rule_to_cib(nvset_el, id_provider, nvset_rule)
    for name, value in nvpair_dict.items():
        _set_nvpair(nvset_el, id_provider, name, value)
    return nvset_el
Esempio n. 2
0
 def assert_cib(tree, expected_xml, schema_version=None):
     if schema_version is None:
         schema_version = Version(3, 5, 0)
     xml = etree.fromstring('<root id="X"/>')
     rule.rule_to_cib(xml, IdProvider(xml), schema_version, tree)
     assert_xml_equal('<root id="X">' + expected_xml + "</root>",
                      etree_to_str(xml))
Esempio n. 3
0
 def assert_cib(tree, expected_xml):
     xml = etree.fromstring('<root id="X"/>')
     rule.rule_to_cib(xml, IdProvider(xml), tree)
     assert_xml_equal('<root id="X">' + expected_xml + "</root>",
                      etree_to_str(xml))