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) ], )
def primitive_element_to_dto( primitive_element: _Element, rule_eval: Optional[rule.RuleInEffectEval] = None, ) -> CibResourcePrimitiveDto: if rule_eval is None: rule_eval = rule.RuleInEffectEvalDummy() return CibResourcePrimitiveDto( id=str(primitive_element.attrib["id"]), agent_name=ResourceAgentNameDto( standard=str(primitive_element.attrib["class"]), provider=primitive_element.get("provider"), type=str(primitive_element.attrib["type"]), ), description=primitive_element.get("description"), operations=[ op_element_to_dto(op_element, rule_eval) for op_element in primitive_element.findall("operations/op") ], meta_attributes=[ nvpair_multi.nvset_element_to_dto(nvset, rule_eval) for nvset in nvpair_multi.find_nvsets(primitive_element, nvpair_multi.NVSET_META) ], instance_attributes=[ nvpair_multi.nvset_element_to_dto(nvset, rule_eval) for nvset in nvpair_multi.find_nvsets(primitive_element, nvpair_multi.NVSET_INSTANCE) ], utilization=[ nvpair_multi.nvset_element_to_dto(nvset, rule_eval) for nvset in nvpair_multi.find_nvsets( primitive_element, nvpair_multi.NVSET_UTILIZATION) ], )
def clone_element_to_dto( clone_element: _Element, rule_eval: Optional[rule.RuleInEffectEval] = None, ) -> CibResourceCloneDto: if rule_eval is None: rule_eval = rule.RuleInEffectEvalDummy() return CibResourceCloneDto( id=str(clone_element.attrib["id"]), description=clone_element.get("description"), member_id=str(get_inner_resource(clone_element).attrib["id"]), meta_attributes=[ nvpair_multi.nvset_element_to_dto(nvset, rule_eval) for nvset in nvpair_multi.find_nvsets(clone_element, nvpair_multi.NVSET_META) ], instance_attributes=[ nvpair_multi.nvset_element_to_dto(nvset, rule_eval) for nvset in nvpair_multi.find_nvsets(clone_element, nvpair_multi.NVSET_INSTANCE) ], )
def group_element_to_dto( group_element: _Element, rule_eval: Optional[rule.RuleInEffectEval] = None, ) -> CibResourceGroupDto: if rule_eval is None: rule_eval = rule.RuleInEffectEvalDummy() return CibResourceGroupDto( id=str(group_element.attrib["id"]), description=group_element.get("description"), member_ids=[ str(primitive_el.attrib["id"]) for primitive_el in get_inner_resources(group_element) ], meta_attributes=[ nvpair_multi.nvset_element_to_dto(nvset, rule_eval) for nvset in nvpair_multi.find_nvsets(group_element, nvpair_multi.NVSET_META) ], instance_attributes=[ nvpair_multi.nvset_element_to_dto(nvset, rule_eval) for nvset in nvpair_multi.find_nvsets(group_element, nvpair_multi.NVSET_INSTANCE) ], )
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 ) ], )