From 31276a49b3046c8d696b9ced0f5c1675a8e55e73 Mon Sep 17 00:00:00 2001
From: Sujitha <sujitha.neti@intel.com>
Date: Thu, 7 Apr 2016 20:22:26 +0000
Subject: [PATCH] Config options: Centralize servicegroup options

This change moves the config options in servicegroup/api.py
to a central location "nova/conf/servicegroup.py".

Change-Id: I894adfe97fbce41435b510caa8b8514cd2fa8166
Implements: blueprint centralize-config-options-newton
---
 nova/conf/__init__.py     |  2 ++
 nova/conf/servicegroup.py | 32 ++++++++++++++++++++++++++++++++
 nova/opts.py              |  2 --
 nova/servicegroup/api.py  | 12 ++----------
 4 files changed, 36 insertions(+), 12 deletions(-)
 create mode 100644 nova/conf/servicegroup.py

diff --git a/nova/conf/__init__.py b/nova/conf/__init__.py
index bcd261a7dbce..aa5f65386435 100644
--- a/nova/conf/__init__.py
+++ b/nova/conf/__init__.py
@@ -73,6 +73,7 @@ from nova.conf import scheduler
 # from nova.conf import security
 from nova.conf import serial_console
 from nova.conf import service
+from nova.conf import servicegroup
 from nova.conf import spice
 from nova.conf import ssl
 # from nova.conf import trusted_computing
@@ -142,6 +143,7 @@ scheduler.register_opts(CONF)
 # security.register_opts(CONF)
 serial_console.register_opts(CONF)
 service.register_opts(CONF)
+servicegroup.register_opts(CONF)
 spice.register_opts(CONF)
 ssl.register_opts(CONF)
 # trusted_computing.register_opts(CONF)
diff --git a/nova/conf/servicegroup.py b/nova/conf/servicegroup.py
new file mode 100644
index 000000000000..5ccab2795f48
--- /dev/null
+++ b/nova/conf/servicegroup.py
@@ -0,0 +1,32 @@
+# Copyright (c) 2016 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
+
+servicegroup_driver = cfg.StrOpt('servicegroup_driver',
+                                  default='db',
+                                  help='The driver for servicegroup '
+                                       'service.',
+                                  choices=['db', 'mc'])
+
+SERVICEGROUP_OPTS = [servicegroup_driver]
+
+
+def register_opts(conf):
+    conf.register_opts(SERVICEGROUP_OPTS)
+
+
+def list_opts():
+    return {'DEFAULT': SERVICEGROUP_OPTS}
diff --git a/nova/opts.py b/nova/opts.py
index f0cd4faf9825..f50677bf1c97 100644
--- a/nova/opts.py
+++ b/nova/opts.py
@@ -26,7 +26,6 @@ import nova.db.base
 import nova.db.sqlalchemy.api
 import nova.exception
 import nova.image.download.file
-import nova.servicegroup.api
 import nova.volume
 
 
@@ -35,7 +34,6 @@ def list_opts():
         ('DEFAULT',
          itertools.chain(
              [nova.db.base.db_driver_opt],
-             [nova.servicegroup.api.servicegroup_driver_opt],
              nova.db.api.db_opts,
              nova.db.sqlalchemy.api.db_opts,
              nova.exception.exc_log_opts,
diff --git a/nova/servicegroup/api.py b/nova/servicegroup/api.py
index 2a09baa42f6f..a7f51ad7149b 100644
--- a/nova/servicegroup/api.py
+++ b/nova/servicegroup/api.py
@@ -16,10 +16,10 @@
 
 """Define APIs for the servicegroup access."""
 
-from oslo_config import cfg
 from oslo_log import log as logging
 from oslo_utils import importutils
 
+import nova.conf
 from nova.i18n import _LW
 
 LOG = logging.getLogger(__name__)
@@ -28,16 +28,8 @@ _driver_name_class_mapping = {
     'db': 'nova.servicegroup.drivers.db.DbDriver',
     'mc': 'nova.servicegroup.drivers.mc.MemcachedDriver'
 }
-_default_driver = 'db'
-servicegroup_driver_opt = cfg.StrOpt('servicegroup_driver',
-                                     default=_default_driver,
-                                     help='The driver for servicegroup '
-                                          'service.',
-                                     choices=sorted(
-                                        _driver_name_class_mapping.keys()))
 
-CONF = cfg.CONF
-CONF.register_opt(servicegroup_driver_opt)
+CONF = nova.conf.CONF
 
 # NOTE(geekinutah): By default drivers wait 5 seconds before reporting
 INITIAL_REPORTING_DELAY = 5