Fixing up gunthers new adjustments.

This commit is contained in:
Joshua Harlow
2012-02-06 11:20:24 -08:00
parent 0f2b5951fb
commit 872c41482f
5 changed files with 66 additions and 39 deletions

View File

@@ -84,10 +84,11 @@ class HorizonInstaller(comp.PythonInstallComponent):
return places return places
def _get_symlinks(self): def _get_symlinks(self):
return { src = self._get_target_config_name(HORIZON_APACHE_CONF)
comp.PythonInstallComponent._get_target_config_name(self, HORIZON_APACHE_CONF):\ tgt = sh.joinpths(*HORIZON_APACHE_TGT)
sh.joinpths(*HORIZON_APACHE_TGT) links = dict()
} links[src] = tgt
return links
def _check_ug(self): def _check_ug(self):
(user, group) = self._get_apache_user_group() (user, group) = self._get_apache_user_group()

View File

@@ -20,15 +20,29 @@ import re
from devstack import log as logging from devstack import log as logging
from devstack import shell as sh from devstack import shell as sh
from devstack import env
LOG = logging.getLogger("devstack.downloader") LOG = logging.getLogger("devstack.downloader")
EXT_REG = re.compile(r"^(.*?)\.git\s*$", re.IGNORECASE) EXT_REG = re.compile(r"^(.*?)\.git\s*$", re.IGNORECASE)
GIT_MASTER_BRANCH = "master" GIT_MASTER_BRANCH = "master"
GIT_CACHE_DIR_ENV = "GIT_CACHE_DIR"
def _git_cache_download(storewhere, uri, branch=None):
cdir = env.get_key(GIT_CACHE_DIR_ENV)
if cdir and sh.isdir(cdir):
#TODO
pass
return False
def _gitdownload(storewhere, uri, branch=None): def _gitdownload(storewhere, uri, branch=None):
dirsmade = sh.mkdirslist(storewhere) dirsmade = sh.mkdirslist(storewhere)
LOG.info("Downloading from %s to %s" % (uri, storewhere)) LOG.info("Downloading from %s to %s" % (uri, storewhere))
#check if already done
if _git_cache_download(storewhere, uri, branch):
return dirsmade
#have to do it...
cmd = ["git", "clone"] + [uri, storewhere] cmd = ["git", "clone"] + [uri, storewhere]
sh.execute(*cmd) sh.execute(*cmd)
if branch and branch != GIT_MASTER_BRANCH: if branch and branch != GIT_MASTER_BRANCH:

View File

