Updated more variables and other cleanups.

This commit is contained in:
Joshua Harlow
2012-01-18 22:51:25 -08:00
parent 51c1b4bcc5
commit 1a13f7528e
7 changed files with 59 additions and 57 deletions

View File

@@ -39,12 +39,9 @@ class ComponentBase():
self.packager = kargs.get("pkg")
self.distro = kargs.get("distro")
self.root = kargs.get("root")
self.othercomponents = set(kargs.get("components", []))
pths = Util.component_pths(self.root, component_name)
self.componentroot = pths.get('root_dir')
self.tracedir = pths.get("trace_dir")
self.appdir = pths.get("app_dir")
self.cfgdir = pths.get('config_dir')
self.all_components = set(kargs.get("components", []))
(self.componentroot, self.tracedir,
self.appdir, self.cfgdir) = Util.component_paths(self.root, component_name)
self.component_name = component_name
#
@@ -264,7 +261,6 @@ class PkgUninstallComponent(ComponentBase, UninstallComponent):
for fn in cfgfiles:
if(len(fn)):
Shell.unlink(fn)
LOG.info("Removed %s" % (fn))
def uninstall(self):
self._uninstall_pkgs()
@@ -284,7 +280,6 @@ class PkgUninstallComponent(ComponentBase, UninstallComponent):
for fn in filestouched:
if(len(fn)):
Shell.unlink(fn)
LOG.info("Removed %s" % (fn))
def _uninstall_dirs(self):
dirsmade = self.tracereader.dirs_made()
@@ -292,7 +287,6 @@ class PkgUninstallComponent(ComponentBase, UninstallComponent):
LOG.info("Removing %s created directories" % (len(dirsmade)))
for dirname in dirsmade:
Shell.deldir(dirname)
LOG.info("Removed %s" % (dirname))
class PythonUninstallComponent(PkgUninstallComponent):

View File

@@ -28,21 +28,22 @@ def _str2bool(value_str):
def get_environment():
env_copy = dict(os.environ)
return env_copy
return dict(os.environ)
def get_environment_key(key, default_val=None):
LOG.debug("Looking up environment variable %s" % (key))
val = get_environment().get(key)
if(val == None):
LOG.debug("Could not find anything in environment variable %s (using default value %s)" % (key, default_val))
val = default_val
return val
def get_environment_key(key, default_value=None):
LOG.debug("Looking up environment variable \"%s\"" % (key))
value = get_environment().get(key)
if(value == None):
LOG.debug("Could not find anything in environment variable \"%s\"" % (key))
value = default_value
else:
LOG.debug("Found \"%s\" in environment variable \"%s\"" % (value, key))
return value
def get_environment_bool(key, default_val=False):
val = get_environment_key(key, None)
if(val == None):
return default_val
return _str2bool(val)
def get_environment_bool(key, default_value=False):
value = get_environment_key(key, None)
if(value == None):
return default_value
return _str2bool(value)

View File

@@ -38,6 +38,10 @@ class StartException(Exception):
pass
class NoIpException(Exception):
pass
class StopException(Exception):
pass

View File

@@ -86,7 +86,7 @@ class KeystoneInstaller(PythonInstallComponent):
def _setup_data(self):
params = self._get_param_map()
cmds = _keystone_setup_cmds(self.othercomponents)
cmds = _keystone_setup_cmds(self.all_components)
execute_template(*cmds, params=params, ignore_missing=True)
def _config_adjust(self, contents, name):

View File

@@ -30,7 +30,7 @@ from Environment import (get_environment_bool, get_environment)
ROOT_HELPER = ["sudo"]
MKPW_CMD = ["openssl", 'rand', '-hex']
PASS_ASK_ENV = 'PASS_ASK'
LOG = Logger.getLogger("install.shell")
@@ -107,7 +107,7 @@ def execute(*cmd, **kwargs):
obj.stdin.close()
_returncode = obj.returncode
LOG.debug('Cmd result had return code: %s' % _returncode)
LOG.debug('Cmd result had exit code: %s' % _returncode)
if((not ignore_exit_code) and (_returncode not in check_exit_code)):
(stdout, stderr) = result
@@ -145,14 +145,18 @@ def _gen_password(pw_len):
return stdout.strip()
def _prompt_password(prompt=None):
if(prompt):
return getpass.getpass(prompt)
else:
return getpass.getpass()
def password(prompt=None, pw_len=8):
rd = ""
pass_ask = get_environment_bool("PASS_ASK", True)
if(pass_ask):
if(prompt):
rd = getpass.getpass(prompt)
else:
rd = getpass.getpass()
ask_for_pw = get_environment_bool(PASS_ASK_ENV, True)
if(ask_for_pw):
rd = _prompt_password(prompt)
if(len(rd) == 0):
return _gen_password(pw_len)
else:
@@ -160,7 +164,7 @@ def password(prompt=None, pw_len=8):
def mkdirslist(path):
LOG.debug("Determining potential paths to create for target path %s" % (path))
LOG.debug("Determining potential paths to create for target path \"%s\"" % (path))
dirs_possible = set()
dirs_possible.add(path)
#TODO maybe just use string split with os.sep?
@@ -174,7 +178,6 @@ def mkdirslist(path):
dirs_made = list()
for check_path in sorted(dirs_possible):
if(not isdir(check_path)):
LOG.debug("Creating directory %s" % (check_path))
mkdir(check_path, False)
dirs_made.append(check_path)
return dirs_made
@@ -214,17 +217,17 @@ def load_file(fn):
def mkdir(path, recurse=True):
if(not isdir(path)):
if(recurse):
LOG.debug("Recursively creating directory \"%s\"" % (path))
os.makedirs(path)
else:
LOG.debug("Creating directory \"%s\"" % (path))
os.mkdir(path)
def deldir(path, force=True):
def deldir(path):
if(isdir(path)):
if(force):
shutil.rmtree(path)
else:
os.removedirs(path)
LOG.debug("Recursively deleting directory tree starting at \"%s\"" % (path))
shutil.rmtree(path)
def prompt(prompt):
@@ -233,6 +236,7 @@ def prompt(prompt):
def unlink(path, ignore_errors=True):
try:
LOG.debug("Unlinking (removing) %s" % (path))
os.unlink(path)
except OSError, e:
if(not ignore_errors):

