def validate_create( existing_nodes_names, existing_nodes_addrs, resource_agent, new_node_name, new_node_addr, instance_attributes ): """ validate inputs for create list of string existing_nodes_names -- node names already in use list of string existing_nodes_addrs -- node addresses already in use ResourceAgent resource_agent -- pacemaker_remote resource agent string new_node_name -- the name of the future node string new_node_addr -- the address of the future node dict instance_attributes -- data for the future resource instance attributes """ report_list = _validate_server_not_used(resource_agent, instance_attributes) addr_is_used = False if new_node_addr in existing_nodes_addrs: report_list.append(reports.id_already_exists(new_node_addr)) addr_is_used = True if not addr_is_used or new_node_addr != new_node_name: if new_node_name in existing_nodes_names: report_list.append(reports.id_already_exists(new_node_name)) return report_list
def validate_conflicts(tree, existing_nodes_names, existing_nodes_addrs, node_name, options): report_list = [] if (does_id_exist(tree, node_name) or node_name in existing_nodes_names or ("remote-addr" not in options and node_name in existing_nodes_addrs)): report_list.append(reports.id_already_exists(node_name)) if ("remote-addr" in options and options["remote-addr"] in existing_nodes_addrs): report_list.append(reports.id_already_exists(options["remote-addr"])) return report_list
def validate_conflicts(tree, nodes, node_name, options): report_list = [] if (does_id_exist(tree, node_name) or node_addresses_contain_name(nodes, node_name) or ("remote-addr" not in options and node_addresses_contain_host(nodes, node_name))): report_list.append(reports.id_already_exists(node_name)) if ("remote-addr" in options and node_addresses_contain_host(nodes, options["remote-addr"])): report_list.append(reports.id_already_exists(options["remote-addr"])) return report_list
def append_new_operation(operations_element, options): """ Create op element and apend it to operations_element. etree operations_element is the context element dict options are attributes of operation """ attribute_map = dict((key, value) for key, value in options.items() if key not in OPERATION_NVPAIR_ATTRIBUTES) if "id" in attribute_map: if does_id_exist(operations_element, attribute_map["id"]): raise LibraryError(reports.id_already_exists(attribute_map["id"])) else: attribute_map.update({ "id": create_id(operations_element.getparent(), options["name"], options["interval"]) }) op_element = etree.SubElement( operations_element, "op", attribute_map, ) nvpair_attribute_map = dict((key, value) for key, value in options.items() if key in OPERATION_NVPAIR_ATTRIBUTES) if nvpair_attribute_map: append_new_instance_attributes(op_element, nvpair_attribute_map) return op_element
def validate_host_not_conflicts( existing_nodes_addrs, node_name, instance_attributes ): host = instance_attributes.get("server", node_name) if host in existing_nodes_addrs: return [reports.id_already_exists(host)] return []
def validate_create(nodes, resource_agent, host, node_name, instance_attributes): """ validate inputs for create list of NodeAddresses nodes -- nodes already used string node_name -- name of future node dict instance_attributes -- data for future resource instance attributes """ report_list = _validate_server_not_used(resource_agent, instance_attributes) host_is_used = False if node_addresses_contain_host(nodes, host): report_list.append(reports.id_already_exists(host)) host_is_used = True if not host_is_used or host != node_name: if node_addresses_contain_name(nodes, node_name): report_list.append(reports.id_already_exists(node_name)) return report_list
def book_ids(self, *id_list): """ Check if the ids are not already used and reserve them for future use strings *id_list -- ids """ reported_ids = set() report_list = [] for id in id_list: if id in reported_ids: continue if id in self._booked_ids or does_id_exist(self._cib, id): report_list.append(reports.id_already_exists(id)) reported_ids.add(id) continue self._booked_ids.add(id) return report_list
def book_ids(self, *id_list): """ Check if the ids are not already used and reserve them for future use strings *id_list -- ids """ reported_ids = set() report_list = [] for _id in id_list: if _id in reported_ids: continue if _id in self._booked_ids or does_id_exist(self._cib, _id): report_list.append(reports.id_already_exists(_id)) reported_ids.add(_id) continue self._booked_ids.add(_id) return report_list
def create( report_processor, resources_section, resource_id, resource_agent, raw_operation_list=None, meta_attributes=None, instance_attributes=None, allow_invalid_operation=False, allow_invalid_instance_attributes=False, use_default_operations=True, resource_type="resource" ): """ Prepare all parts of primitive resource and append it into cib. report_processor is a tool for warning/info/error reporting etree.Element resources_section is place where new element will be appended string resource_id is id of new resource lib.resource_agent.CrmAgent resource_agent list of dict raw_operation_list specifies operations of resource dict meta_attributes specifies meta attributes of resource dict instance_attributes specifies instance attributes of resource bool allow_invalid_operation is flag for skipping validation of operations bool allow_invalid_instance_attributes is flag for skipping validation of instance_attributes bool use_default_operations is flag for completion operations with default actions specified in resource agent string resource_type -- describes the resource for reports """ if raw_operation_list is None: raw_operation_list = [] if meta_attributes is None: meta_attributes = {} if instance_attributes is None: instance_attributes = {} if does_id_exist(resources_section, resource_id): raise LibraryError(reports.id_already_exists(resource_id)) validate_id(resource_id, "{0} name".format(resource_type)) operation_list = prepare_operations( report_processor, raw_operation_list, resource_agent.get_cib_default_actions( necessary_only=not use_default_operations ), [operation["name"] for operation in resource_agent.get_actions()], allow_invalid=allow_invalid_operation, ) report_processor.process_list( resource_agent.validate_parameters( instance_attributes, parameters_type=resource_type, allow_invalid=allow_invalid_instance_attributes, ) ) return append_new( resources_section, resource_id, resource_agent.get_standard(), resource_agent.get_provider(), resource_agent.get_type(), instance_attributes=instance_attributes, meta_attributes=meta_attributes, operation_list=operation_list )
def validate_id_does_not_exist(tree, id): """ tree cib etree node """ if does_id_exist(tree, id): raise LibraryError(reports.id_already_exists(id))
def validate_host_not_conflicts(nodes, node_name, instance_attributes): host = instance_attributes.get("server", node_name) if node_addresses_contain_host(nodes, host): return [reports.id_already_exists(host)] return []
def create( report_processor: ReportProcessor, resources_section, id_provider, resource_id, resource_agent, raw_operation_list=None, meta_attributes=None, instance_attributes=None, allow_invalid_operation=False, allow_invalid_instance_attributes=False, use_default_operations=True, resource_type="resource", do_not_report_instance_attribute_server_exists=False # TODO remove this arg ): # pylint: disable=too-many-arguments """ Prepare all parts of primitive resource and append it into cib. report_processor is a tool for warning/info/error reporting etree.Element resources_section is place where new element will be appended IdProvider id_provider -- elements' ids generator string resource_id is id of new resource lib.resource_agent.CrmAgent resource_agent list of dict raw_operation_list specifies operations of resource dict meta_attributes specifies meta attributes of resource dict instance_attributes specifies instance attributes of resource bool allow_invalid_operation is flag for skipping validation of operations bool allow_invalid_instance_attributes is flag for skipping validation of instance_attributes bool use_default_operations is flag for completion operations with default actions specified in resource agent string resource_type -- describes the resource for reports bool do_not_report_instance_attribute_server_exists -- dirty fix due to suboptimal architecture, TODO: fix the architecture and remove the param """ if raw_operation_list is None: raw_operation_list = [] if meta_attributes is None: meta_attributes = {} if instance_attributes is None: instance_attributes = {} if does_id_exist(resources_section, resource_id): raise LibraryError(reports.id_already_exists(resource_id)) validate_id(resource_id, "{0} name".format(resource_type)) operation_list = prepare_operations( report_processor, raw_operation_list, resource_agent.get_cib_default_actions( necessary_only=not use_default_operations ), [operation["name"] for operation in resource_agent.get_actions()], allow_invalid=allow_invalid_operation, ) if report_processor.report_list( validate_resource_instance_attributes_create( resource_agent, instance_attributes, resources_section, force=allow_invalid_instance_attributes, do_not_report_instance_attribute_server_exists=( do_not_report_instance_attribute_server_exists ) ) ).has_errors: raise LibraryError() return append_new( resources_section, id_provider, resource_id, resource_agent.get_standard(), resource_agent.get_provider(), resource_agent.get_type(), instance_attributes=instance_attributes, meta_attributes=meta_attributes, operation_list=operation_list )
def create( report_processor, resources_section, resource_id, resource_agent, raw_operation_list=None, meta_attributes=None, instance_attributes=None, allow_invalid_operation=False, allow_invalid_instance_attributes=False, use_default_operations=True, ensure_disabled=False, ): """ Prepare all parts of primitive resource and append it into cib. report_processor is a tool for warning/info/error reporting etree.Element resources_section is place where new element will be appended string resource_id is id of new resource lib.resource_agent.CrmAgent resource_agent list of dict raw_operation_list specifies operations of resource dict meta_attributes specifies meta attributes of resource dict instance_attributes specifies instance attributes of resource bool allow_invalid_operation is flag for skipping validation of operations bool allow_invalid_instance_attributes is flag for skipping validation of instance_attributes bool use_default_operations is flag for completion operations with default actions specified in resource agent bool ensure_disabled is flag for completion meta_attributes with attribute causing disabling resource """ if raw_operation_list is None: raw_operation_list = [] if meta_attributes is None: meta_attributes = {} if instance_attributes is None: instance_attributes = {} if does_id_exist(resources_section, resource_id): raise LibraryError(reports.id_already_exists(resource_id)) validate_id(resource_id, "resource name") operation_list = prepare_operations( report_processor, raw_operation_list, resource_agent.get_cib_default_actions( necessary_only=not use_default_operations ), [operation["name"] for operation in resource_agent.get_actions()], allow_invalid=allow_invalid_operation, ) if ensure_disabled: meta_attributes = disable_meta(meta_attributes) report_processor.process_list( resource_agent.validate_parameters( instance_attributes, parameters_type="resource", allow_invalid=allow_invalid_instance_attributes, ) ) return append_new( resources_section, resource_id, resource_agent.get_standard(), resource_agent.get_provider(), resource_agent.get_type(), instance_attributes=instance_attributes, meta_attributes=meta_attributes, operation_list=operation_list )