forked from ungleich-public/cdist
import logging, begin to put constant stuff in module
Signed-off-by: Nico Schottelius <nico@kr.ethz.ch>
This commit is contained in:
parent
e8360df96b
commit
4c1939829e
1 changed files with 26 additions and 19 deletions
45
bin/cdist
45
bin/cdist
|
@ -19,22 +19,36 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
import sys # argv
|
import sys
|
||||||
import subprocess # execute stuff
|
import subprocess # execute stuff
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import shutil
|
import shutil
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
|
||||||
|
|
||||||
|
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(message)s')
|
||||||
|
|
||||||
class Cdist:
|
class Cdist:
|
||||||
"""Cdist main class to hold arbitrary data"""
|
"""Cdist main class to hold arbitrary data"""
|
||||||
version="2.0.0"
|
version="2.0.0"
|
||||||
|
|
||||||
def __init__(self, hostname):
|
def __init__(self, hostname):
|
||||||
self.tempdir = tempfile.mkdtemp()
|
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
print(self.hostname)
|
|
||||||
print(self.tempdir)
|
# Setup directory paths
|
||||||
|
self.temp_dir = tempfile.mkdtemp()
|
||||||
|
|
||||||
|
self.out_dir = os.path.join(self.temp_dir, "out")
|
||||||
|
os.mkdir(self.out_dir)
|
||||||
|
|
||||||
|
self.global_explorer_out_dir = os.path.join(self.out_dir, "explorer")
|
||||||
|
os.mkdir(self.global_explorer_out_dir)
|
||||||
|
|
||||||
|
# Given paths from installation
|
||||||
|
self.conf_dir = os.path.join(self.base_dir, "conf")
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
# Do not use in __del__:
|
# Do not use in __del__:
|
||||||
|
@ -45,11 +59,6 @@ class Cdist:
|
||||||
print(self.tempdir)
|
print(self.tempdir)
|
||||||
shutil.rmtree(self.tempdir)
|
shutil.rmtree(self.tempdir)
|
||||||
|
|
||||||
def out_dir(self):
|
|
||||||
# FIXME: stopped - probably need static temp know!
|
|
||||||
"""Local directory containing output"""
|
|
||||||
return os.path.join(base_directory(), "conf")
|
|
||||||
|
|
||||||
def logger(self,type, *args):
|
def logger(self,type, *args):
|
||||||
"""Ignore type for now, support later"""
|
"""Ignore type for now, support later"""
|
||||||
print(*args)
|
print(*args)
|
||||||
|
@ -83,18 +92,9 @@ class Cdist:
|
||||||
self.remove_remote_dir(destination)
|
self.remove_remote_dir(destination)
|
||||||
self.run_or_fail(["scp", "-qr", source, "root@" + self.hostname + ":" + destination])
|
self.run_or_fail(["scp", "-qr", source, "root@" + self.hostname + ":" + destination])
|
||||||
|
|
||||||
def base_directory(self):
|
|
||||||
"""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 remote_base_directory(self):
|
def remote_base_directory(self):
|
||||||
return "/var/lib/cdist"
|
return "/var/lib/cdist"
|
||||||
|
|
||||||
def conf_directory(self):
|
|
||||||
"""Returns path to main configuration directory"""
|
|
||||||
return os.path.join(self.base_directory(), "conf")
|
|
||||||
|
|
||||||
def remote_conf_directory(self):
|
def remote_conf_directory(self):
|
||||||
"""Returns path to remote main configuration directory"""
|
"""Returns path to remote main configuration directory"""
|
||||||
|
@ -112,6 +112,10 @@ class Cdist:
|
||||||
"""Returns path to the remote explorer"""
|
"""Returns path to the remote explorer"""
|
||||||
return os.path.join(self.remote_global_explorer_directory(), explorer)
|
return os.path.join(self.remote_global_explorer_directory(), explorer)
|
||||||
|
|
||||||
|
def global_explorer_output_path(self, explorer):
|
||||||
|
"""Returns path of the output for a global explorer"""
|
||||||
|
return os.path.join(self.global_explorer_out_dir, explorer)
|
||||||
|
|
||||||
def list_global_explorers(self):
|
def list_global_explorers(self):
|
||||||
"""Return list of available explorers"""
|
"""Return list of available explorers"""
|
||||||
return os.listdir(self.global_explorer_directory())
|
return os.listdir(self.global_explorer_directory())
|
||||||
|
@ -127,7 +131,10 @@ class Cdist:
|
||||||
|
|
||||||
self.transfer_global_explorers()
|
self.transfer_global_explorers()
|
||||||
for explorer in explorers:
|
for explorer in explorers:
|
||||||
self.remote_run_or_fail([self.remote_global_explorer_path(explorer)])
|
output = self.global_explorer_output_path(explorer)
|
||||||
|
output_fd = open(output, mode='w')
|
||||||
|
self.remote_run_or_fail([self.remote_global_explorer_path(explorer)], stdout=output_fd)
|
||||||
|
output_fd.close()
|
||||||
|
|
||||||
|
|
||||||
def init_deploy(self):
|
def init_deploy(self):
|
||||||
|
|
Loading…
Reference in a new issue