View File

@@ -33,14 +33,13 @@ VERSION_STR = "%0.2f" % (VERSION)
DEVSTACK = 'DEVSTACK'
#these also have meaning outside python
#ie in the pkg listings so update there also!
#ie in the pkg/pip listings so update there also!
UBUNTU11 = "ubuntu-oneiric"
RHEL6 = "rhel-6"
#GIT master
MASTER_BRANCH = "master"
#other constants
PRE_INSTALL = 'pre-install'
POST_INSTALL = 'post-install'
@@ -48,7 +47,9 @@ IPV4 = 'IPv4'
IPV6 = 'IPv6'
DEFAULT_NET_INTERFACE = 'eth0'
DEFAULT_NET_INTERFACE_IP_VERSION = IPV4
PARAM_SUB_REGEX = re.compile("%([\\w\\d]+?)%")
#this regex is used for parameter substitution
PARAM_SUB_REGEX = re.compile(r"%([\w\d]+?)%")
#component name mappings
NOVA = "nova"
@@ -117,6 +118,11 @@ WELCOME_MAP = {
STACK_CONFIG_DIR = "conf"
STACK_CFG_LOC = Shell.joinpths(STACK_CONFIG_DIR, "stack.ini")
#default subdirs of a components dir (valid unless overriden)
TRACE_DIR = "traces"
APP_DIR = "app"
CONFIG_DIR = "config"
#this regex is how we match python platform output to
#a known constant
KNOWN_OS = {
@@ -191,11 +197,6 @@ PKG_MAP = {
],
}
#subdirs of a components dir
TRACE_DIR = "traces"
APP_DIR = "app"
CONFIG_DIR = "config"
LOG = Logger.getLogger("install.util")
@@ -268,17 +269,12 @@ def prioritize_components(components):
return component_order
def component_pths(root, compnent_type):
component_root = Shell.joinpths(root, compnent_type)
def component_paths(root, component_name):
component_root = Shell.joinpths(root, component_name)
tracedir = Shell.joinpths(component_root, TRACE_DIR)
appdir = Shell.joinpths(component_root, APP_DIR)
cfgdir = Shell.joinpths(component_root, CONFIG_DIR)
out = dict()
out['root_dir'] = component_root
out['trace_dir'] = tracedir
out['app_dir'] = appdir
out['config_dir'] = cfgdir
return out
return (component_root, tracedir, appdir, cfgdir)
def load_json(fn):
@@ -306,7 +302,10 @@ def get_host_ip(cfg=None):
ipinfo = def_info.get(DEFAULT_NET_INTERFACE_IP_VERSION)
if(ipinfo):
ip = ipinfo.get('addr')
LOG.debug("Got host ip %s" % (ip))
if(ip == None):
msg = "Your host does not have an ip address!"
raise Exceptions.NoIpException(msg)
LOG.debug("Determined host ip to be: \"%s\"" % (ip))
return ip

2
stack
View File

@@ -163,7 +163,7 @@ def runner(action_name, component_set, distro, root_dir, program_args):
pkg_manager_cls = get_package_manager_class(distro)
pkg_manager = pkg_manager_cls(distro)
config = get_config(action_name)
LOG.info("Will %s [%s] using root directory %s" % (action_name, ", ".join(component_set), root_dir))
LOG.info("Will %s [%s] using root directory \"%s\"" % (action_name, ", ".join(component_set), root_dir))
results = list()
class_lookup = ACTION_CLASSES.get(action_name)
force = program_args.get('force', False)