コード例 #1
0
def update_node_instance_attrs(cib, node_name, attrs, state_nodes=None):
    """
    Update nvpairs in instance_attributes for a node specified by its name.

    Automatically creates instance_attributes element if needed. If the node has
    more than one instance_attributes element, the first one is modified. If the
    node is missing in the CIB, it is automatically created if its state is
    provided in state_nodes.

    etree cib -- cib
    string node_name -- name of the node to be updated
    dict attrs -- attrs to update, e.g. {'A': 'a', 'B': ''}
    iterable state_nodes -- optional list of node state objects
    """
    node_el = _ensure_node_exists(get_nodes(cib), node_name, state_nodes)
    # If no instance_attributes id is specified, crm_attribute modifies the
    # first one found. So we just mimic this behavior here.
    attrs_el = node_el.find("./instance_attributes")
    if attrs_el is None:
        attrs_el = etree.SubElement(
            node_el,
            "instance_attributes",
            id=find_unique_id(cib, "nodes-{0}".format(node_el.get("id")))
        )
    update_nvset(attrs_el, attrs)
コード例 #2
0
ファイル: node.py プロジェクト: HideoYamauchi/pcs
def update_node_instance_attrs(cib, node_name, attrs, state_nodes=None):
    """
    Update nvpairs in instance_attributes for a node specified by its name.

    Automatically creates instance_attributes element if needed. If the node has
    more than one instance_attributes element, the first one is modified. If the
    node is missing in the CIB, it is automatically created if its state is
    provided in state_nodes.

    etree cib -- cib
    string node_name -- name of the node to be updated
    dict attrs -- attrs to update, e.g. {'A': 'a', 'B': ''}
    iterable state_nodes -- optional list of node state objects
    """
    node_el = _ensure_node_exists(get_nodes(cib), node_name, state_nodes)
    # If no instance_attributes id is specified, crm_attribute modifies the
    # first one found. So we just mimic this behavior here.
    attrs_el = node_el.find("./instance_attributes")
    if attrs_el is None:
        attrs_el = etree.SubElement(
            node_el,
            "instance_attributes",
            id=find_unique_id(cib, "nodes-{0}".format(node_el.get("id")))
        )
    update_nvset(attrs_el, attrs)
コード例 #3
0
ファイル: resource_set.py プロジェクト: idevat/pcs
def create(parent, resource_set):
    """
    parent - lxml element for append new resource_set
    """
    element = etree.SubElement(parent, "resource_set")
    element.attrib.update(resource_set["options"])
    element.attrib["id"] = find_unique_id(parent.getroottree(), "pcs_rsc_set_{0}".format("_".join(resource_set["ids"])))

    for id in resource_set["ids"]:
        etree.SubElement(element, "resource_ref").attrib["id"] = id

    return element
コード例 #4
0
def create_id(primitive_element):
    """
    Create id for clone element based on contained primitive_element.

    etree.Element primitive_element is resource which will be cloned.
        It must be connected into the cib to ensure that the resulting id is
        unique!
    """
    return find_unique_id(
        primitive_element,
        "{0}-{1}".format(primitive_element.get("id"), TAG_CLONE)
    )
コード例 #5
0
ファイル: clone.py プロジェクト: miz-take/pcs
def create_id(clone_tag, primitive_element):
    """
    Create id for clone element based on contained primitive_element.

    string clone_tag is tag of clone element. Specialization of "clone" is
        "master" and this function is common for both - "clone" and "master".
    etree.Element primitive_element is resource which will be cloned.
        It must be connected into the cib to ensure that the resulting id is
        unique!
    """
    return find_unique_id(
        primitive_element, "{0}-{1}".format(primitive_element.get("id"),
                                            clone_tag))
