diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-06-10 22:30:11 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-06-10 22:30:11 +0000 |
| commit | 2d017a228812f6cbd1ae9bbbcc5d53f1f573ab94 (patch) | |
| tree | e1d01f66dd99046c17557639591646a71e7b9e93 /nova | |
| parent | bfc1065fc19608a532eaba6e4f54409f9fedf5e7 (diff) | |
| parent | 7bf5c100775b4a859c3ef487cf6dfe1c460ede30 (diff) | |
| download | nova-2d017a228812f6cbd1ae9bbbcc5d53f1f573ab94.tar.gz nova-2d017a228812f6cbd1ae9bbbcc5d53f1f573ab94.tar.xz nova-2d017a228812f6cbd1ae9bbbcc5d53f1f573ab94.zip | |
Merge "Enhance group handling in extract_opts"
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/api/openstack/compute/plugins/v3/servers.py | 9 | ||||
| -rw-r--r-- | nova/cmd/novnc.py | 44 | ||||
| -rw-r--r-- | nova/cmd/novncproxy.py | 30 | ||||
| -rw-r--r-- | nova/cmd/spicehtml5proxy.py | 36 | ||||
| -rw-r--r-- | nova/openstack/common/config/__init__.py | 0 | ||||
| -rwxr-xr-x | nova/openstack/common/config/generator.py | 253 | ||||
| -rw-r--r-- | nova/utils.py | 3 | ||||
| -rwxr-xr-x | nova/virt/baremetal/tilera.py | 13 |
8 files changed, 319 insertions, 69 deletions
diff --git a/nova/api/openstack/compute/plugins/v3/servers.py b/nova/api/openstack/compute/plugins/v3/servers.py index d9b2d4a3b..5ba249c78 100644 --- a/nova/api/openstack/compute/plugins/v3/servers.py +++ b/nova/api/openstack/compute/plugins/v3/servers.py @@ -41,14 +41,9 @@ from nova.openstack.common import uuidutils from nova import utils -server_opts = [ - cfg.BoolOpt('enable_instance_password', - default=True, - help='Allows use of instance password during ' - 'server creation'), -] CONF = cfg.CONF -CONF.register_opts(server_opts) +CONF.import_opt('enable_instance_password', + 'nova.api.openstack.compute.servers') CONF.import_opt('network_api_class', 'nova.network') CONF.import_opt('reclaim_instance_interval', 'nova.compute.manager') diff --git a/nova/cmd/novnc.py b/nova/cmd/novnc.py new file mode 100644 index 000000000..c381984da --- /dev/null +++ b/nova/cmd/novnc.py @@ -0,0 +1,44 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2012 OpenStack Foundation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo.config import cfg + +opts = [ + cfg.BoolOpt('record', + default=False, + help='Record sessions to FILE.[session_number]'), + cfg.BoolOpt('daemon', + default=False, + help='Become a daemon (background process)'), + cfg.BoolOpt('ssl_only', + default=False, + help='Disallow non-encrypted connections'), + cfg.BoolOpt('source_is_ipv6', + default=False, + help='Source is ipv6'), + cfg.StrOpt('cert', + default='self.pem', + help='SSL certificate file'), + cfg.StrOpt('key', + default=None, + help='SSL key file (if separate from cert)'), + cfg.StrOpt('web', + default='/usr/share/spice-html5', + help='Run webserver on same port. Serve files from DIR.'), + ] + +cfg.CONF.register_cli_opts(opts) diff --git a/nova/cmd/novncproxy.py b/nova/cmd/novncproxy.py index 449aea76e..2abba7c90 100644 --- a/nova/cmd/novncproxy.py +++ b/nova/cmd/novncproxy.py @@ -30,27 +30,6 @@ from nova.console import websocketproxy opts = [ - cfg.BoolOpt('record', - default=False, - help='Record sessions to FILE.[session_number]'), - cfg.BoolOpt('daemon', - default=False, - help='Become a daemon (background process)'), - cfg.BoolOpt('ssl_only', - default=False, - help='Disallow non-encrypted connections'), - cfg.BoolOpt('source_is_ipv6', - default=False, - help='Source is ipv6'), - cfg.StrOpt('cert', - default='self.pem', - help='SSL certificate file'), - cfg.StrOpt('key', - default=None, - help='SSL key file (if separate from cert)'), - cfg.StrOpt('web', - default='/usr/share/novnc', - help='Run webserver on same port. Serve files from DIR.'), cfg.StrOpt('novncproxy_host', default='0.0.0.0', help='Host on which to listen for incoming requests'), @@ -61,11 +40,18 @@ opts = [ CONF = cfg.CONF CONF.register_cli_opts(opts) -CONF.import_opt('debug', 'nova.openstack.common.log') +CONF.import_opt('record', 'nova.cmd.novnc') +CONF.import_opt('daemon', 'nova.cmd.novnc') +CONF.import_opt('ssl_only', 'nova.cmd.novnc') +CONF.import_opt('source_is_ipv6', 'nova.cmd.novnc') +CONF.import_opt('cert', 'nova.cmd.novnc') +CONF.import_opt('key', 'nova.cmd.novnc') +CONF.import_opt('web', 'nova.cmd.novnc') def main(): # Setup flags + CONF.set_defaults(CONF, web='/usr/share/novnc') config.parse_args(sys.argv) if CONF.ssl_only and not os.path.exists(CONF.cert): diff --git a/nova/cmd/spicehtml5proxy.py b/nova/cmd/spicehtml5proxy.py index c6f2be53d..561c6e7aa 100644 --- a/nova/cmd/spicehtml5proxy.py +++ b/nova/cmd/spicehtml5proxy.py @@ -28,29 +28,7 @@ from oslo.config import cfg from nova import config from nova.console import websocketproxy - opts = [ - cfg.BoolOpt('record', - default=False, - help='Record sessions to FILE.[session_number]'), - cfg.BoolOpt('daemon', - default=False, - help='Become a daemon (background process)'), - cfg.BoolOpt('ssl_only', - default=False, - help='Disallow non-encrypted connections'), - cfg.BoolOpt('source_is_ipv6', - default=False, - help='Source is ipv6'), - cfg.StrOpt('cert', - default='self.pem', - help='SSL certificate file'), - cfg.StrOpt('key', - default=None, - help='SSL key file (if separate from cert)'), - cfg.StrOpt('web', - default='/usr/share/spice-html5', - help='Run webserver on same port. Serve files from DIR.'), cfg.StrOpt('spicehtml5proxy_host', default='0.0.0.0', help='Host on which to listen for incoming requests'), @@ -59,13 +37,19 @@ opts = [ help='Port on which to listen for incoming requests'), ] +CONF = cfg.CONF +CONF.register_cli_opts(opts) +CONF.import_opt('record', 'nova.cmd.novnc') +CONF.import_opt('daemon', 'nova.cmd.novnc') +CONF.import_opt('ssl_only', 'nova.cmd.novnc') +CONF.import_opt('source_is_ipv6', 'nova.cmd.novnc') +CONF.import_opt('cert', 'nova.cmd.novnc') +CONF.import_opt('key', 'nova.cmd.novnc') +CONF.import_opt('web', 'nova.cmd.novnc') + def main(): # Setup flags - - CONF = cfg.CONF - CONF.register_cli_opts(opts) - CONF.import_opt('debug', 'nova.openstack.common.log') config.parse_args(sys.argv) if CONF.ssl_only and not os.path.exists(CONF.cert): diff --git a/nova/openstack/common/config/__init__.py b/nova/openstack/common/config/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/nova/openstack/common/config/__init__.py diff --git a/nova/openstack/common/config/generator.py b/nova/openstack/common/config/generator.py new file mode 100755 index 000000000..7ab3abc70 --- /dev/null +++ b/nova/openstack/common/config/generator.py @@ -0,0 +1,253 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 SINA Corporation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# @author: Zhongyue Luo, SINA Corporation. +# +"""Extracts OpenStack config option info from module(s).""" + +import imp +import os +import re +import socket +import sys +import textwrap + +from oslo.config import cfg + +from nova.openstack.common import gettextutils +from nova.openstack.common import importutils + +gettextutils.install('nova') + +STROPT = "StrOpt" +BOOLOPT = "BoolOpt" +INTOPT = "IntOpt" +FLOATOPT = "FloatOpt" +LISTOPT = "ListOpt" +MULTISTROPT = "MultiStrOpt" + +OPT_TYPES = { + STROPT: 'string value', + BOOLOPT: 'boolean value', + INTOPT: 'integer value', + FLOATOPT: 'floating point value', + LISTOPT: 'list value', + MULTISTROPT: 'multi valued', +} + +OPTION_COUNT = 0 +OPTION_REGEX = re.compile(r"(%s)" % "|".join([STROPT, BOOLOPT, INTOPT, + FLOATOPT, LISTOPT, + MULTISTROPT])) + +PY_EXT = ".py" +BASEDIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../")) +WORDWRAP_WIDTH = 60 + + +def generate(srcfiles): + mods_by_pkg = dict() + for filepath in srcfiles: + pkg_name = filepath.split(os.sep)[1] + mod_str = '.'.join(['.'.join(filepath.split(os.sep)[:-1]), + os.path.basename(filepath).split('.')[0]]) + mods_by_pkg.setdefault(pkg_name, list()).append(mod_str) + # NOTE(lzyeval): place top level modules before packages + pkg_names = filter(lambda x: x.endswith(PY_EXT), mods_by_pkg.keys()) + pkg_names.sort() + ext_names = filter(lambda x: x not in pkg_names, mods_by_pkg.keys()) + ext_names.sort() + pkg_names.extend(ext_names) + + # opts_by_group is a mapping of group name to an options list + # The options list is a list of (module, options) tuples + opts_by_group = {'DEFAULT': []} + + for pkg_name in pkg_names: + mods = mods_by_pkg.get(pkg_name) + mods.sort() + for mod_str in mods: + if mod_str.endswith('.__init__'): + mod_str = mod_str[:mod_str.rfind(".")] + + mod_obj = _import_module(mod_str) + if not mod_obj: + continue + + for group, opts in _list_opts(mod_obj): + opts_by_group.setdefault(group, []).append((mod_str, opts)) + + print_group_opts('DEFAULT', opts_by_group.pop('DEFAULT', [])) + for group, opts in opts_by_group.items(): + print_group_opts(group, opts) + + print "# Total option count: %d" % OPTION_COUNT + + +def _import_module(mod_str): + try: + if mod_str.startswith('bin.'): + imp.load_source(mod_str[4:], os.path.join('bin', mod_str[4:])) + return sys.modules[mod_str[4:]] + else: + return importutils.import_module(mod_str) + except ImportError as ie: + sys.stderr.write("%s\n" % str(ie)) + return None + except Exception: + return None + + +def _is_in_group(opt, group): + "Check if opt is in group." + for key, value in group._opts.items(): + if value['opt'] == opt: + return True + return False + + +def _guess_groups(opt, mod_obj): + # is it in the DEFAULT group? + if _is_in_group(opt, cfg.CONF): + return 'DEFAULT' + + # what other groups is it in? + for key, value in cfg.CONF.items(): + if isinstance(value, cfg.CONF.GroupAttr): + if _is_in_group(opt, value._group): + return value._group.name + + raise RuntimeError( + "Unable to find group for option %s, " + "maybe it's defined twice in the same group?" + % opt.name + ) + + +def _list_opts(obj): + def is_opt(o): + return (isinstance(o, cfg.Opt) and + not isinstance(o, cfg.SubCommandOpt)) + + opts = list() + for attr_str in dir(obj): + attr_obj = getattr(obj, attr_str) + if is_opt(attr_obj): + opts.append(attr_obj) + elif (isinstance(attr_obj, list) and + all(map(lambda x: is_opt(x), attr_obj))): + opts.extend(attr_obj) + + ret = {} + for opt in opts: + ret.setdefault(_guess_groups(opt, obj), []).append(opt) + return ret.items() + + +def print_group_opts(group, opts_by_module): + print "[%s]" % group + print + global OPTION_COUNT + for mod, opts in opts_by_module: + OPTION_COUNT += len(opts) + print '#' + print '# Options defined in %s' % mod + print '#' + print + for opt in opts: + _print_opt(opt) + print + + +def _get_my_ip(): + try: + csock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + csock.connect(('8.8.8.8', 80)) + (addr, port) = csock.getsockname() + csock.close() + return addr + except socket.error: + return None + + +def _sanitize_default(s): + """Set up a reasonably sensible default for pybasedir, my_ip and host.""" + if s.startswith(BASEDIR): + return s.replace(BASEDIR, '/usr/lib/python/site-packages') + elif BASEDIR in s: + return s.replace(BASEDIR, '') + elif s == _get_my_ip(): + return '10.0.0.1' + elif s == socket.getfqdn(): + return 'nova' + elif s.strip() != s: + return '"%s"' % s + return s + + +def _print_opt(opt): + opt_name, opt_default, opt_help = opt.dest, opt.default, opt.help + if not opt_help: + sys.stderr.write('WARNING: "%s" is missing help string.\n' % opt_name) + opt_type = None + try: + opt_type = OPTION_REGEX.search(str(type(opt))).group(0) + except (ValueError, AttributeError), err: + sys.stderr.write("%s\n" % str(err)) + sys.exit(1) + opt_help += ' (' + OPT_TYPES[opt_type] + ')' + print '#', "\n# ".join(textwrap.wrap(opt_help, WORDWRAP_WIDTH)) + try: + if opt_default is None: + print '#%s=<None>' % opt_name + elif opt_type == STROPT: + assert(isinstance(opt_default, basestring)) + print '#%s=%s' % (opt_name, _sanitize_default(opt_default)) + elif opt_type == BOOLOPT: + assert(isinstance(opt_default, bool)) + print '#%s=%s' % (opt_name, str(opt_default).lower()) + elif opt_type == INTOPT: + assert(isinstance(opt_default, int) and + not isinstance(opt_default, bool)) + print '#%s=%s' % (opt_name, opt_default) + elif opt_type == FLOATOPT: + assert(isinstance(opt_default, float)) + print '#%s=%s' % (opt_name, opt_default) + elif opt_type == LISTOPT: + assert(isinstance(opt_default, list)) + print '#%s=%s' % (opt_name, ','.join(opt_default)) + elif opt_type == MULTISTROPT: + assert(isinstance(opt_default, list)) + if not opt_default: + opt_default = [''] + for default in opt_default: + print '#%s=%s' % (opt_name, default) + print + except Exception: + sys.stderr.write('Error in option "%s"\n' % opt_name) + sys.exit(1) + + +def main(): + if len(sys.argv) < 2: + print "usage: %s [srcfile]...\n" % sys.argv[0] + sys.exit(0) + generate(sys.argv[1:]) + +if __name__ == '__main__': + main() diff --git a/nova/utils.py b/nova/utils.py index 2b488a7e7..9067488d5 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -68,9 +68,6 @@ utils_opts = [ cfg.IntOpt('password_length', default=12, help='Length of generated instance admin passwords'), - cfg.BoolOpt('disable_process_locking', - default=False, - help='Whether to disable inter-process locks'), cfg.StrOpt('instance_usage_audit_period', default='month', help='time period to generate instance usages for. ' diff --git a/nova/virt/baremetal/tilera.py b/nova/virt/baremetal/tilera.py index d9a065bf1..7906fdddd 100755 --- a/nova/virt/baremetal/tilera.py +++ b/nova/virt/baremetal/tilera.py @@ -35,22 +35,13 @@ from nova.virt.baremetal import base from nova.virt.baremetal import db from nova.virt.baremetal import utils as bm_utils -tilera_opts = [ - cfg.StrOpt('net_config_template', - default='$pybasedir/nova/virt/baremetal/' - 'net-dhcp.ubuntu.template', - help='Template file for injected network config'), - ] LOG = logging.getLogger(__name__) -baremetal_group = cfg.OptGroup(name='baremetal', - title='Baremetal Options') - CONF = cfg.CONF -CONF.register_group(baremetal_group) -CONF.register_opts(tilera_opts, baremetal_group) CONF.import_opt('use_ipv6', 'nova.netconf') +CONF.import_opt('net_config_template', 'nova.virt.baremetal.pxe', + group='baremetal') CHEETAH = None |
