Example #1
0
def op_element_to_dto(
    op_element: _Element,
    rule_eval: Optional[rule.RuleInEffectEval] = None
) -> CibResourceOperationDto:
    if rule_eval is None:
        rule_eval = rule.RuleInEffectEvalDummy()
    return CibResourceOperationDto(
        id=str(op_element.attrib["id"]),
        name=str(op_element.attrib["name"]),
        interval=str(op_element.attrib["interval"]),
        description=op_element.get("description"),
        start_delay=op_element.get("start-delay"),
        interval_origin=op_element.get("interval-origin"),
        timeout=op_element.get("timeout"),
        enabled=get_optional_value(is_true, op_element.get("enabled")),
        record_pending=get_optional_value(is_true,
                                          op_element.get("record-pending")),
        role=get_optional_value(
            lambda _role: role.get_value_primary(const.PcmkRoleType(_role)),
            op_element.get("role"),
        ),
        on_fail=get_optional_value(const.PcmkOnFailAction,
                                   op_element.get("on-fail")),
        meta_attributes=[
            nvpair_multi.nvset_element_to_dto(nvset, rule_eval) for nvset in
            nvpair_multi.find_nvsets(op_element, nvpair_multi.NVSET_META)
        ],
        instance_attributes=[
            nvpair_multi.nvset_element_to_dto(nvset, rule_eval) for nvset in
            nvpair_multi.find_nvsets(op_element, nvpair_multi.NVSET_INSTANCE)
        ],
    )
Example #2
0
def export_attributes(element: _Element,
                      with_id: bool = True) -> Dict[str, str]:
    result = {str(key): str(value) for key, value in element.attrib.items()}
    if not with_id:
        result.pop("id", None)
    for role_name in ("role", "rsc-role", "with-rsc-role"):
        if role_name in result:
            result[role_name] = pacemaker.role.get_value_primary(
                const.PcmkRoleType(result[role_name].capitalize()))
    return result
Example #3
0
def _filter_op_dict(
        op: ResourceOperationIn,
        new_role_names_supported: bool) -> ResourceOperationFilteredOut:
    # adjust new operation definition (coming from agent metadata) to old code,
    # TODO this should be handled in a different place - in saving operations to
    # CIB
    result = {
        key: val
        for key, val in op.items() if val is not None and val != ""
    }
    # translate a role to a proper value
    if "role" in result:
        result["role"] = pacemaker.role.get_value_for_cib(
            const.PcmkRoleType(result["role"]), new_role_names_supported)
    return result
Example #4
0
 def _get_raw_actions(self) -> List[AgentActionDto]:
     actions_element = self._get_metadata().find("actions")
     if actions_element is None:
         return []
     return [
         AgentActionDto(
             str(action.attrib["name"]),
             action.get("timeout"),
             action.get("interval"),
             pacemaker.role.get_value_primary(
                 const.PcmkRoleType(str(action.attrib["role"]))
             )
             if action.get("role", None) is not None
             else action.get("role"),
             action.get("start-delay"),
             action.get("depth"),
             action.get("automatic"),
             action.get("on_target"),
             None,  # ocf_check_level, TODO remove
         )
         for action in actions_element.iter("action")
         if action.get("name", None) is not None
     ]