コード例 #6
0
def create_id(cib, type_prefix, resource_set_list):
    # Create a semi-random id. We need it to be predictable (for testing), short
    # and somehow different than other ids so that we don't spend much time in
    # find_unique_id.
    # Avoid using actual resource names. It makes the id very long (consider 10
    # or more resources in a set constraint). Also, if a resource is deleted
    # and therefore removed from the constraint, the id no longer matches the
    # constraint.
    resource_ids = []
    for _set in resource_set_list:
        resource_ids.extend(_set["ids"])
    id_part = "".join([_id[0] + _id[-1] for _id in resource_ids][:3])
    return find_unique_id(cib, "{0}_set_{1}".format(type_prefix, id_part))
コード例 #7
0
ファイル: resource_set.py プロジェクト: miladalipour99/pcs
def create(parent, resource_set):
    """
    parent - lxml element for append new resource_set
    """
    element = etree.SubElement(parent, "resource_set")
    element.attrib.update(resource_set["options"])
    element.attrib["id"] = find_unique_id(
        parent.getroottree(),
        "pcs_rsc_set_{0}".format("_".join(resource_set["ids"])))

    for _id in resource_set["ids"]:
        etree.SubElement(element, "resource_ref").attrib["id"] = _id

    return element
コード例 #8
0
ファイル: clone.py プロジェクト: HideoYamauchi/pcs
def create_id(clone_tag, primitive_element):
    """
    Create id for clone element based on contained primitive_element.

    string clone_tag is tag of clone element. Specialization of "clone" is
        "master" and this function is common for both - "clone" and "master".
    etree.Element primitive_element is resource which will be cloned.
        It must be connected into the cib to ensure that the resulting id is
        unique!
    """
    return find_unique_id(
        primitive_element,
        "{0}-{1}".format(primitive_element.get("id"), clone_tag)
    )
コード例 #9
0
def create(parent, resource_set):
    """
    parent - lxml element for append new resource_set
    """
    element = etree.SubElement(parent, "resource_set")
    element.attrib.update(resource_set["options"])
    element.attrib["id"] = find_unique_id(
        parent.getroottree(),
        "{0}_set".format(parent.attrib.get("id", "constraint_set")),
    )

    for _id in resource_set["ids"]:
        etree.SubElement(element, "resource_ref").attrib["id"] = _id

    return element
コード例 #10
0
def _append_level_element(tree, level, target_type, target_value, devices):
    level_el = etree.SubElement(tree,
                                "fencing-level",
                                index=str(level),
                                devices=",".join(devices))
    if target_type == TARGET_TYPE_NODE:
        level_el.set("target", target_value)
        id_part = target_value
    elif target_type == TARGET_TYPE_REGEXP:
        level_el.set("target-pattern", target_value)
        id_part = target_value
    elif target_type == TARGET_TYPE_ATTRIBUTE:
        level_el.set("target-attribute", target_value[0])
        level_el.set("target-value", target_value[1])
        id_part = target_value[0]
    level_el.set(
        "id",
        find_unique_id(tree, sanitize_id("fl-{0}-{1}".format(id_part, level))))
    return level_el
コード例 #11
0
ファイル: resource_set.py プロジェクト: CtrlZmaster/pcs
def create(parent, resource_set):
    """
    parent - lxml element for append new resource_set
    """
    element = etree.SubElement(parent, "resource_set")
    if "role" in resource_set["options"]:
        resource_set["options"]["role"] = pacemaker.role.get_value_for_cib(
            resource_set["options"]["role"],
            is_latest_supported=are_new_role_names_supported(parent),
        )
    element.attrib.update(resource_set["options"])
    element.attrib["id"] = find_unique_id(
        parent.getroottree(),
        "{0}_set".format(parent.attrib.get("id", "constraint_set")),
    )

    for _id in resource_set["ids"]:
        etree.SubElement(element, "resource_ref").attrib["id"] = _id

    return element
