コード例 #1
0
ファイル: config_corosync_conf.py プロジェクト: miz-take/pcs
    def load(
        self, node_name_list=None, name="corosync_conf.load",
        auto_tie_breaker=None
    ):
        content = open(rc("corosync.conf")).read()
        corosync_conf = None
        if node_name_list:
            corosync_conf = ConfigFacade.from_string(content).config
            for nodelist in corosync_conf.get_sections(name="nodelist"):
                corosync_conf.del_section(nodelist)

            nodelist_section = Section("nodelist")
            corosync_conf.add_section(nodelist_section)
            for i, node_name in enumerate(node_name_list):
                node_section = Section("node")
                node_section.add_attribute("ring0_addr", node_name)
                node_section.add_attribute("nodeid", i)
                nodelist_section.add_section(node_section)


        if auto_tie_breaker is not None:
            corosync_conf = (
                corosync_conf if corosync_conf
                else ConfigFacade.from_string(content).config
            )
            for quorum in corosync_conf.get_sections(name="quorum"):
                quorum.set_attribute(
                    "auto_tie_breaker",
                    "1" if auto_tie_breaker else  "0"
                )

        if corosync_conf:
            content = corosync_conf.export()

        self.load_content(content, name)
コード例 #2
0
    def test_bad_all(self):
        section = CorosyncSection("sec#tion")
        section.add_attribute("na#me", "va}l{ue")
        new_conf = CorosyncConfigFacade(section)

        env = self.env_assistant.get_env()
        assert_raise_library_error(
            lambda: env.push_corosync_conf(new_conf),
            fixture.error(
                report_codes.COROSYNC_CONFIG_CANNOT_SAVE_INVALID_NAMES_VALUES,
                section_name_list=["sec#tion"],
                attribute_name_list=["sec#tion.na#me"],
                attribute_value_pairs=[("sec#tion.na#me", "va}l{ue")],
            ))
コード例 #3
0
    def load(
        self, node_name_list=None, name="corosync_conf.load",
        filename="corosync.conf", auto_tie_breaker=None, instead=None
    ):
        content = open(rc(filename)).read()
        corosync_conf = None
        if node_name_list:
            corosync_conf = ConfigFacade.from_string(content).config
            for nodelist in corosync_conf.get_sections(name="nodelist"):
                corosync_conf.del_section(nodelist)

            nodelist_section = Section("nodelist")
            corosync_conf.add_section(nodelist_section)
            for i, node_name in enumerate(node_name_list):
                node_section = Section("node")
                node_section.add_attribute("ring0_addr", node_name)
                node_section.add_attribute("nodeid", i)
                node_section.add_attribute("name", node_name)
                nodelist_section.add_section(node_section)


        if auto_tie_breaker is not None:
            corosync_conf = (
                corosync_conf if corosync_conf
                else ConfigFacade.from_string(content).config
            )
            for quorum in corosync_conf.get_sections(name="quorum"):
                quorum.set_attribute(
                    "auto_tie_breaker",
                    "1" if auto_tie_breaker else  "0"
                )

        if corosync_conf:
            content = corosync_conf.export()

        self.load_content(content, name=name, instead=instead)
コード例 #4
0
ファイル: config_corosync_conf.py プロジェクト: zht750808/pcs
    def load(
        self,
        node_name_list=None,
        name="corosync_conf.load",
        filename="corosync.conf",
        auto_tie_breaker=None,
        instead=None,
    ):
        # pylint: disable=too-many-locals
        with open(rc(filename)) as a_file:
            content = a_file.read()
        corosync_conf = None
        if node_name_list:
            corosync_conf = ConfigFacade(
                Parser.parse(content.encode("utf-8"))
            ).config
            for nodelist in corosync_conf.get_sections(name="nodelist"):
                corosync_conf.del_section(nodelist)

            nodelist_section = Section("nodelist")
            corosync_conf.add_section(nodelist_section)
            for i, node_name in enumerate(node_name_list):
                node_section = Section("node")
                node_section.add_attribute("ring0_addr", node_name)
                node_section.add_attribute("nodeid", i)
                node_section.add_attribute("name", node_name)
                nodelist_section.add_section(node_section)

        if auto_tie_breaker is not None:
            corosync_conf = (
                corosync_conf
                if corosync_conf
                else ConfigFacade(Parser.parse(content.encode("utf-8"))).config
            )
            for quorum in corosync_conf.get_sections(name="quorum"):
                quorum.set_attribute(
                    "auto_tie_breaker", "1" if auto_tie_breaker else "0"
                )

        if corosync_conf:
            content = corosync_conf.export()

        self.load_content(content, name=name, instead=instead)