From 95213244fe341b7ec2723b92a5b793e89ee8403f Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Sun, 19 Jun 2011 14:41:42 -0400 Subject: Cleaned up nova-api binary and logging a bit. --- nova/utils.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 691134ada..22d0ce940 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -238,6 +238,8 @@ def default_flagfile(filename='nova.conf'): filename = "./nova.conf" if not os.path.exists(filename): filename = '/etc/nova/nova.conf' + if not os.path.exists(filename): + return flagfile = ['--flagfile=%s' % filename] sys.argv = sys.argv[:1] + flagfile + sys.argv[1:] -- cgit From dd870291a32d18d0f62592a73a03b9038ae5c3da Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Mon, 20 Jun 2011 10:12:43 -0400 Subject: Cleanup and addition of tests for WSGI server. --- nova/utils.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 22d0ce940..691134ada 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -238,8 +238,6 @@ def default_flagfile(filename='nova.conf'): filename = "./nova.conf" if not os.path.exists(filename): filename = '/etc/nova/nova.conf' - if not os.path.exists(filename): - return flagfile = ['--flagfile=%s' % filename] sys.argv = sys.argv[:1] + flagfile + sys.argv[1:] -- cgit From 13a51049ce5e76fd679b3dee978edce58db21d09 Mon Sep 17 00:00:00 2001 From: Mark Washenberger Date: Wed, 22 Jun 2011 09:33:46 -0400 Subject: fix some issues with flags and logging --- nova/utils.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index e2ac16f31..a9b0f3128 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -226,8 +226,10 @@ def novadir(): return os.path.abspath(nova.__file__).split('nova/__init__.pyc')[0] -def default_flagfile(filename='nova.conf'): - for arg in sys.argv: +def default_flagfile(filename='nova.conf', args=None): + if args is None: + args = sys.argv + for arg in args: if arg.find('flagfile') != -1: break else: @@ -239,8 +241,8 @@ def default_flagfile(filename='nova.conf'): filename = "./nova.conf" if not os.path.exists(filename): filename = '/etc/nova/nova.conf' - flagfile = ['--flagfile=%s' % filename] - sys.argv = sys.argv[:1] + flagfile + sys.argv[1:] + flagfile = '--flagfile=%s' % filename + args.insert(1, flagfile) def debug(arg): -- cgit From 655a783d5a0ef2ddadcf119793cd34513a45fe27 Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Thu, 23 Jun 2011 21:31:00 -0400 Subject: Created Bootstrapper to handle Nova bootstrapping logic. --- nova/utils.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index a9b0f3128..a6b8d4cbe 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -743,3 +743,40 @@ def is_uuid_like(val): if not isinstance(val, basestring): return False return (len(val) == 36) and (val.count('-') == 4) + + +class Bootstrapper(object): + """Provides environment bootstrapping capabilities for entry points.""" + + @staticmethod + def bootstrap_binary(argv): + """Initialize the Nova environment using command line arguments.""" + Bootstrapper.setup_flags(argv) + Bootstrapper.setup_logging() + Bootstrapper.log_flags() + + @staticmethod + def setup_logging(): + """Initialize logging and log a message indicating the Nova version.""" + logging.setup() + logging.audit(_("Nova Version (%s)") % + version.version_string_with_vcs()) + + @staticmethod + def setup_flags(input_flags): + """Initialize flags, load flag file, and print help if needed.""" + default_flagfile(args=input_flags) + FLAGS(input_flags or []) + flags.DEFINE_flag(flags.HelpFlag()) + flags.DEFINE_flag(flags.HelpshortFlag()) + flags.DEFINE_flag(flags.HelpXMLFlag()) + FLAGS.ParseNewFlags() + + @staticmethod + def log_flags(): + """Log the list of all active flags being used.""" + logging.audit(_("Currently active flags:")) + for key in FLAGS: + value = FLAGS.get(key, None) + logging.audit(_("%(key)s : %(value)s" % locals())) + -- cgit From d4fc1d77a4b7c668453042b83e34da76ee3c3818 Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Fri, 24 Jun 2011 09:54:38 +0400 Subject: Unwind last commit, force anyjson to use our serialization methods. --- nova/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 691134ada..a77cf7993 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -525,6 +525,15 @@ def loads(s): return json.loads(s) +try: + import anyjson +except ImportError: + pass +else: + anyjson._modules.append(("nova.utils", "dumps", TypeError, "loads", ValueError)) + anyjson.force_implementation("nova.utils") + + _semaphores = {} -- cgit From e253cd3cf01d29106daff1592a7c629307b449ff Mon Sep 17 00:00:00 2001 From: Yuriy Taraday Date: Sat, 25 Jun 2011 14:04:40 +0400 Subject: PEP8 fix --- nova/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 8f9ca42c1..6d8324e5b 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -531,7 +531,8 @@ try: except ImportError: pass else: - anyjson._modules.append(("nova.utils", "dumps", TypeError, "loads", ValueError)) + anyjson._modules.append(("nova.utils", "dumps", TypeError, + "loads", ValueError)) anyjson.force_implementation("nova.utils") -- cgit From 9855acc214a02d5181a0d8a735e57a89146127db Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Mon, 27 Jun 2011 15:49:24 -0400 Subject: Added nova.version to utils.py --- nova/utils.py | 1 + 1 file changed, 1 insertion(+) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index a6b8d4cbe..badd67599 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -46,6 +46,7 @@ from eventlet.green import subprocess from nova import exception from nova import flags from nova import log as logging +from nova import version LOG = logging.getLogger("nova.utils") -- cgit From 4ec4ec7e4008adabf051651e3c55137c9954139f Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Tue, 28 Jun 2011 10:43:25 -0400 Subject: pep8 fix --- nova/utils.py | 1 - 1 file changed, 1 deletion(-) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index caa1df22a..918541224 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -790,4 +790,3 @@ class Bootstrapper(object): for key in FLAGS: value = FLAGS.get(key, None) logging.audit(_("%(key)s : %(value)s" % locals())) - -- cgit From 498f2d671573fc19d551516f7ead5da8d052ee18 Mon Sep 17 00:00:00 2001 From: Monsyne Dragon Date: Tue, 28 Jun 2011 20:37:05 +0000 Subject: Refactored usage generation --- nova/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'nova/utils.py') diff --git a/nova/utils.py b/nova/utils.py index 6d8324e5b..aee2715ba 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -279,6 +279,22 @@ EASIER_PASSWORD_SYMBOLS = ('23456789' # Removed: 0, 1 'ABCDEFGHJKLMNPQRSTUVWXYZ') # Removed: I, O +def usage_from_instance(instance_ref, **kw): + usage_info = dict( + tenant_id=instance_ref['project_id'], + user_id=instance_ref['user_id'], + instance_id=instance_ref['id'], + instance_type=instance_ref['instance_type']['name'], + instance_type_id=instance_ref['instance_type_id'], + display_name=instance_ref['display_name'], + created_at=str(instance_ref['created_at']), + launched_at=str(instance_ref['launched_at']) \ + if instance_ref['launched_at'] else '', + image_ref=instance_ref['image_ref']) + usage_info.update(kw) + return usage_info + + def generate_password(length=20, symbols=DEFAULT_PASSWORD_SYMBOLS): """Generate a random password from the supplied symbols. -- cgit