From 7e026dd1dff71db0a744d38b3ac4a2d4d2aa0415 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Tue, 18 Sep 2018 07:47:03 +0000 Subject: [PATCH] Pause/Resume methods can be called by actions. Add pause and resume methods which can be called by charm actions. Change-Id: I91a1bfe1cb58abbb401356a14cb3725eaefc1138 --- charms_openstack/charm/classes.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/charms_openstack/charm/classes.py b/charms_openstack/charm/classes.py index 82bfb20..46f1977 100644 --- a/charms_openstack/charm/classes.py +++ b/charms_openstack/charm/classes.py @@ -170,6 +170,24 @@ class OpenStackCharm(BaseOpenStackCharm, version = os_utils.os_release(self.version_package) return version + def run_pause_or_resume(self, action): + """Helper to enable pause/resume action to be processed.""" + actions = { + 'pause': os_utils.pause_unit, + 'resume': os_utils.resume_unit} + pause_services = self.services + if self.haproxy_enabled(): + pause_services.append('haproxy') + actions[action](self.assess_status, services=pause_services) + + def pause(self): + """Pause the charms services.""" + self.run_pause_or_resume('pause') + + def resume(self): + """Resume the charms services.""" + self.run_pause_or_resume('resume') + class OpenStackAPICharm(OpenStackCharm): """The base class for API OS charms -- this just bakes in the default