Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVOPS-419 WIP: Migrate narrative-traefiker to using classes instead of modules for orchestration handlers #105

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@
from datetime import datetime
import json
import hashlib
import manage_docker
import manage_rancher
from rancher1_handler import rancher1_handler
sychan marked this conversation as resolved.
Show resolved Hide resolved
from typing import Dict, List, Optional
import ipaddress
import sqlite3

VERSION = "0.9.11"
VERSION = "0.10.0"

# Setup default configuration values, overriden by values from os.environ later
cfg = {"docker_url": u"unix://var/run/docker.sock", # path to docker socket
Expand Down Expand Up @@ -79,6 +78,9 @@
find_stopped_services = None
stack_suffix = None

# Instance var for the container manager
container_mgr = None


def merge_env_cfg() -> None:
"""
Expand Down Expand Up @@ -200,33 +202,23 @@ def setup_app(app: flask.Flask) -> None:
global naming_regex
global find_stopped_services
global stack_suffix
global container_mgr

try:
if (cfg["rancher_url"] is not None):
cfg['mode'] = "rancher"
manage_rancher.setup(cfg, logger)
manage_rancher.verify_config(cfg)
check_session = manage_rancher.check_session
start = manage_rancher.start
find_image = manage_rancher.find_image
find_service = manage_rancher.find_service
find_narratives = manage_rancher.find_narratives
find_narrative_labels = manage_rancher.find_narrative_labels
reap_narrative = manage_rancher.reap_narrative
container_mgr = rancher1_handler(cfg, logger)
container_mgr.verify_config(cfg)
check_session = container_mgr.check_session
start = container_mgr.start
find_image = container_mgr.find_image
find_service = container_mgr.find_service
find_narratives = container_mgr.find_narratives
find_narrative_labels = container_mgr.find_narrative_labels
reap_narrative = container_mgr.reap_narrative
naming_regex = "^{}_"
find_stopped_services = manage_rancher.find_stopped_services
stack_suffix = manage_rancher.stack_suffix
else:
cfg['mode'] = "docker"
manage_docker.setup(cfg, logger)
manage_docker.verify_config(cfg)
start = manage_docker.start
find_image = manage_docker.find_image
find_service = manage_docker.find_service
find_narratives = manage_docker.find_narratives
find_narrative_labels = manage_docker.find_narrative_labels
reap_narrative = manage_docker.reap_narrative
naming_regex = "^{}$"
find_stopped_services = container_mgr.find_stopped_services
stack_suffix = container_mgr.stack_suffix
except Exception as ex:
logger.critical("Failed validation of docker or rancher configuration")
raise(ex)
Expand Down Expand Up @@ -266,7 +258,7 @@ def get_prespawned() -> List[str]:
"""
if cfg["mode"] != "rancher":
raise(NotImplementedError("prespawning only supports rancher mode, current mode={}".format(cfg['mode'])))
narratives = manage_rancher.find_narratives()
narratives = find_narratives()
idle_narr = [narr for narr in narratives if cfg['container_name_prespawn'].format("") in narr]
return(idle_narr)

Expand All @@ -286,7 +278,7 @@ def prespawn_narrative(num: int) -> None:
session = random.getrandbits(128).to_bytes(16, "big").hex()
narr_id = session[0:6]
try:
manage_rancher.start(session, narr_id, True)
start(session, narr_id, True)
except Exception as err:
logger.critical({"message": "prespawn_narrative_exception", "session": session,
"container": "{} of {}".format(a, num), "exception": repr(err)})
Expand Down
15 changes: 15 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[flake8]
max-line-length = 100
exclude =
lib/biokbase,
submodules,
*/prepare_deploy_cfg.py,
*/NarrativeRunner_server_test.py,
test_scripts
temp_test*
putty-ignore =
*/__init__.py : F401,E126
*Impl.py : E265,E266
*Server.py : E265,E266
*Client.py : E265,E266