コード例 #12
0
ファイル: alert.py プロジェクト: HideoYamauchi/pcs
def create_alert(tree, alert_id, path, description=""):
    """
    Create new alert element. Returns newly created element.
    Raises LibraryError if element with specified id already exists.

    tree -- cib etree node
    alert_id -- id of new alert, it will be generated if it is None
    path -- path to script
    description -- description
    """
    if alert_id:
        check_new_id_applicable(tree, "alert-id", alert_id)
    else:
        alert_id = find_unique_id(tree, "alert")

    alert = etree.SubElement(get_alerts(tree), "alert", id=alert_id, path=path)
    if description:
        alert.set("description", description)

    return alert
コード例 #13
0
ファイル: alert.py プロジェクト: miladalipour99/pcs
def create_alert(tree, alert_id, path, description=""):
    """
    Create new alert element. Returns newly created element.
    Raises LibraryError if element with specified id already exists.

    tree -- cib etree node
    alert_id -- id of new alert, it will be generated if it is None
    path -- path to script
    description -- description
    """
    if alert_id:
        check_new_id_applicable(tree, "alert-id", alert_id)
    else:
        alert_id = find_unique_id(tree, "alert")

    alert = etree.SubElement(get_alerts(tree), "alert", id=alert_id, path=path)
    if description:
        alert.set("description", description)

    return alert
コード例 #14
0
ファイル: alert.py プロジェクト: vvidic/pcs
def add_recipient(
    reporter: ReportProcessor,
    tree,
    alert_id,
    recipient_value,
    recipient_id=None,
    description="",
    allow_same_value=False,
):
    """
    Add recipient to alert with specified id. Returns added recipient element.
    Raises LibraryError if alert with specified recipient_id doesn't exist.
    Raises LibraryError if recipient already exists.

    reporter -- report processor
    tree -- cib etree node
    alert_id -- id of alert which should be parent of new recipient
    recipient_value -- value of recipient
    recipient_id -- id of new recipient, if None it will be generated
    description -- description of recipient
    allow_same_value -- if True unique recipient value is not required
    """
    if recipient_id is None:
        recipient_id = find_unique_id(tree, "{0}-recipient".format(alert_id))
    else:
        validate_id_does_not_exist(tree, recipient_id)

    alert = find_alert(get_alerts(tree), alert_id)
    ensure_recipient_value_is_unique(reporter,
                                     alert,
                                     recipient_value,
                                     allow_duplicity=allow_same_value)
    recipient = etree.SubElement(alert,
                                 "recipient",
                                 id=recipient_id,
                                 value=recipient_value)

    if description:
        recipient.attrib["description"] = description

    return recipient
コード例 #15
0
ファイル: acl.py プロジェクト: OndrejHome/pcs
def add_permissions_to_role(role_el, permission_info_list):
    """
    Add permissions from permission_info_list to role_el.

    role_el -- acl_role element to which permissions should be added
    permission_info_list -- list of tuples,
        each contains (permission, scope_type, scope)
    """
    area_type_attribute_map = {
        'xpath': 'xpath',
        'id': 'reference',
    }
    for permission, scope_type, scope in permission_info_list:
        perm = etree.SubElement(role_el, "acl_permission")
        perm.set(
            "id",
            find_unique_id(
                role_el, "{0}-{1}".format(role_el.get("id", "role"),
                                          permission)))
        perm.set("kind", permission)
        perm.set(area_type_attribute_map[scope_type], scope)
コード例 #16
0
ファイル: acl.py プロジェクト: dchirikov/pcs
def add_permissions_to_role(tree, role_id, permission_info_list):
    """
    tree etree node
    role_id value of atribute id, which exists in dom
    permission_info_list list of tuples,
        each contains (permission, scope_type, scope)
    """
    __validate_permissions(tree, permission_info_list)

    area_type_attribute_map = {
        'xpath': 'xpath',
        'id': 'reference',
    }
    for permission, scope_type, scope in permission_info_list:
        perm = etree.SubElement(__find_role(tree, role_id), "acl_permission")
        perm.set(
            "id",
            find_unique_id(tree, "{0}-{1}".format(role_id, permission))
        )
        perm.set("kind", permission)
        perm.set(area_type_attribute_map[scope_type], scope)
