From 0bc0fed6ed180af35efe09dc1bf47ab030acdcaa Mon Sep 17 00:00:00 2001
From: Allen Gao <wanlong.gao@easystack.cn>
Date: Sat, 2 Apr 2016 13:35:29 +0800
Subject: [PATCH] config options: centralize baseproxy cli options

The cli options of baseproxy got moved from
"nova/cmd/novnc.py"
to the new central location
"nova/conf/novnc.py".

Change-Id: Ifec51d57865150b0cf8ed79f6f48fcc512c15824
Implements: blueprint centralize-config-options-newton
---
 nova/api/opts.py            |  1 -
 nova/cmd/baseproxy.py       | 13 ++++---------
 nova/conf/__init__.py       |  2 ++
 nova/{cmd => conf}/novnc.py | 16 +++++++++++++---
 nova/opts.py                |  2 --
 5 files changed, 19 insertions(+), 15 deletions(-)
 rename nova/{cmd => conf}/novnc.py (87%)

diff --git a/nova/api/opts.py b/nova/api/opts.py
index af006f4f47fd..3d4cfcf51d18 100644
--- a/nova/api/opts.py
+++ b/nova/api/opts.py
@@ -39,7 +39,6 @@ import nova.cells.weights.ram_by_instance_type
 import nova.cells.weights.weight_offset
 import nova.cert.rpcapi
 import nova.cloudpipe.pipelib
-import nova.cmd.novnc
 import nova.cmd.novncproxy
 import nova.cmd.serialproxy
 import nova.cmd.spicehtml5proxy
diff --git a/nova/cmd/baseproxy.py b/nova/cmd/baseproxy.py
index ef27470faf53..499d8d878707 100644
--- a/nova/cmd/baseproxy.py
+++ b/nova/cmd/baseproxy.py
@@ -20,22 +20,17 @@ for OpenStack Nova."""
 import os
 import sys
 
-from oslo_config import cfg
 from oslo_log import log as logging
 from oslo_reports import guru_meditation_report as gmr
 
+import nova.conf
+from nova.conf import novnc
 from nova.console import websocketproxy
 from nova import version
 
 
-CONF = cfg.CONF
-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')
+CONF = nova.conf.CONF
+novnc.register_cli_opts(CONF)
 
 
 def exit_with_error(msg, errno=-1):
diff --git a/nova/conf/__init__.py b/nova/conf/__init__.py
index 6e4a0ba6a187..30ac545b6917 100644
--- a/nova/conf/__init__.py
+++ b/nova/conf/__init__.py
@@ -59,6 +59,7 @@ from nova.conf import mks
 from nova.conf import network
 # from nova.conf import neutron
 # from nova.conf import notification
+from nova.conf import novnc
 # from nova.conf import osapi_v21
 from nova.conf import pci
 from nova.conf import rdp
@@ -124,6 +125,7 @@ keymgr.register_opts(CONF)
 network.register_opts(CONF)
 # neutron.register_opts(CONF)
 # notification.register_opts(CONF)
+novnc.register_opts(CONF)
 # osapi_v21.register_opts(CONF)
 pci.register_opts(CONF)
 rdp.register_opts(CONF)
diff --git a/nova/cmd/novnc.py b/nova/conf/novnc.py
similarity index 87%
rename from nova/cmd/novnc.py
rename to nova/conf/novnc.py
index 0b69e5f3b676..aba098022814 100644
--- a/nova/cmd/novnc.py
+++ b/nova/conf/novnc.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2012 OpenStack Foundation
+# Copyright (c) 2016 OpenStack Foundation
 # All Rights Reserved.
 #
 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
@@ -15,7 +15,7 @@
 
 from oslo_config import cfg
 
-opts = [
+novnc_opts = [
     cfg.StrOpt('record',
                 help='This is the filename that will be used for storing '
                      'websocket frames received and sent by a proxy service '
@@ -40,4 +40,14 @@ opts = [
                help='Run webserver on same port. Serve files from DIR.'),
     ]
 
-cfg.CONF.register_cli_opts(opts)
+
+def register_opts(conf):
+    conf.register_opts(novnc_opts)
+
+
+def register_cli_opts(conf):
+    conf.register_cli_opts(novnc_opts)
+
+
+def list_opts():
+    return {'DEFAULT': novnc_opts}
diff --git a/nova/opts.py b/nova/opts.py
index 89770bb1dfd8..b6a415e80638 100644
--- a/nova/opts.py
+++ b/nova/opts.py
@@ -14,7 +14,6 @@ import itertools
 
 import nova.baserpc
 import nova.cloudpipe.pipelib
-import nova.cmd.novnc
 import nova.cmd.serialproxy
 import nova.cmd.spicehtml5proxy
 import nova.conductor.rpcapi
@@ -49,7 +48,6 @@ def list_opts():
              [nova.db.base.db_driver_opt],
              [nova.ipv6.api.ipv6_backend_opt],
              [nova.servicegroup.api.servicegroup_driver_opt],
-             nova.cmd.novnc.opts,
              nova.console.manager.console_manager_opts,
              nova.console.rpcapi.rpcapi_opts,
              nova.console.xvp.xvp_opts,