Move actions to action.py

This commit is contained in:
Alberto Donato 2015-08-19 09:22:21 +03:00
parent 53f2db4369
commit 324ae4684c
4 changed files with 57 additions and 38 deletions

View File

@ -4,3 +4,4 @@ exclude_lines =
if __name__ == .__main__.:
include=
hooks/keystone_*
actions/actions.py

54
actions/actions.py Executable file
View File

@ -0,0 +1,54 @@
import sys
import os
from charmhelpers.core.host import service_pause, service_resume
from charmhelpers.core.hookenv import action_fail, status_set
from hooks.keystone_utils import services
def pause(args):
"""Pause all the swift services.
@raises Exception if any services fail to stop
"""
for service in services():
stopped = service_pause(service)
if not stopped:
raise Exception("{} didn't stop cleanly.".format(service))
status_set(
"maintenance", "Paused. Use 'resume' action to resume normal service.")
def resume(args):
"""Resume all the swift services.
@raises Exception if any services fail to start
"""
for service in services():
started = service_resume(service)
if not started:
raise Exception("{} didn't start cleanly.".format(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))

View File

@ -1,19 +0,0 @@
#!/usr/bin/python
import sys
from charmhelpers.core import hookenv, host
from hooks.keystone_utils import services
def pause_service(service):
result = host.service_pause(service)
if not result:
hookenv.action_fail("Failed to pause service {}.".format(service))
return result
if __name__ == "__main__":
for service in services():
if not pause_service(service):
sys.exit(-1)

1
actions/pause Symbolic link
View File

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

View File

@ -1,19 +0,0 @@
#!/usr/bin/python
import sys
from charmhelpers.core import hookenv, host
from hooks.keystone_utils import services
def resume_service(service):
result = host.service_resume(service)
if not result:
hookenv.action_fail("Failed to resume service {}.".format(service))
return result
if __name__ == "__main__":
for service in services():
if not resume_service(service):
sys.exit(-1)

1
actions/resume Symbolic link
View File

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