Skip to content

Commit

Permalink
Export user-facing types in root namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
LourensVeen committed Feb 11, 2019
1 parent 8a58a7a commit 0b47b33
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 14 additions & 0 deletions cerise_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@

__author__ = "Lourens Veen"
__email__ = '[email protected]'


from cerise_manager.errors import (
ServiceNotFound, ServiceAlreadyExists, PortNotAvailable,
CommunicationError)

from cerise_manager.service import (
create_service, destroy_service, service_exists, get_service,
require_service, service_to_dict, service_from_dict, ManagedService)

__all__ = ['ServiceNotFound', 'ServiceAlreadyExists', 'PortNotAvailable',
'CommunicationError', 'create_service', 'destroy_service',
'service_exists', 'get_service', 'require_service',
'service_to_dict', 'service_from_dict', 'ManagedService']
13 changes: 7 additions & 6 deletions cerise_manager/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import docker
from cerise_client import Service

from cerise_manager import errors
from cerise_manager import (
ServiceAlreadyExists, PortNotAvailable, ServiceNotFound)


# Creating and destroying services
Expand Down Expand Up @@ -44,7 +45,7 @@ def create_service(srv_name, srv_type, port=None, user_name=None, password=None)
dc = docker.from_env()

if service_exists(srv_name):
raise errors.ServiceAlreadyExists()
raise ServiceAlreadyExists()

auto_port = port is None
if auto_port:
Expand Down Expand Up @@ -91,7 +92,7 @@ def create_service(srv_name, srv_type, port=None, user_name=None, password=None)
if auto_port:
port += 1
else:
raise errors.PortNotAvailable(e)
raise PortNotAvailable(e)
else:
raise

Expand All @@ -118,7 +119,7 @@ def destroy_service(srv):
container.stop()
container.remove()
except docker.errors.NotFound:
raise errors.ServiceNotFound()
raise ServiceNotFound()

def service_exists(srv_name):
"""
Expand Down Expand Up @@ -153,7 +154,7 @@ def get_service(srv_name):
ServiceNotFound: The requested service does not exist.
"""
if not service_exists(srv_name):
raise errors.ServiceNotFound()
raise ServiceNotFound()

dc = docker.from_env()
service = dc.containers.get(srv_name)
Expand Down Expand Up @@ -191,7 +192,7 @@ def require_service(srv_name, srv_type, port=None, user_name=None, password=None
"""
try:
return create_service(srv_name, srv_type, port, user_name, password)
except errors.ServiceAlreadyExists:
except ServiceAlreadyExists:
srv = get_service(srv_name)
if not srv.is_running():
srv.start()
Expand Down

0 comments on commit 0b47b33

Please sign in to comment.