コード例 #17
0
ファイル: fencing_topology.py プロジェクト: HideoYamauchi/pcs
def _append_level_element(tree, level, target_type, target_value, devices):
    level_el = etree.SubElement(
        tree,
        "fencing-level",
        index=str(level),
        devices=",".join(devices)
    )
    if target_type == TARGET_TYPE_NODE:
        level_el.set("target", target_value)
        id_part = target_value
    elif target_type == TARGET_TYPE_REGEXP:
        level_el.set("target-pattern", target_value)
        id_part = target_value
    elif target_type == TARGET_TYPE_ATTRIBUTE:
        level_el.set("target-attribute", target_value[0])
        level_el.set("target-value", target_value[1])
        id_part = target_value[0]
    level_el.set(
        "id",
        find_unique_id(tree, sanitize_id("fl-{0}-{1}".format(id_part, level)))
    )
    return level_el
コード例 #18
0
ファイル: alert.py プロジェクト: HideoYamauchi/pcs
def add_recipient(
    reporter,
    tree,
    alert_id,
    recipient_value,
    recipient_id=None,
    description="",
    allow_same_value=False
):
    """
    Add recipient to alert with specified id. Returns added recipient element.
    Raises LibraryError if alert with specified recipient_id doesn't exist.
    Raises LibraryError if recipient already exists.

    reporter -- report processor
    tree -- cib etree node
    alert_id -- id of alert which should be parent of new recipient
    recipient_value -- value of recipient
    recipient_id -- id of new recipient, if None it will be generated
    description -- description of recipient
    allow_same_value -- if True unique recipient value is not required
    """
    if recipient_id is None:
        recipient_id = find_unique_id(tree, "{0}-recipient".format(alert_id))
    else:
        validate_id_does_not_exist(tree, recipient_id)

    alert = find_alert(get_alerts(tree), alert_id)
    ensure_recipient_value_is_unique(
        reporter, alert, recipient_value, allow_duplicity=allow_same_value
    )
    recipient = etree.SubElement(
        alert, "recipient", id=recipient_id, value=recipient_value
    )

    if description:
        recipient.set("description", description)

    return recipient
コード例 #19
0
ファイル: acl.py プロジェクト: HideoYamauchi/pcs
def add_permissions_to_role(role_el, permission_info_list):
    """
    Add permissions from permission_info_list to role_el.

    role_el -- acl_role element to which permissions should be added
    permission_info_list -- list of tuples,
        each contains (permission, scope_type, scope)
    """
    area_type_attribute_map = {
        'xpath': 'xpath',
        'id': 'reference',
    }
    for permission, scope_type, scope in permission_info_list:
        perm = etree.SubElement(role_el, "acl_permission")
        perm.set(
            "id",
            find_unique_id(
                role_el,
                "{0}-{1}".format(role_el.get("id", "role"), permission)
            )
        )
        perm.set("kind", permission)
        perm.set(area_type_attribute_map[scope_type], scope)
コード例 #20
0
ファイル: test_tools.py プロジェクト: HideoYamauchi/pcs
 def test_add_first_available_suffix(self):
     self.fixture_add_primitive_with_id("myId")
     self.fixture_add_primitive_with_id("myId-1")
     self.fixture_add_primitive_with_id("myId-3")
     self.assertEqual("myId-2", lib.find_unique_id(self.cib.tree, "myId"))
コード例 #21
0
ファイル: test_tools.py プロジェクト: HideoYamauchi/pcs
 def test_suffix_not_needed(self):
     self.fixture_add_primitive_with_id("myId-1")
     self.assertEqual("myId", lib.find_unique_id(self.cib.tree, "myId"))
