Move config options from nova/api directory (1)

This is the first patch moving config options from the nova/api
directory. In this patch, the auth and metadata options are moved. A
subsequent patch will enhance the help text for these options.

Blueprint centralize-config-options-newton

Change-Id: Id2d755ccb589cedd8ac8663f81d3222ae7d47b3a
This commit is contained in:
EdLeafe
2016-04-20 14:25:02 +00:00
parent b4db932936
commit 515eacc693
11 changed files with 90 additions and 82 deletions

View File

@@ -16,7 +16,6 @@ Common Auth Middleware.
"""
from oslo_config import cfg
from oslo_log import log as logging
from oslo_log import versionutils
from oslo_middleware import request_id
@@ -24,35 +23,14 @@ from oslo_serialization import jsonutils
import webob.dec
import webob.exc
import nova.conf
from nova import context
from nova.i18n import _
from nova.i18n import _LW
from nova import wsgi
auth_opts = [
cfg.BoolOpt('api_rate_limit',
default=False,
help='Whether to use per-user rate limiting for the api. '
'This option is only used by v2 api. Rate limiting '
'is removed from v2.1 api.'),
cfg.StrOpt('auth_strategy',
default='keystone',
choices=('keystone', 'noauth2'),
help='''
The strategy to use for auth: keystone or noauth2. noauth2 is designed for
testing only, as it does no actual credential checking. noauth2 provides
administrative credentials only if 'admin' is specified as the username.
'''),
cfg.BoolOpt('use_forwarded_for',
default=False,
help='Treat X-Forwarded-For as the canonical remote address. '
'Only enable this if you have a sanitizing proxy.'),
]
CONF = cfg.CONF
CONF.register_opts(auth_opts)
CONF = nova.conf.CONF
LOG = logging.getLogger(__name__)

View File

@@ -20,7 +20,6 @@ import base64
import os
import posixpath
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from oslo_utils import importutils
@@ -43,20 +42,7 @@ from nova import utils
from nova.virt import netutils
metadata_opts = [
cfg.StrOpt('config_drive_skip_versions',
default=('1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 '
'2007-12-15 2008-02-01 2008-09-01'),
help='List of metadata versions to skip placing into the '
'config drive'),
cfg.StrOpt('vendordata_driver',
default='nova.api.metadata.vendordata_json.JsonFileVendorData',
help='DEPRECATED: Driver to use for vendor data',
deprecated_for_removal=True),
]
CONF = nova.conf.CONF
CONF.register_opts(metadata_opts)
VERSIONS = [
'1.0',

View File

@@ -19,7 +19,6 @@ import hashlib
import hmac
import os
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import secretutils as secutils
import six
@@ -38,21 +37,6 @@ from nova.network.neutronv2 import api as neutronapi
from nova import wsgi
CONF = nova.conf.CONF
CONF.import_opt('use_forwarded_for', 'nova.api.auth')
metadata_opts = [
cfg.IntOpt('metadata_cache_expiration',
default=15,
help='Time in seconds to cache metadata; 0 to disable '
'metadata caching entirely (not recommended). Increasing'
'this should improve response times of the metadata API '
'when under heavy load. Higher values may increase memory'
'usage and result in longer times for host metadata '
'changes to take effect.')
]
CONF.register_opts(metadata_opts)
LOG = logging.getLogger(__name__)

View File

@@ -17,18 +17,14 @@
import errno
from oslo_config import cfg
from oslo_log import log as logging
from oslo_serialization import jsonutils
from nova.api.metadata import base
import nova.conf
from nova.i18n import _LW
file_opt = cfg.StrOpt('vendordata_jsonfile_path',
help='File to load JSON formatted vendor data from')
CONF = cfg.CONF
CONF.register_opt(file_opt)
CONF = nova.conf.CONF
LOG = logging.getLogger(__name__)
@@ -37,7 +33,7 @@ class JsonFileVendorData(base.VendorDataDriver):
super(JsonFileVendorData, self).__init__(*args, **kwargs)
data = {}
fpath = CONF.vendordata_jsonfile_path
logprefix = "%s[%s]:" % (file_opt.name, fpath)
logprefix = "vendordata_jsonfile_path[%s]:" % fpath
if fpath:
try:
with open(fpath, "r") as fp:

View File

@@ -14,16 +14,15 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
import webob.dec
import webob.exc
from nova.api.openstack import wsgi
import nova.conf
from nova import context
from nova import wsgi as base_wsgi
CONF = cfg.CONF
CONF.import_opt('use_forwarded_for', 'nova.api.auth')
CONF = nova.conf.CONF
class NoAuthMiddlewareBase(base_wsgi.Middleware):

View File

@@ -12,10 +12,6 @@
import itertools
import nova.api.auth
import nova.api.metadata.base
import nova.api.metadata.handler
import nova.api.metadata.vendordata_json
import nova.api.openstack
import nova.api.openstack.common
import nova.api.openstack.compute
@@ -31,11 +27,7 @@ def list_opts():
return [
('DEFAULT',
itertools.chain(
[nova.api.metadata.vendordata_json.file_opt],
[nova.api.openstack.compute.allow_instance_snapshots_opt],
nova.api.auth.auth_opts,
nova.api.metadata.base.metadata_opts,
nova.api.metadata.handler.metadata_opts,
nova.api.openstack.common.osapi_opts,
nova.api.openstack.compute.legacy_v2.contrib.ext_opts,
nova.api.openstack.compute.legacy_v2.contrib.fping.fping_opts,

View File

@@ -19,7 +19,7 @@
from oslo_config import cfg
# from nova.conf import api
from nova.conf import api
# from nova.conf import api_database
from nova.conf import availability_zone
# from nova.conf import aws
@@ -89,7 +89,7 @@ from nova.conf import xvp
CONF = cfg.CONF
# api.register_opts(CONF)
api.register_opts(CONF)
# api_database.register_opts(CONF)
availability_zone.register_opts(CONF)
# aws.register_opts(CONF)

78
nova/conf/api.py Normal file
View File

@@ -0,0 +1,78 @@
# Copyright 2015 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
auth_opts = [
cfg.BoolOpt('api_rate_limit',
default=False,
help='Whether to use per-user rate limiting for the api. '
'This option is only used by v2 api. Rate limiting '
'is removed from v2.1 api.'),
cfg.StrOpt('auth_strategy',
default='keystone',
choices=('keystone', 'noauth2'),
help='''
The strategy to use for auth: keystone or noauth2. noauth2 is designed for
testing only, as it does no actual credential checking. noauth2 provides
administrative credentials only if 'admin' is specified as the username.
'''),
cfg.BoolOpt('use_forwarded_for',
default=False,
help='Treat X-Forwarded-For as the canonical remote address. '
'Only enable this if you have a sanitizing proxy.'),
]
metadata_opts = [
cfg.StrOpt('config_drive_skip_versions',
default=('1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 '
'2007-12-15 2008-02-01 2008-09-01'),
help='List of metadata versions to skip placing into the '
'config drive'),
cfg.StrOpt('vendordata_driver',
default='nova.api.metadata.vendordata_json.JsonFileVendorData',
help='DEPRECATED: Driver to use for vendor data',
deprecated_for_removal=True),
cfg.IntOpt('metadata_cache_expiration',
default=15,
help='Time in seconds to cache metadata; 0 to disable '
'metadata caching entirely (not recommended). Increasing'
'this should improve response times of the metadata API '
'when under heavy load. Higher values may increase memory'
'usage and result in longer times for host metadata '
'changes to take effect.'),
]
file_opt = cfg.StrOpt('vendordata_jsonfile_path',
help='File to load JSON formatted vendor data from')
ALL_OPTS = (auth_opts +
metadata_opts +
[file_opt] +
[])
# Please note that final empty list in the line above is just to allow adding
# additional options in later patches without changing the last line. Once they
# are all moved, the empty list will be removed.
def register_opts(conf):
conf.register_opts(auth_opts)
conf.register_opts(metadata_opts)
conf.register_opt(file_opt)
def list_opts():
return {"DEFAULT": ALL_OPTS}

View File

@@ -14,7 +14,6 @@
# under the License.
import copy
import itertools
from keystoneauth1 import loading as ks_loading
from oslo_config import cfg
@@ -52,10 +51,7 @@ metadata_proxy_opts = [
help='Shared secret to validate proxies Neutron metadata requests'),
]
ALL_OPTS = list(itertools.chain(
neutron_opts,
metadata_proxy_opts
))
ALL_OPTS = (neutron_opts + metadata_proxy_opts)
deprecations = {'cafile': [cfg.DeprecatedOpt('ca_certificates_file',
group=NEUTRON_GROUP)],

View File

@@ -46,7 +46,6 @@ from nova import signature_utils
LOG = logging.getLogger(__name__)
CONF = nova.conf.CONF
CONF.import_opt('auth_strategy', 'nova.api.auth')
supported_glance_versions = (1, 2)

View File

@@ -13,16 +13,16 @@
# under the License.
import mock
from oslo_config import cfg
from oslo_middleware import request_id
from oslo_serialization import jsonutils
import webob
import webob.exc
import nova.api.auth
import nova.conf
from nova import test
CONF = cfg.CONF
CONF = nova.conf.CONF
class TestNovaKeystoneContextMiddleware(test.NoDBTestCase):