示例#1
0
def stonith(node):
    p_cfg = PacemakerConfig()

    # TODO: signal that manager that a STONITH has been done so that it
    #       doesn't treat it as an AWOL
    console_log.info("Rebooting %s per a STONITH request" % node)

    p_cfg.get_node(node).fence_reboot()
示例#2
0
def configure_fencing(agents):
    pc = PacemakerConfig()
    node = pc.get_node(socket.gethostname())

    node.clear_fence_attributes()

    if isinstance(agents, basestring):
        # For CLI debugging
        agents = json.loads(agents)

    for idx, agent in enumerate(agents):
        node.set_fence_attributes(idx, agent)

    pc.create_update_properyset("cib-bootstrap-options",
                                {"stonith-enabled": "true"})
示例#3
0
def _configure_pacemaker():
    '''
    Configure pacemaker if this node is the dc.

    :return: agent_ok if no error else returns an agent_error
    '''
    pc = PacemakerConfig()

    timeout_time = time.time() + PACEMAKER_CONFIGURE_TIMEOUT
    error = None

    while (pc.configured is False) and (time.time() < timeout_time):
        if pc.is_dc:
            daemon_log.info(
                'Configuring (global) pacemaker configuration because I am the DC'
            )

            error = _do_configure_pacemaker(pc)

            if error:
                return agent_error(error)
        else:
            daemon_log.info(
                'Not configuring (global) pacemaker configuration because I am not the DC'
            )

        time.sleep(10)

    if pc.configured is False:
        error = 'Failed to configure (global) pacemaker configuration dc=%s' % pc.dc

    return agent_ok_or_error(error)
示例#4
0
    def test_finding_fenceable_nodes(self):
        self.reset_command_capture()
        self.add_command(('cibadmin', '--query', '--local'))

        # Not strictly an agent test, but the tested method is used by
        # the agent to generate the -o list output.
        from chroma_agent.lib.pacemaker import PacemakerConfig
        p_cfg = PacemakerConfig()
        self.assertEqual(len(p_cfg.fenceable_nodes), 1)

        self.assertRanAllCommandsInOrder()
示例#5
0
def set_node_online(node):
    pc = PacemakerConfig()
    node = pc.get_node(node)
    node.disable_standby()
示例#6
0
def set_node_standby(node):
    pc = PacemakerConfig()
    node = pc.get_node(node)
    node.enable_standby()
示例#7
0
def main(args=None):
    configure_logging()

    VALID_ACTIONS = ["off", "on", "reboot", "metadata", "list", "monitor"]

    epilog = """
With no command line argument, arguments are read from standard input.
Arguments read from standard input take the form of:

    arg1=value1
    arg2=value2

  action                Action to perform (%s)
  port                  Name of node on which to perform action
""" % ", ".join(VALID_ACTIONS)

    parser = ArgumentParser(description="Chroma Fence Agent",
                            formatter_class=RawDescriptionHelpFormatter,
                            epilog=epilog)

    parser.add_argument("-o",
                        "--option",
                        "--action",
                        dest="action",
                        choices=VALID_ACTIONS)
    parser.add_argument("-n",
                        "--plug",
                        "--nodename",
                        "--port",
                        dest="port",
                        help="Name of node on which to perform action")
    ns = parser.parse_args(args)

    if not ns.action and not ns.port:
        ns = parser.parse_args(stdin_to_args())

    if ns.action == "metadata":
        print """<?xml version="1.0" ?>
<resource-agent name="fence_chroma" shortdesc="Fence agent for Integrated Manager for Lustre software Storage Servers">
<longdesc>fence_chroma is an I/O Fencing agent which can be used with Integrated Manager for Lustre software Storage Servers.</longdesc>
<vendor-url>http://www.whamcloud.com</vendor-url>
<parameters>
    <parameter name="port">
        <getopt mixed="-p" />
        <content type="string" />
        <shortdesc lang="en">Storage Server (machine name) to fence</shortdesc>
    </parameter>
    <parameter name="action">
        <getopt mixed="-o" />
        <content type="string" />
        <shortdesc lang="en">Fencing action (%s)</shortdesc>
    </parameter>
</parameters>
<actions>
    <action name="reboot" />
    <action name="off" />
    <action name="on" />
    <action name="metadata" />
    <action name="list" />
    <action name="monitor" />
</actions>
</resource-agent>
""" % ", ".join(VALID_ACTIONS)
    elif ns.action in ["on", "off"]:
        node = PacemakerConfig().get_node(ns.port)
        getattr(node, "fence_%s" % ns.action)()
    elif ns.action == "reboot":
        manage_node.stonith(ns.port)
    elif ns.action == "list":
        for node in PacemakerConfig().fenceable_nodes:
            print "%s," % node.name
    elif ns.action == "monitor":
        # TODO: What does "monitor" mean for this agent? We have to have it
        # to keep pacemaker happy, but longer-term it might make sense to
        # make this a meta-monitor, in that it invokes the monitor action for
        # all sub-agents and aggregates the results.
        sys.exit(0)
    else:
        # Supposedly impossible to get here with argparse, but one never
        # knows...
        raise RuntimeError("Invalid action: %s" % ns.action)