Add module for mgmt services inside container
Change-Id: Ib61667ddfee9b24600ebe0f14b42e2f8e3f3d65b
diff --git a/_modules/dockerng_service.py b/_modules/dockerng_service.py
new file mode 100644
index 0000000..515cc0f
--- /dev/null
+++ b/_modules/dockerng_service.py
@@ -0,0 +1,90 @@
+#!/usr/bin/python
+# Copyright 2017 Mirantis, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+try:
+ import docker
+ HAS_DOCKER = True
+except ImportError:
+ HAS_DOCKER = False
+
+__opts__ = {}
+__virtualname__ = 'dockerng_service'
+
+
+def __virtual__():
+ '''
+ Only load this module if docker library is installed.
+ '''
+ if HAS_DOCKER:
+ return __virtualname__
+ return (False, 'dockerio execution module not loaded: docker python library not available.')
+
+
+def status(container, service):
+ cmd = "systemctl show " + service + " -p ActiveState,SubState,UnitFileState"
+ data = __salt__['dockerng.run'](container, cmd)
+ data = data.splitlines()
+ result = dict(s.split('=') for s in data)
+ return result
+
+
+def restart(container, service):
+ cmd = "systemctl restart " + service
+ data = __salt__['dockerng.run'](container, cmd)
+ if len(data) > 0:
+ return False
+ return True
+
+
+def stop(container, service):
+ cmd = "systemctl stop " + service
+ data = __salt__['dockerng.run'](container, cmd)
+ if len(data) > 0:
+ return False
+ return True
+
+
+def start(container, service):
+ cmd = "systemctl start " + service
+ data = __salt__['dockerng.run'](container, cmd)
+ if len(data) > 0:
+ return False
+ return True
+
+
+def enable(container, service):
+ cmd = "systemctl enable " + service
+ data = __salt__['dockerng.run'](container, cmd)
+ if len(data) > 0:
+ return False
+ return True
+
+
+def reload(container, service):
+ cmd = "systemctl reload " + service
+ data = __salt__['dockerng.run'](container, cmd)
+ if len(data) > 0:
+ return False
+ return True
+
+
+def disable(container, service):
+ cmd = "systemctl disable " + service
+ data = __salt__['dockerng.run'](container, cmd)
+ if len(data) > 0:
+ return False
+ return True
+