def update_alert(lib_env, alert_id, path, instance_attribute_dict, meta_attribute_dict, description=None): """ Update existing alert with specified id. lib_env -- LibraryEnvironment alert_id -- id of alert to be updated path -- new path, if None old value will stay unchanged instance_attribute_dict -- dictionary of instance attributes to update meta_attribute_dict -- dictionary of meta attributes to update description -- new description, if empty string, old description will be deleted, if None old value will stay unchanged """ cib = lib_env.get_cib(REQUIRED_CIB_VERSION) id_provider = IdProvider(cib) alert_el = alert.update_alert(cib, alert_id, path, description) arrange_first_instance_attributes(alert_el, instance_attribute_dict, id_provider) arrange_first_meta_attributes(alert_el, meta_attribute_dict, id_provider) lib_env.push_cib()
def update_alert( lib_env, alert_id, path, instance_attribute_dict, meta_attribute_dict, description=None ): """ Update existing alert with specified id. lib_env -- LibraryEnvironment alert_id -- id of alert to be updated path -- new path, if None old value will stay unchanged instance_attribute_dict -- dictionary of instance attributes to update meta_attribute_dict -- dictionary of meta attributes to update description -- new description, if empty string, old description will be deleted, if None old value will stay unchanged """ cib = lib_env.get_cib(REQUIRED_CIB_VERSION) id_provider = IdProvider(cib) alert_el = alert.update_alert(cib, alert_id, path, description) arrange_first_instance_attributes( alert_el, instance_attribute_dict, id_provider ) arrange_first_meta_attributes( alert_el, meta_attribute_dict, id_provider ) lib_env.push_cib()
def create_alert(lib_env, alert_id, path, instance_attribute_dict, meta_attribute_dict, description=None): """ Create new alert. Raises LibraryError if path is not specified, or any other failure. lib_env -- LibraryEnvironment alert_id -- id of alert to be created, if None it will be generated path -- path to script for alert instance_attribute_dict -- dictionary of instance attributes meta_attribute_dict -- dictionary of meta attributes description -- alert description description """ if not path: raise LibraryError(reports.required_option_is_missing(["path"])) cib = lib_env.get_cib(REQUIRED_CIB_VERSION) id_provider = IdProvider(cib) alert_el = alert.create_alert(cib, alert_id, path, description) arrange_first_instance_attributes(alert_el, instance_attribute_dict, id_provider) arrange_first_meta_attributes(alert_el, meta_attribute_dict, id_provider) lib_env.push_cib()
def create_alert( lib_env, alert_id, path, instance_attribute_dict, meta_attribute_dict, description=None ): """ Create new alert. Raises LibraryError if path is not specified, or any other failure. lib_env -- LibraryEnvironment alert_id -- id of alert to be created, if None it will be generated path -- path to script for alert instance_attribute_dict -- dictionary of instance attributes meta_attribute_dict -- dictionary of meta attributes description -- alert description description """ if not path: raise LibraryError(reports.required_option_is_missing(["path"])) cib = lib_env.get_cib(REQUIRED_CIB_VERSION) id_provider = IdProvider(cib) alert_el = alert.create_alert(cib, alert_id, path, description) arrange_first_instance_attributes( alert_el, instance_attribute_dict, id_provider ) arrange_first_meta_attributes( alert_el, meta_attribute_dict, id_provider ) lib_env.push_cib()
def add_recipient( lib_env, alert_id, recipient_value, instance_attribute_dict, meta_attribute_dict, recipient_id=None, description=None, allow_same_value=False ): """ Add new recipient to alert witch id alert_id. lib_env -- LibraryEnvironment alert_id -- id of alert to which new recipient should be added recipient_value -- value of new recipient instance_attribute_dict -- dictionary of instance attributes to update meta_attribute_dict -- dictionary of meta attributes to update recipient_id -- id of new recipient, if None it will be generated description -- recipient description allow_same_value -- if True unique recipient value is not required """ if not recipient_value: raise LibraryError( reports.required_option_is_missing(["value"]) ) cib = lib_env.get_cib(REQUIRED_CIB_VERSION) id_provider = IdProvider(cib) recipient = alert.add_recipient( lib_env.report_processor, cib, alert_id, recipient_value, recipient_id=recipient_id, description=description, allow_same_value=allow_same_value ) arrange_first_instance_attributes( recipient, instance_attribute_dict, id_provider ) arrange_first_meta_attributes( recipient, meta_attribute_dict, id_provider ) lib_env.push_cib()
def add_recipient( lib_env, alert_id, recipient_value, instance_attribute_dict, meta_attribute_dict, recipient_id=None, description=None, allow_same_value=False ): """ Add new recipient to alert witch id alert_id. lib_env -- LibraryEnvironment alert_id -- id of alert to which new recipient should be added recipient_value -- value of new recipient instance_attribute_dict -- dictionary of instance attributes to update meta_attribute_dict -- dictionary of meta attributes to update recipient_id -- id of new recipient, if None it will be generated description -- recipient description allow_same_value -- if True unique recipient value is not required """ if not recipient_value: raise LibraryError( reports.required_options_are_missing(["value"]) ) cib = lib_env.get_cib(REQUIRED_CIB_VERSION) id_provider = IdProvider(cib) recipient = alert.add_recipient( lib_env.report_processor, cib, alert_id, recipient_value, recipient_id=recipient_id, description=description, allow_same_value=allow_same_value ) arrange_first_instance_attributes( recipient, instance_attribute_dict, id_provider ) arrange_first_meta_attributes( recipient, meta_attribute_dict, id_provider ) lib_env.push_cib()
def update_recipient( lib_env, recipient_id, instance_attribute_dict, meta_attribute_dict, recipient_value=None, description=None, allow_same_value=False ): """ Update existing recipient. lib_env -- LibraryEnvironment recipient_id -- id of recipient to be updated instance_attribute_dict -- dictionary of instance attributes to update meta_attribute_dict -- dictionary of meta attributes to update recipient_value -- new recipient value, if None old value will stay unchanged description -- new description, if empty string, old description will be deleted, if None old value will stay unchanged allow_same_value -- if True unique recipient value is not required """ if not recipient_value and recipient_value is not None: raise LibraryError( reports.cib_alert_recipient_invalid_value(recipient_value) ) cib = lib_env.get_cib(REQUIRED_CIB_VERSION) id_provider = IdProvider(cib) recipient = alert.update_recipient( lib_env.report_processor, cib, recipient_id, recipient_value=recipient_value, description=description, allow_same_value=allow_same_value ) arrange_first_instance_attributes( recipient, instance_attribute_dict, id_provider ) arrange_first_meta_attributes( recipient, meta_attribute_dict, id_provider ) lib_env.push_cib()
def update_scsi_devices_without_restart( runner: CommandRunner, cluster_state: _Element, resource_el: _Element, id_provider: IdProvider, devices_list: Iterable[str], ) -> None: """ Update scsi devices without restart of stonith resource or other resources. runner -- command runner instance cluster_state -- status of the cluster resource_el -- resource element being updated id_provider -- elements' ids generator device_list -- list of updated scsi devices """ resource_id = resource_el.get("id", "") roles_with_nodes = get_resource_state(cluster_state, resource_id) if "Started" not in roles_with_nodes: raise LibraryError( ReportItem.error( reports.messages.StonithRestartlessUpdateUnableToPerform( f"resource '{resource_id}' is not running on any node", reason_type=reports.const. STONITH_RESTARTLESS_UPDATE_UNABLE_TO_PERFORM_REASON_NOT_RUNNING, ))) if len(roles_with_nodes["Started"]) != 1: # TODO: do we want to be able update cloned fence_scsi? Or just case # when it's running on more than 1 node? It is possible but we need to # update more lrm_rsc_op elements raise LibraryError( ReportItem.error( reports.messages.StonithRestartlessUpdateUnableToPerform( f"resource '{resource_id}' is running on more than 1 node") )) node_name = roles_with_nodes["Started"][0] new_instance_attrs = {"devices": ",".join(sorted(devices_list))} arrange_first_instance_attributes(resource_el, new_instance_attrs, id_provider) lrm_rsc_op_start_list = _get_lrm_rsc_op_elements(get_root(resource_el), resource_id, node_name, "start") if len(lrm_rsc_op_start_list) == 1: _update_digest_attrs_in_lrm_rsc_op( lrm_rsc_op_start_list[0], get_resource_digests( runner, resource_id, node_name, new_instance_attrs, ), ) else: raise LibraryError( ReportItem.error( reports.messages.StonithRestartlessUpdateUnableToPerform( "lrm_rsc_op element for start operation was not found"))) monitor_attrs_list = _get_monitor_attrs(resource_el) lrm_rsc_op_monitor_list = _get_lrm_rsc_op_elements(get_root(resource_el), resource_id, node_name, "monitor") if len(lrm_rsc_op_monitor_list) != len(monitor_attrs_list): raise LibraryError( ReportItem.error( reports.messages.StonithRestartlessUpdateUnableToPerform( ("number of lrm_rsc_op and op elements for monitor " "operation differs")))) for monitor_attrs in monitor_attrs_list: lrm_rsc_op_list = _get_lrm_rsc_op_elements( get_root(resource_el), resource_id, node_name, "monitor", monitor_attrs["interval"], ) if len(lrm_rsc_op_list) == 1: _update_digest_attrs_in_lrm_rsc_op( lrm_rsc_op_list[0], get_resource_digests( runner, resource_id, node_name, new_instance_attrs, crm_meta_attributes=monitor_attrs, ), ) else: raise LibraryError( ReportItem.error( reports.messages.StonithRestartlessUpdateUnableToPerform( ("monitor lrm_rsc_op element for resource " f"'{resource_id}', node '{node_name}' and interval " f"'{monitor_attrs['interval']}' not found"))))