Exemplo n.º 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)
        ],
    )
Exemplo n.º 2
0
def _bundle_network_element_to_dto(
    network_element: _Element,
) -> bundle.CibResourceBundleNetworkOptionsDto:
    return bundle.CibResourceBundleNetworkOptionsDto(
        ip_range_start=network_element.get("ip-range-start"),
        control_port=get_optional_value(
            int, network_element.get("control-port")
        ),
        host_interface=network_element.get("host-interface"),
        host_netmask=get_optional_value(
            int, network_element.get("host-netmask")
        ),
        add_host=get_optional_value(bool, network_element.get("add-host")),
    )
Exemplo n.º 3
0
def bundle_element_to_dto(
    bundle_element: _Element,
    rule_eval: Optional[rule.RuleInEffectEval] = None,
) -> bundle.CibResourceBundleDto:
    if rule_eval is None:
        rule_eval = rule.RuleInEffectEvalDummy()
    primitive_el = get_inner_resource(bundle_element)
    runtime_el = _get_container_element(bundle_element)
    network_el = bundle_element.find("network")
    return bundle.CibResourceBundleDto(
        id=str(bundle_element.attrib["id"]),
        description=bundle_element.get("description"),
        member_id=(
            str(primitive_el.attrib["id"]) if primitive_el is not None else None
        ),
        container_type=(
            bundle.ContainerType(runtime_el.tag)
            if runtime_el is not None
            else None
        ),
        container_options=(
            bundle.CibResourceBundleContainerRuntimeOptionsDto(
                image=str(runtime_el.attrib["image"]),
                replicas=get_optional_value(int, runtime_el.get("replicas")),
                replicas_per_host=get_optional_value(
                    int, runtime_el.get("replicas-per-host")
                ),
                promoted_max=get_optional_value(
                    int,
                    runtime_el.get("promoted-max") or runtime_el.get("masters"),
                ),
                run_command=runtime_el.get("run-command"),
                network=runtime_el.get("network"),
                options=runtime_el.get("options"),
            )
            if runtime_el is not None
            else None
        ),
        network=(
            _bundle_network_element_to_dto(network_el)
            if network_el is not None
            else None
        ),
        port_mappings=[
            bundle.CibResourceBundlePortMappingDto(
                id=str(net_map_el.attrib["id"]),
                port=get_optional_value(int, net_map_el.get("port")),
                internal_port=get_optional_value(
                    int, net_map_el.get("internal-port")
                ),
                range=net_map_el.get("range"),
            )
            for net_map_el in bundle_element.findall("network/port-mapping")
        ],
        storage_mappings=[
            bundle.CibResourceBundleStorageMappingDto(
                id=str(storage_el.attrib["id"]),
                source_dir=storage_el.get("source-dir"),
                source_dir_root=storage_el.get("source-dir-root"),
                target_dir=str(storage_el.attrib["target-dir"]),
                options=storage_el.get("options"),
            )
            for storage_el in bundle_element.findall("storage/storage-mapping")
        ],
        meta_attributes=[
            nvpair_multi.nvset_element_to_dto(nvset, rule_eval)
            for nvset in nvpair_multi.find_nvsets(
                bundle_element, nvpair_multi.NVSET_META
            )
        ],
        instance_attributes=[
            nvpair_multi.nvset_element_to_dto(nvset, rule_eval)
            for nvset in nvpair_multi.find_nvsets(
                bundle_element, nvpair_multi.NVSET_INSTANCE
            )
        ],
    )