#!/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 status_retcode(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)
    if result['ActiveState'] == "active" and result['SubState'] == "running":
        return True
    return False


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
