forked from Tendrl/commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporated review comments on service use
tendrl-bug-id: Tendrl#841 bugzilla: 1583590 Signed-off-by: Anmol Sachan <[email protected]>
- Loading branch information
1 parent
e76795e
commit 051223e
Showing
3 changed files
with
138 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
73 changes: 69 additions & 4 deletions
73
tendrl/commons/objects/node/atoms/stop_integration_services/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,78 @@ | ||
from tendrl.commons.flows import service_utils | ||
from tendrl.commons import objects | ||
from tendrl.commons.utils import cmd_utils | ||
from tendrl.commons.utils import log_utils as logger | ||
from tendrl.commons.utils.service import Service | ||
|
||
|
||
class StopIntegrationServices(objects.BaseAtom): | ||
def __init__(self, *args, **kwargs): | ||
super(StopIntegrationServices, self).__init__(*args, **kwargs) | ||
|
||
def run(self): | ||
return service_utils.stop_service( | ||
["tendrl-gluster-integration"], | ||
self.parameters | ||
service = "tendrl-gluster-integration" | ||
logger.log( | ||
"info", | ||
NS.publisher_id, | ||
{ | ||
"message": "Stopping service %s on %s" | ||
% (service, NS.node_context.fqdn) | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
) | ||
srv = NS.tendrl.objects.Service(service=service) | ||
if not srv.running: | ||
logger.log( | ||
"debug", | ||
NS.publisher_id, | ||
{ | ||
"message": "Service %s not running on %s" | ||
% (service, NS.node_context.fqdn) | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
) | ||
else: | ||
stopped = Service(service_name=service, | ||
publisher_id=NS.publisher_id, | ||
enabled=True).stop() | ||
if stopped: | ||
logger.log( | ||
"info ", | ||
NS.publisher_id, | ||
{ | ||
"message": "Service %s stopped on %s" % | ||
(service, NS.node_context.fqdn) | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
) | ||
|
||
_cmd_str = "systemctl disable %s" % service | ||
cmd = cmd_utils.Command(_cmd_str) | ||
err, out, rc = cmd.run() | ||
if err: | ||
logger.log( | ||
"error", | ||
NS.publisher_id, | ||
{ | ||
"message": "Could not disable %s" | ||
" service. Error: %s" % (service, err) | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
) | ||
return False | ||
else: | ||
logger.log( | ||
"error", | ||
NS.publisher_id, | ||
{ | ||
"message": "Could not stop service %s on %s" % | ||
(service, NS.node_context.fqdn) | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
) | ||
return False | ||
return True |
73 changes: 69 additions & 4 deletions
73
tendrl/commons/objects/node/atoms/stop_monitoring_services/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,78 @@ | ||
from tendrl.commons.flows import service_utils | ||
from tendrl.commons import objects | ||
from tendrl.commons.utils import cmd_utils | ||
from tendrl.commons.utils import log_utils as logger | ||
from tendrl.commons.utils.service import Service | ||
|
||
|
||
class StopMonitoringServices(objects.BaseAtom): | ||
def __init__(self, *args, **kwargs): | ||
super(StopMonitoringServices, self).__init__(*args, **kwargs) | ||
|
||
def run(self): | ||
return service_utils.stop_service( | ||
["collectd"], | ||
self.parameters | ||
service = "collectd" | ||
logger.log( | ||
"info", | ||
NS.publisher_id, | ||
{ | ||
"message": "Stopping service %s on %s" | ||
% (service, NS.node_context.fqdn) | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
) | ||
srv = NS.tendrl.objects.Service(service=service) | ||
if not srv.running: | ||
logger.log( | ||
"debug", | ||
NS.publisher_id, | ||
{ | ||
"message": "Service %s not running on %s" | ||
% (service, NS.node_context.fqdn) | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
) | ||
else: | ||
stopped = Service(service_name=service, | ||
publisher_id=NS.publisher_id, | ||
enabled=True).stop() | ||
if stopped: | ||
logger.log( | ||
"info", | ||
NS.publisher_id, | ||
{ | ||
"message": "Service %s stopped on %s" % | ||
(service, NS.node_context.fqdn) | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
) | ||
|
||
_cmd_str = "systemctl disable %s" % service | ||
cmd = cmd_utils.Command(_cmd_str) | ||
err, out, rc = cmd.run() | ||
if err: | ||
logger.log( | ||
"error", | ||
NS.publisher_id, | ||
{ | ||
"message": "Could not disable %s" | ||
" service. Error: %s" % (service, err) | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
) | ||
return False | ||
else: | ||
logger.log( | ||
"error", | ||
NS.publisher_id, | ||
{ | ||
"message": "Could not stop service %s on %s" % | ||
(service, NS.node_context.fqdn) | ||
}, | ||
job_id=self.parameters['job_id'], | ||
flow_id=self.parameters['flow_id'], | ||
) | ||
return False | ||
return True |