Commit 5d8d50fd authored by EKbfh's avatar EKbfh 🐼
Browse files

Add deploy command

parent b45d58a7
......@@ -70,6 +70,7 @@ def main():
"tower-dump = tower.cli.backup:dump",
"tower-restore = tower.cli.backup:restore",
"tower-joblog = tower.cli.joblog:main",
"tower-deploy = tower.cli.deploy:main",
]
},
package_data={
......
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------
# Generate pb and deploy
# -----------------------------------------------------------------------
# Copyright (C) 2015-2021 The NOC Project
# See LICENSE for details
# -----------------------------------------------------------------------
# Python modules
import logging
import os
import sys
from argparse import ArgumentParser
# Tower modules
from tower.models.environment import Environment # noqa
os.chdir(os.path.join(os.path.dirname(sys.argv[0]), ".."))
def main():
logging.basicConfig(level=logging.DEBUG)
parser = ArgumentParser()
parser.add_argument(
"--env",
action="store",
dest="env",
help="Use environment [%default]",
default=get_default_env(),
)
parser.add_argument(
"--generate",
action="store_const",
dest="cmd",
const="generate",
help="Generate tower.yml",
)
args = parser.parse_args()
try:
env = Environment.get(Environment.name == args.env)
except Environment.DoesNotExist:
die("Invalid environment: '%s'" % args.env)
if args.cmd == "generate":
write_pb(env)
def get_default_env():
if os.environ.get("NOC_ENV"):
env = os.environ.get("NOC_ENV")
else:
env = Environment.get(is_default=1).name
return env
def write_pb(env):
from tower.models.service import Service
order = Service.get_execution_order(env)
pb_order = []
for service in order:
pb = resolv_pb(env, service)
if not pb:
continue
pb_order.append(pb)
tower_autogen = os.path.abspath(os.path.join(env.playbook_path, "tower.yml"))
with open(tower_autogen, "w") as f:
for line in pb_order:
f.write("- import_playbook: %s\n" % line)
def resolv_pb(env, service):
if os.path.exists(
os.path.join(env.roles_prefix, service, "service.yml")
):
return os.path.join(
env.roles_prefix, service, "service.yml"
)
elif os.path.exists(
os.path.join(env.playbook_path, "system_roles", service, "service.yml")
):
return os.path.join(
env.playbook_path, "system_roles", service, "service.yml"
)
elif os.path.exists(
os.path.join(env.playbook_path, "noc_roles", service, "service.yml")
):
return os.path.join(
env.playbook_path, "noc_roles", service, "service.yml"
)
else:
return None
def die(msg):
print(msg + "\n")
sys.exit(1)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment