Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE
fence-agents.9831
0003-fence_gce-add-power-cycle-as-default-metho...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0003-fence_gce-add-power-cycle-as-default-method.patch of Package fence-agents.9831
From 8ae1af8068d1718a861a25bf954e14392384fa55 Mon Sep 17 00:00:00 2001 From: Helen Koike <helen.koike@collabora.com> Date: Wed, 4 Jul 2018 09:25:46 -0300 Subject: [PATCH 3/7] fence_gce: add power cycle as default method Add function to power cycle an instance and set cycle as the default method to reboot. --- agents/gce/fence_gce.py | 21 +++++++++++++++++++-- tests/data/metadata/fence_gce.xml | 8 ++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/fence/agents/gce/fence_gce.py b/fence/agents/gce/fence_gce.py index e53dc5a6..3f77dc24 100644 --- a/fence/agents/gce/fence_gce.py +++ b/fence/agents/gce/fence_gce.py @@ -83,6 +83,21 @@ def set_power_status(conn, options): fail_usage("Failed: set_power_status: {}".format(str(err))) +def power_cycle(conn, options): + try: + LOGGER.info('Issuing reset of %s in zone %s' % (options["--plug"], options["--zone"])) + operation = conn.instances().reset( + project=options["--project"], + zone=options["--zone"], + instance=options["--plug"]).execute() + wait_for_operation(conn, options["--project"], options["--zone"], operation) + LOGGER.info('Reset of %s in zone %s complete' % (options["--plug"], options["--zone"])) + return True + except Exception as err: + LOGGER.error("Failed: power_cycle: {}".format(str(err))) + return False + + def get_instance(conn, project, zone, instance): request = conn.instances().get( project=project, zone=zone, instance=instance) @@ -161,13 +176,15 @@ def main(): hostname = platform.node() - device_opt = ["port", "no_password", "zone", "project", "logging"] + device_opt = ["port", "no_password", "zone", "project", "logging", "method"] atexit.register(atexit_handler) define_new_opts() all_opt["power_timeout"]["default"] = "60" + all_opt["method"]["default"] = "cycle" + all_opt["method"]["help"] = "-m, --method=[method] Method to fence (onoff|cycle) (Default: cycle)" options = check_input(device_opt, process_input(device_opt)) @@ -225,7 +242,7 @@ def main(): fail_usage("Failed retrieving GCE zone. Please provide --zone option: {}".format(str(err))) # Operate the fencing device - result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list) + result = fence_action(conn, options, set_power_status, get_power_status, get_nodes_list, power_cycle) sys.exit(result) if __name__ == "__main__": diff --git a/tests/data/metadata/fence_gce.xml b/tests/data/metadata/fence_gce.xml index 507b8385..f522550f 100644 --- a/tests/data/metadata/fence_gce.xml +++ b/tests/data/metadata/fence_gce.xml @@ -10,6 +10,14 @@ For instructions see: https://cloud.google.com/compute/docs/tutorials/python-gui <content type="string" default="reboot" /> <shortdesc lang="en">Fencing action</shortdesc> </parameter> + <parameter name="method" unique="0" required="0"> + <getopt mixed="-m, --method=[method]" /> + <content type="select" default="cycle" > + <option value="onoff" /> + <option value="cycle" /> + </content> + <shortdesc lang="en">Method to fence</shortdesc> + </parameter> <parameter name="plug" unique="0" required="1" obsoletes="port"> <getopt mixed="-n, --plug=[id]" /> <content type="string" /> -- 2.16.4
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor