09c58e2327
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
105 lines
3.1 KiB
Python
Executable file
105 lines
3.1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
#
|
|
# 2010-2011 Nico Schottelius (nico-cdist at schottelius.org)
|
|
#
|
|
# This file is part of cdist.
|
|
#
|
|
# cdist is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# cdist is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
#
|
|
|
|
import sys # argv
|
|
import subprocess # execute stuff
|
|
import os
|
|
|
|
__cdist_version="2.0.0"
|
|
|
|
def logger(type, *args):
|
|
"""Ignore type for now, support later"""
|
|
print(*args)
|
|
|
|
def exit_error(*args):
|
|
logger("error", *args)
|
|
sys.exit(1)
|
|
|
|
|
|
def run_or_fail(*args):
|
|
newargs = ["echo"]
|
|
newargs.extend(*args)
|
|
|
|
try:
|
|
subprocess.check_call(newargs)
|
|
except CalledProcessError:
|
|
exit_error("Command failed:", newargs)
|
|
|
|
def remote_run_or_fail(hostname, *args):
|
|
newargs = ["ssh", hostname]
|
|
newargs.extend(*args)
|
|
|
|
run_or_fail(newargs)
|
|
|
|
|
|
def base_directory():
|
|
"""Returns the directory in which all cdist stuff is based in"""
|
|
print("Going to", __file__, os.path.join(os.path.dirname(__file__), os.pardir))
|
|
os.chdir(os.path.join(os.path.dirname(__file__), os.pardir))
|
|
return os.getcwd()
|
|
|
|
def conf_directory():
|
|
"""Returns path to main configuration directory"""
|
|
return os.path.join(base_directory(), "conf")
|
|
|
|
def global_explorer_directory():
|
|
"""Returns path to directory containing the global explorers"""
|
|
return os.path.join(conf_directory(), "explorer")
|
|
|
|
def list_global_explorers():
|
|
"""Return list of available explorers"""
|
|
return os.listdir(global_explorer_directory())
|
|
|
|
def global_explore(hostname):
|
|
"""Run global explorers"""
|
|
explorer = list_global_explorers()
|
|
if(len(explorer) == 0):
|
|
exit_error("No explorers found in", global_explorer_directory())
|
|
|
|
|
|
def init_deploy(hostname):
|
|
logger("info", "Creating clean directory structure")
|
|
|
|
# Ensure there is no old stuff, neither local nor remote
|
|
run_or_fail(["rm -rf", "$__cdist_local_base_dir"])
|
|
|
|
remote_run_or_fail(hostname, ["rm -rf", "${__cdist_remote_base_dir}"])
|
|
|
|
# Create base directories
|
|
run_or_fail(["mkdir -p", "$__cdist_local_base_dir"])
|
|
remote_run_or_fail(hostname,["mkdir -p", "${__cdist_remote_base_dir}"])
|
|
|
|
# Link configuraion source directory - consistent with remote
|
|
run_or_fail(["ln -sf", "$__cdist_conf_dir", "$__cdist_local_base_dir/$__cdist_name_conf_dir"])
|
|
|
|
def cdist_deploy_to(hostname):
|
|
"""Mimic the old deploy to: Deploy to one host"""
|
|
logger("info", "Deploying to host", hostname)
|
|
init_deploy(hostname)
|
|
global_explore(hostname)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
hostname=sys.argv[1]
|
|
logger("info", "cdist", __cdist_version, ": Configuring host", hostname)
|
|
cdist_deploy_to(hostname)
|
|
print(list_global_explorers())
|
|
|