コード例 #22
0
ファイル: test_tools.py プロジェクト: HideoYamauchi/pcs
 def test_already_unique(self):
     self.fixture_add_primitive_with_id("myId")
     self.assertEqual("other", lib.find_unique_id(self.cib.tree, "other"))
コード例 #23
0
ファイル: resource.py プロジェクト: nrwahl2/pcs
def create_resource_id(resources_section, name, suffix):
    return find_unique_id(resources_section.getroottree(),
                          "booth-{0}-{1}".format(name, suffix))
コード例 #24
0
def _create_id(cib, ticket, resource_id, resource_role):
    return tools.find_unique_id(
        cib,
        "-".join(('ticket', ticket, resource_id))
        +("-{0}".format(resource_role) if resource_role else "")
    )
コード例 #25
0
ファイル: test_tools.py プロジェクト: tomjelinek/pcs
 def test_reserved_ids(self):
     self.fixture_add_primitive_with_id("myId-1")
     self.assertEqual(
         "myId-3",
         lib.find_unique_id(self.cib.tree, "myId", ["myId", "myId-2"])
     )
コード例 #26
0
ファイル: test_tools.py プロジェクト: cwjenkins/pcs
 def test_add_first_available_suffix(self):
     self.fixture_add_primitive_with_id("myId")
     self.fixture_add_primitive_with_id("myId-1")
     self.fixture_add_primitive_with_id("myId-3")
     self.assertEqual("myId-2", lib.find_unique_id(self.cib.tree, "myId"))
コード例 #27
0
ファイル: test_tools.py プロジェクト: cwjenkins/pcs
 def test_already_unique(self):
     self.fixture_add_primitive_with_id("myId")
     self.assertEqual("other", lib.find_unique_id(self.cib.tree, "other"))
コード例 #28
0
def create_id(cib, type_prefix, resource_set_list):
    id = "pcs_" +type_prefix +"".join([
        "_set_"+"_".join(id_set)
        for id_set in resource_set.extract_id_set_list(resource_set_list)
    ])
    return find_unique_id(cib, id)
コード例 #29
0
ファイル: constraint.py プロジェクト: miz-take/pcs
def create_id(cib, type_prefix, resource_set_list):
    id = "pcs_" + type_prefix + "".join([
        "_set_" + "_".join(id_set)
        for id_set in resource_set.extract_id_set_list(resource_set_list)
    ])
    return find_unique_id(cib, id)
コード例 #30
0
ファイル: ticket.py プロジェクト: tomjelinek/pcs
def _create_id(cib, ticket, resource_id, resource_role):
    return tools.find_unique_id(
        cib,
        "-".join(('ticket', ticket, resource_id))
        +("-{0}".format(resource_role) if resource_role else "")
    )
コード例 #31
0
ファイル: test_tools.py プロジェクト: cwjenkins/pcs
 def test_suffix_not_needed(self):
     self.fixture_add_primitive_with_id("myId-1")
     self.assertEqual("myId", lib.find_unique_id(self.cib.tree, "myId"))
コード例 #32
0
ファイル: resource.py プロジェクト: tomjelinek/pcs
def create_resource_id(resources_section, name, suffix):
    return find_unique_id(
        resources_section.getroottree(), "booth-{0}-{1}".format(name, suffix)
    )
コード例 #33
0
ファイル: test_tools.py プロジェクト: cwjenkins/pcs
 def test_reserved_ids(self):
     self.fixture_add_primitive_with_id("myId-1")
     self.assertEqual(
         "myId-3",
         lib.find_unique_id(self.cib.tree, "myId", ["myId", "myId-2"]))
コード例 #34
0
ファイル: ticket.py プロジェクト: dchirikov/pcs
def _create_id(cib, ticket, resource_id, resource_role):
    return tools.find_unique_id(
        cib,
        "-".join(('ticket', ticket, resource_id, resource_role))
    )