Switch to symlinked actions instead of one file per action.

This commit is contained in:
Geoffrey J. Teale 2015-08-19 11:26:45 +02:00
parent b477c275a0
commit 611e506e0b
3 changed files with 53 additions and 21 deletions

51
actions/actions.py Normal file
View File

@ -0,0 +1,51 @@
#!/usr/bin/python
import os
import sys
from charmhelpers.core.host import service_pause, service_resume
from charmhelpers.core.hookenv import action_fail, status_set
MYSQL_SERVICE = "mysql"
def pause():
"""Pause the MySQL service.
@raises Exception should the service fail to stop.
"""
if not service_pause(MYSQL_SERVICE):
raise Exception("Failed to pause MySQL service.")
status_set(
"maintenance", "Paused. Use 'resume' action to resume normal service.")
def resume():
"""Resume the MySQL service.
@raises Exception should the service fail to start."""
if not service_resume(MYSQL_SERVICE):
raise Exception("Failed to resume MySQL service.")
status_set("active", "")
# A dictionary of all the defined actions to callables (which take
# parsed arguments).
ACTIONS = {"pause": pause, "resume": resume}
def main(args):
action_name = os.path.basename(args[0])
try:
action = ACTIONS[action_name]
except KeyError:
return "Action %s undefined" % action_name
else:
try:
action(args)
except Exception as e:
action_fail(str(e))
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))

View File

@ -1,9 +0,0 @@
#!/usr/bin/python
import sys
from charmhelpers.core import hookenv, host
if __name__ == "__main__":
if not host.service_pause("mysql"):
hookenv.action_fail("Failed to pause MySQL service.")
sys.exit(-1)

1
actions/pause Symbolic link
View File

@ -0,0 +1 @@
actions.py

View File

@ -1,12 +0,0 @@
#!/usr/bin/python
import os
import sys
from charmhelpers.core import hookenv, host
if __name__ == "__main__":
if not host.service_resume("mysql"):
hookenv.action_fail("Failed to resume MySQL service.")
sys.exit(-1)

1
actions/resume Symbolic link
View File

@ -0,0 +1 @@
actions.py