def remove_levels_by_params( lib_env, level=None, target_type=None, target_value=None, devices=None, ignore_if_missing=False ): """ Remove specified fencing level(s) LibraryEnvironment lib_env -- environment int|string level -- level (index) of the fencing level to remove constant target_type -- the removed fencing level target value type mixed target_value -- the removed fencing level target value Iterable devices -- list of stonith devices of the removed fencing level bool ignore_if_missing -- when True, do not report if level not found """ cib_fencing_topology.remove_levels_by_params( lib_env.report_processor, get_fencing_topology(lib_env.get_cib()), level, target_type, target_value, devices, ignore_if_missing ) lib_env.report_processor.send() lib_env.push_cib()
def test_success_if_exists(self): self.cib.append_to_first_tag_name( "configuration", "<fencing-topology />" ) self.assertEqual( "fencing-topology", lib.get_fencing_topology(self.cib.tree).tag )
def verify(env, verbose=False): runner = env.cmd_runner() dummy_stdout, verify_stderr, verify_returncode = verify_cmd( runner, verbose=verbose, ) #1) Do not even try to think about upgrading! #2) We do not need cib management in env (no need for push...). #So env.get_cib is not best choice here (there were considerations to #upgrade cib at all times inside env.get_cib). Go to a lower level here. if verify_returncode != 0: env.report_processor.append(reports.invalid_cib_content(verify_stderr)) #Cib is sometimes loadable even if `crm_verify` fails (e.g. when #fencing topology is invalid). On the other hand cib with id duplication #is not loadable. #We try extra checks when cib is possible to load. cib_xml, dummy_stderr, returncode = get_cib_xml_cmd_results(runner) if returncode != 0: #can raise; raise LibraryError is better but in this case we prefer #be consistent with raising below env.report_processor.send() else: cib_xml = get_cib_xml(runner) cib = get_cib(cib_xml) fencing_topology.verify( env.report_processor, get_fencing_topology(cib), get_resources(cib), ClusterState(get_cluster_status_xml(runner)).node_section.nodes) #can raise env.report_processor.send()
def add_level(lib_env, level, target_type, target_value, devices, force_device=False, force_node=False): """ Validate and add a new fencing level LibraryError lib_env -- environment int|string level -- level (index) of the new fencing level constant target_type -- the new fencing level target value type mixed target_value -- the new fencing level target value Iterable devices -- list of stonith devices for the new fencing level bool force_device -- continue even if a stonith device does not exist bool force_node -- continue even if a node (target) does not exist """ version_check = None if target_type == TARGET_TYPE_REGEXP: version_check = (2, 3, 0) elif target_type == TARGET_TYPE_ATTRIBUTE: version_check = (2, 4, 0) cib = lib_env.get_cib(version_check) cib_fencing_topology.add_level( lib_env.report_processor, get_fencing_topology(cib), get_resources(cib), level, target_type, target_value, devices, ClusterState(get_cluster_status_xml( lib_env.cmd_runner())).node_section.nodes, force_device, force_node) lib_env.report_processor.send() lib_env.push_cib()
def remove_all_levels(lib_env: LibraryEnvironment): """ Remove all fencing levels LibraryEnvironment lib_env -- environment """ cib_fencing_topology.remove_all_levels( get_fencing_topology(lib_env.get_cib())) lib_env.push_cib()
def remove_all_levels(lib_env): """ Remove all fencing levels LibraryError lib_env -- environment """ cib = lib_env.get_cib() cib_fencing_topology.remove_all_levels(get_fencing_topology(cib)) lib_env.push_cib(cib)
def get_config(lib_env: LibraryEnvironment): """ Get fencing levels configuration. Return a list of levels where each level is a dict with keys: target_type, target_value. level and devices. Devices is a list of stonith device ids. LibraryEnvironment lib_env -- environment """ cib = lib_env.get_cib() return cib_fencing_topology.export(get_fencing_topology(cib))
def get_config(lib_env): """ Get fencing levels configuration. Return a list of levels where each level is a dict with keys: target_type, target_value. level and devices. Devices is a list of stonith device ids. LibraryEnvironment lib_env -- environment """ cib = lib_env.get_cib() return cib_fencing_topology.export(get_fencing_topology(cib))
def verify(lib_env): """ Check if all cluster nodes and stonith devices used in fencing levels exist LibraryError lib_env -- environment """ cib = lib_env.get_cib() cib_fencing_topology.verify( lib_env.report_processor, get_fencing_topology(cib), get_resources(cib), ClusterState(get_cluster_status_xml( lib_env.cmd_runner())).node_section.nodes) lib_env.report_processor.send()
def verify(lib_env: LibraryEnvironment): """ Check if all cluster nodes and stonith devices used in fencing levels exist LibraryEnvironment lib_env -- environment """ cib = lib_env.get_cib() lib_env.report_processor.report_list( cib_fencing_topology.verify( get_fencing_topology(cib), get_resources(cib), ClusterState(lib_env.get_cluster_state()).node_section.nodes, )) if lib_env.report_processor.has_errors: raise LibraryError()
def verify(lib_env): """ Check if all cluster nodes and stonith devices used in fencing levels exist LibraryEnvironment lib_env -- environment """ cib = lib_env.get_cib() cib_fencing_topology.verify( lib_env.report_processor, get_fencing_topology(cib), get_resources(cib), ClusterState( get_cluster_status_xml(lib_env.cmd_runner()) ).node_section.nodes ) lib_env.report_processor.send()
def add_level( lib_env, level, target_type, target_value, devices, force_device=False, force_node=False ): """ Validate and add a new fencing level LibraryEnvironment lib_env -- environment int|string level -- level (index) of the new fencing level constant target_type -- the new fencing level target value type mixed target_value -- the new fencing level target value Iterable devices -- list of stonith devices for the new fencing level bool force_device -- continue even if a stonith device does not exist bool force_node -- continue even if a node (target) does not exist """ version_check = None if target_type == TARGET_TYPE_REGEXP: version_check = Version(2, 3, 0) elif target_type == TARGET_TYPE_ATTRIBUTE: version_check = Version(2, 4, 0) cib = lib_env.get_cib(version_check) cib_fencing_topology.add_level( lib_env.report_processor, get_fencing_topology(cib), get_resources(cib), level, target_type, target_value, devices, ClusterState( get_cluster_status_xml(lib_env.cmd_runner()) ).node_section.nodes, force_device, force_node ) lib_env.report_processor.send() lib_env.push_cib()
def add_level( lib_env: LibraryEnvironment, level, target_type, target_value, devices, force_device=False, force_node=False, ): """ Validate and add a new fencing level LibraryEnvironment lib_env -- environment int|string level -- level (index) of the new fencing level constant target_type -- the new fencing level target value type mixed target_value -- the new fencing level target value Iterable devices -- list of stonith devices for the new fencing level bool force_device -- continue even if a stonith device does not exist bool force_node -- continue even if a node (target) does not exist """ cib = lib_env.get_cib() cib_fencing_topology.add_level( lib_env.report_processor, get_fencing_topology(cib), get_resources(cib), level, target_type, target_value, devices, ClusterState(lib_env.get_cluster_state()).node_section.nodes, force_device, force_node, ) if lib_env.report_processor.has_errors: raise LibraryError() lib_env.push_cib()
def test_success_if_missing(self): ft = lib.get_fencing_topology(self.cib.tree) self.assertEqual("fencing-topology", ft.tag) self.assertEqual("configuration", ft.getparent().tag)
def remove_levels_by_params( lib_env: LibraryEnvironment, level=None, # TODO create a special type, so that it cannot accept any string target_type: Optional[str] = None, target_value=None, devices: Optional[Iterable[str]] = None, # TODO remove, deprecated backward compatibility layer ignore_if_missing: bool = False, # TODO remove, deprecated backward compatibility layer target_may_be_a_device: bool = False, ): """ Remove specified fencing level(s). LibraryEnvironment lib_env -- environment int|string level -- level (index) of the fencing level to remove target_type -- the removed fencing level target value type mixed target_value -- the removed fencing level target value devices -- list of stonith devices of the removed fencing level ignore_if_missing -- when True, do not report if level not found target_may_be_a_device -- enables backward compatibility mode for old CLI """ topology_el = get_fencing_topology(lib_env.get_cib()) report_list = cib_fencing_topology.remove_levels_by_params( topology_el, level, target_type, target_value, devices, ignore_if_missing, validate_device_ids=(not target_may_be_a_device), ) if not target_may_be_a_device or target_type != TARGET_TYPE_NODE: if lib_env.report_processor.report_list(report_list).has_errors: raise LibraryError() lib_env.push_cib() return # TODO remove, deprecated backward compatibility mode # CLI command parameters are: level, node, stonith, stonith... Both the # node and the stonith list are optional. If the node is ommited and the # stonith list is present, there is no way to figure it out, since there is # no specification of what the parameter is. Hence the pre-lib code tried # both. First it assumed the first parameter is a node. If that fence level # didn't exist, it assumed the first parameter is a device. Since it was # only possible to specify node as a target back then, this is enabled only # in that case. # CLI has no way to figure out what the first parameter is. Therefore, the # lib must try both cases if asked to do so. if not report.has_errors(report_list): lib_env.report_processor.report_list(report_list) lib_env.push_cib() return level_not_found = False for report_item in report_list: if (report_item.message.code == report.codes.CIB_FENCING_LEVEL_DOES_NOT_EXIST): level_not_found = True break if not level_not_found: lib_env.report_processor.report_list(report_list) raise LibraryError() target_and_devices = [target_value] if devices: target_and_devices.extend(devices) report_list_second = cib_fencing_topology.remove_levels_by_params( topology_el, level, None, None, target_and_devices, ignore_if_missing, validate_device_ids=(not target_may_be_a_device), ) if not report.has_errors(report_list_second): lib_env.report_processor.report_list(report_list_second) lib_env.push_cib() return lib_env.report_processor.report_list(report_list) lib_env.report_processor.report_list(report_list_second) raise LibraryError()