From ed32f9ef600fa4ef6dbae626766ba2e40abb4e43 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 29 Mar 2012 16:35:13 -0700 Subject: [PATCH] Fixed bug in setting sections that aren't there, and added a little upload image tool/util --- devstack/cfg.py | 2 ++ tools/upload-img.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tools/upload-img.py diff --git a/devstack/cfg.py b/devstack/cfg.py index 49d6d8ac..c2719451 100644 --- a/devstack/cfg.py +++ b/devstack/cfg.py @@ -117,6 +117,8 @@ class StackConfigParser(IgnoreMissingConfigParser): key = cfg_helpers.make_id(section, option) LOG.audit("Setting config value '%s' for param %r" % (value, key)) self.configs_fetched[key] = value + if not self.has_section(section): + self.add_section(section) IgnoreMissingConfigParser.set(self, section, option, value) def _resolve_replacements(self, value): diff --git a/tools/upload-img.py b/tools/upload-img.py new file mode 100644 index 00000000..b2c3bd07 --- /dev/null +++ b/tools/upload-img.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +import os +import sys +from optparse import OptionParser + +possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), + os.pardir, + os.pardir)) +if os.path.exists(os.path.join(possible_topdir, + 'devstack', + '__init__.py')): + sys.path.insert(0, possible_topdir) + + +from devstack import log as logging +from devstack import utils +from devstack import cfg +from devstack import passwords +from devstack.image import uploader + + + +if __name__ == "__main__": + parser = OptionParser() + parser.add_option("-u", "--uri", + action="append", + dest="uris", + metavar="URI", + help=("uri to attempt to upload to glance")) + (options, args) = parser.parse_args() + uris = options.uris or list() + uri_sep = ",".join(uris) + utils.configure_logging(3) + config = cfg.StackConfigParser() + config.add_section('img') + config.set('img', 'image_urls', uri_sep) + pw_gen = passwords.PasswordGenerator(config) + uploader = uploader.Service(config, pw_gen) + uploader.install()