@@ -24,6 +24,7 @@ from devstack import version
HELP_WIDTH = 80 HELP_WIDTH = 80
LOG = logging.getLogger("devstack.opts") LOG = logging.getLogger("devstack.opts")
DEF_DIR_NAME = 'stack'
def _format_list(in_list): def _format_list(in_list):
@@ -31,9 +32,12 @@ def _format_list(in_list):
return "[" + ", ".join(sorted_list) + "]" return "[" + ", ".join(sorted_list) + "]"
def _get_def_dir():
return sh.joinpths(sh.gethomedir(), DEF_DIR_NAME)
def parse(): def parse():
#version
version_str = "%prog v" + version.version_string() version_str = "%prog v" + version.version_string()
help_formatter = IndentedHelpFormatter(width=HELP_WIDTH) help_formatter = IndentedHelpFormatter(width=HELP_WIDTH)
parser = OptionParser(version=version_str, formatter=help_formatter) parser = OptionParser(version=version_str, formatter=help_formatter)
@@ -55,8 +59,8 @@ def parse():
dest="dir", dest="dir",
metavar="DIR", metavar="DIR",
help=("empty root DIR for install or " help=("empty root DIR for install or "
"DIR with existing components for start/stop/uninstall"), "DIR with existing components for start/stop/uninstall (default: %default)"),
default='/opt/stack' if sh.geteuid() == 0 else sh.joinpths(sh.gethomedir(), 'stack')) default=_get_def_dir())
base_group.add_option("-i", "--ignore-deps", base_group.add_option("-i", "--ignore-deps",
action="store_false", action="store_false",
dest="ensure_deps", dest="ensure_deps",
@@ -93,10 +97,7 @@ def parse():
output['ref_components'] = options.r_component output['ref_components'] = options.r_component
output['action'] = options.action output['action'] = options.action
output['force'] = options.force output['force'] = options.force
if options.ensure_deps: output['ignore_deps'] = not options.ensure_deps
output['ignore_deps'] = False
else:
output['ignore_deps'] = True
output['keep_packages'] = options.keep_packages output['keep_packages'] = options.keep_packages
output['extras'] = args output['extras'] = args
return output return output

View File

@@ -95,10 +95,11 @@ def execute(*cmd, **kwargs):
for (k, v) in env_overrides.items(): for (k, v) in env_overrides.items():
process_env[k] = str(v) process_env[k] = str(v)
rc = None
result = None
try: try:
if run_as_root: if run_as_root:
root_mode() root_mode()
obj = subprocess.Popen(execute_cmd, obj = subprocess.Popen(execute_cmd,
stdin=stdin_fh, stdin=stdin_fh,
stdout=stdout_fh, stdout=stdout_fh,
@@ -107,22 +108,19 @@ def execute(*cmd, **kwargs):
cwd=cwd, cwd=cwd,
shell=shell, shell=shell,
env=process_env) env=process_env)
result = None result = None
if process_input is not None: if process_input is not None:
result = obj.communicate(str(process_input)) result = obj.communicate(str(process_input))
else: else:
result = obj.communicate() result = obj.communicate()
if (stdin_fh != subprocess.PIPE if (stdin_fh != subprocess.PIPE
and obj.stdin and close_stdin): and obj.stdin and close_stdin):
obj.stdin.close() obj.stdin.close()
rc = obj.returncode rc = obj.returncode
LOG.debug('Cmd result had exit code: %s' % rc) LOG.debug('Cmd result had exit code: %s' % rc)
finally: finally:
user_mode() if run_as_root:
user_mode()
if (not ignore_exit_code) and (rc not in check_exit_code): if (not ignore_exit_code) and (rc not in check_exit_code):
(stdout, stderr) = result (stdout, stderr) = result
@@ -188,10 +186,10 @@ def prompt_password(pw_prompt=None):
return rc.strip() return rc.strip()
def chown_r(path, uid, gid): def chown_r(path, uid, gid, run_as_root=True):
try: try:
root_mode() if run_as_root:
root_mode()
if(isdir(path)): if(isdir(path)):
LOG.debug("Changing ownership of %s to %s:%s" % (path, uid, gid)) LOG.debug("Changing ownership of %s to %s:%s" % (path, uid, gid))
os.chown(path, uid, gid) os.chown(path, uid, gid)
@@ -205,7 +203,8 @@ def chown_r(path, uid, gid):
os.chown(joinpths(root, f), uid, gid) os.chown(joinpths(root, f), uid, gid)
LOG.debug("Changing ownership of %s to %s:%s" % (joinpths(root, f), uid, gid)) LOG.debug("Changing ownership of %s to %s:%s" % (joinpths(root, f), uid, gid))
finally: finally:
user_mode() if run_as_root:
user_mode()
def password(prompt_=None, pw_len=8): def password(prompt_=None, pw_len=8):
@@ -293,12 +292,12 @@ def deldir(path, run_as_root=False):
try: try:
if run_as_root: if run_as_root:
root_mode() root_mode()
if isdir(path): if isdir(path):
LOG.debug("Recursively deleting directory tree starting at \"%s\"" % (path)) LOG.debug("Recursively deleting directory tree starting at \"%s\"" % (path))
shutil.rmtree(path) shutil.rmtree(path)
finally: finally:
user_mode() if run_as_root:
user_mode()
def rmdir(path, quiet=True, run_as_root=False): def rmdir(path, quiet=True, run_as_root=False):
@@ -307,7 +306,6 @@ def rmdir(path, quiet=True, run_as_root=False):
try: try:
if run_as_root: if run_as_root:
root_mode() root_mode()
LOG.debug("Deleting directory \"%s\" with the cavet that we will fail if it's not empty." % (path)) LOG.debug("Deleting directory \"%s\" with the cavet that we will fail if it's not empty." % (path))
os.rmdir(path) os.rmdir(path)
LOG.debug("Deleted directory \"%s\"" % (path)) LOG.debug("Deleted directory \"%s\"" % (path))
@@ -317,24 +315,23 @@ def rmdir(path, quiet=True, run_as_root=False):
else: else:
pass pass
finally: finally:
user_mode() if run_as_root:
user_mode()
def symlink(source, link, force=True, run_as_root=True): def symlink(source, link, force=True, run_as_root=True):
try: try:
if run_as_root: if run_as_root:
root_mode() root_mode()
path = dirname(link) path = dirname(link)
mkdirslist(path) mkdirslist(path)
LOG.debug("Creating symlink from %s => %s" % (link, source)) LOG.debug("Creating symlink from %s => %s" % (link, source))
if force and exists(link): if force and exists(link):
unlink(link, True) unlink(link, True)
os.symlink(source, link) os.symlink(source, link)
finally: finally:
user_mode() if run_as_root:
user_mode()
def exists(path): def exists(path):
@@ -383,7 +380,8 @@ def getuid(username):
def gethomedir(): def gethomedir():
return pwd.getpwuid(geteuid())[5] #TODO will just using os.path.expanduser("~") work??
return pwd.getpwuid(geteuid()).pw_dir
def getgid(groupname): def getgid(groupname):
@@ -469,7 +467,8 @@ def replace_in_file(fname, search, replace, run_as_root=False):
line = line.replace(search, replace) line = line.replace(search, replace)
print line, print line,
finally: finally:
user_mode() if run_as_root:
user_mode()
def copy_replace_file(fsrc, fdst, map_): def copy_replace_file(fsrc, fdst, map_):

28
stack
View File

@@ -29,30 +29,42 @@ if(log_fn == None):
log_fn = os.path.normpath(os.path.join("conf", 'logging.ini')) log_fn = os.path.normpath(os.path.join("conf", 'logging.ini'))
logging.config.fileConfig(log_fn) logging.config.fileConfig(log_fn)
#this handles our option parsing
from devstack import opts from devstack import opts
from devstack import utils from devstack import settings
from devstack import shell as sh from devstack import shell as sh
from devstack import utils
#these are the program runtimes that actually do the running #these are the program runtimes that actually do the running
from devstack.progs import actions from devstack.progs import actions
#the user who's user id should be 0
ROOT_USER = 'root'
def main(): def main():
# will need root to setup openstack #names!
prog_name = os.path.basename(sys.argv[0])
pretty_name = settings.PROG_NICE_NAME
#do this first so people can see the help message...
args = opts.parse()
#will need root to setup openstack
if not sh.got_root(): if not sh.got_root():
print("%s needs to run as root" % os.path.basename(sys.argv[0])) msg = "%s needs to be ran as %s!" % (pretty_name, ROOT_USER)
print(utils.color_text(msg, 'red', True))
msg = "Perhaps you should try %s" % \
(utils.color_text("sudo %s" % (prog_name), "red", True))
print(msg)
return 1 return 1
# drop to usermode #drop to usermode
sh.user_mode() sh.user_mode()
args = opts.parse()
try: try:
# now let's go # now let's go
started_ok = actions.run(args) started_ok = actions.run(args)
if not started_ok: if not started_ok:
me = utils.color_text((os.path.basename(sys.argv[0])), "red", True) me = utils.color_text(prog_name, "red", True)
me += " " + utils.color_text('--help', 'red') me += " " + utils.color_text('--help', 'red')
print("Perhaps you should try %s" % (me)) print("Perhaps you should try %s" % (me))
return 1 return 1