def _set_any_defaults(section_name, env: LibraryEnvironment, options): """ string section_name -- determine the section of defaults env -- provides access to outside environment dict options -- are desired options with its values; when value is empty the option have to be removed """ # Do not ever remove the nvset element, even if it is empty. There may be # ACLs set in pacemaker which allow "write" for nvpairs (adding, changing # and removing) but not nvsets. In such a case, removing the nvset would # cause the whole change to be rejected by pacemaker with a "permission # denied" message. # https://bugzilla.redhat.com/show_bug.cgi?id=1642514 env.report_processor.report( ReportItem.warning(reports.messages.DefaultsCanBeOverriden())) if not options: return cib = env.get_cib() # Do not create new defaults element if we are only removing values from it. only_removing = True for value in options.values(): if value != "": only_removing = False break if only_removing and not sections.exists(cib, section_name): return defaults_section = sections.get(cib, section_name) arrange_first_meta_attributes( defaults_section, options, IdProvider(cib), new_id="{0}-options".format(section_name), ) env.push_cib()
def _set_any_defaults(section_name, env, options): """ string section_name -- determine the section of defaults LibraryEnvironment env -- provides access to outside environment dict options -- are desired options with its values; when value is empty the option have to be removed """ # Do not ever remove the nvset element, even if it is empty. There may be # ACLs set in pacemaker which allow "write" for nvpairs (adding, changing # and removing) but not nvsets. In such a case, removing the nvset would # cause the whole change to be rejected by pacemaker with a "permission # denied" message. # https://bugzilla.redhat.com/show_bug.cgi?id=1642514 env.report_processor.process(reports.defaults_can_be_overriden()) if not options: return cib = env.get_cib() # Do not create new defaults element if we are only removing values from it. only_removing = True for value in options.values(): if value != "": only_removing = False break if only_removing and not sections.exists(cib, section_name): return defaults_section = sections.get(cib, section_name) arrange_first_meta_attributes( defaults_section, options, IdProvider(cib), new_id="{0}-options".format(section_name), ) env.push_cib()
def _defaults_update( env: LibraryEnvironment, cib_section_name: str, nvset_id: Optional[str], nvpairs: Mapping[str, str], pcs_command: reports.types.PcsCommand, ) -> None: cib = env.get_cib() id_provider = IdProvider(cib) if nvset_id is None: # Backward compatibility code to support an old use case where no id # was requested and provided and the first meta_attributes nvset was # created / updated. However, we check that there is only one nvset # present in the CIB to prevent breaking the configuration with # multiple nvsets in place. # This is to be supported as it provides means of easily managing # defaults if only one set of defaults is needed. # TODO move this to a separate lib command. if not nvpairs: return # Do not create new defaults element if we are only removing values # from it. only_removing = True for value in nvpairs.values(): if value != "": only_removing = False break if only_removing and not sections.exists(cib, cib_section_name): env.report_processor.report( ReportItem.warning(reports.messages.DefaultsCanBeOverriden())) return nvset_elements = nvpair_multi.find_nvsets( sections.get(cib, cib_section_name)) if len(nvset_elements) > 1: env.report_processor.report( reports.item.ReportItem.error( reports.messages.CibNvsetAmbiguousProvideNvsetId( pcs_command))) raise LibraryError() env.report_processor.report( ReportItem.warning(reports.messages.DefaultsCanBeOverriden())) if len(nvset_elements) == 1: nvpair_multi.nvset_update(nvset_elements[0], id_provider, nvpairs) elif only_removing: # do not create new nvset if there is none and we are only removing # nvpairs return else: nvpair_multi.nvset_append_new( sections.get(cib, cib_section_name), id_provider, nvpair_multi.NVSET_META, nvpairs, {}, ) env.push_cib() return nvset_elements, report_list = nvpair_multi.find_nvsets_by_ids( sections.get(cib, cib_section_name), [nvset_id]) if env.report_processor.report_list(report_list).has_errors: raise LibraryError() nvpair_multi.nvset_update(nvset_elements[0], id_provider, nvpairs) env.report_processor.report( ReportItem.warning(reports.messages.DefaultsCanBeOverriden())) env.push_cib()