From 2642897d6f5b8a211424519d99feddc89c3bf180 Mon Sep 17 00:00:00 2001
From: Gary Kotton <gkotton@vmware.com>
Date: Tue, 16 Jul 2013 20:25:56 -0700
Subject: [PATCH] Create vmware section

Implements blueprint vmware-configuration-section

VMware specific parameters will be moved to a new section. The
change is backward compatible and supports existing
configurations.

DocImpact

Change-Id: Ic9b425a3d9ea2b614643ba8d3db50b065947c806
---
 etc/nova/nova.conf.sample                     | 132 +++++++++---------
 nova/tests/virt/vmwareapi/test_vmwareapi.py   |  30 ++--
 .../virt/vmwareapi/test_vmwareapi_vif.py      |   2 +-
 nova/virt/vmwareapi/driver.py                 |  52 ++++---
 nova/virt/vmwareapi/vif.py                    |   8 +-
 nova/virt/vmwareapi/vim.py                    |   8 +-
 nova/virt/vmwareapi/vmops.py                  |   8 +-
 nova/virt/vmwareapi/volumeops.py              |   4 +-
 8 files changed, 133 insertions(+), 111 deletions(-)

diff --git a/etc/nova/nova.conf.sample b/etc/nova/nova.conf.sample
index 9df46d1d55f0..45b439095fdf 100644
--- a/etc/nova/nova.conf.sample
+++ b/etc/nova/nova.conf.sample
@@ -2169,72 +2169,6 @@
 #powervm_img_local_path=/tmp
 
 
-#
-# Options defined in nova.virt.vmwareapi.driver
-#
-
-# URL for connection to VMware ESX/VC host. Required if
-# compute_driver is vmwareapi.VMwareESXDriver or
-# vmwareapi.VMwareVCDriver. (string value)
-#vmwareapi_host_ip=<None>
-
-# Username for connection to VMware ESX/VC host. Used only if
-# compute_driver is vmwareapi.VMwareESXDriver or
-# vmwareapi.VMwareVCDriver. (string value)
-#vmwareapi_host_username=<None>
-
-# Password for connection to VMware ESX/VC host. Used only if
-# compute_driver is vmwareapi.VMwareESXDriver or
-# vmwareapi.VMwareVCDriver. (string value)
-#vmwareapi_host_password=<None>
-
-# Name of a VMware Cluster ComputeResource. Used only if
-# compute_driver is vmwareapi.VMwareVCDriver. (string value)
-#vmwareapi_cluster_name=<None>
-
-# The interval used for polling of remote tasks. Used only if
-# compute_driver is vmwareapi.VMwareESXDriver or
-# vmwareapi.VMwareVCDriver. (floating point value)
-#vmwareapi_task_poll_interval=5.0
-
-# The number of times we retry on failures, e.g., socket
-# error, etc. Used only if compute_driver is
-# vmwareapi.VMwareESXDriver or vmwareapi.VMwareVCDriver.
-# (integer value)
-#vmwareapi_api_retry_count=10
-
-# VNC starting port (integer value)
-#vnc_port=5900
-
-# Total number of VNC ports (integer value)
-#vnc_port_total=10000
-
-# VNC password (string value)
-#vnc_password=<None>
-
-# Whether to use linked clone (boolean value)
-#use_linked_clone=true
-
-
-#
-# Options defined in nova.virt.vmwareapi.vif
-#
-
-# Physical ethernet adapter name for vlan networking (string
-# value)
-#vmwareapi_vlan_interface=vmnic0
-
-
-#
-# Options defined in nova.virt.vmwareapi.vim
-#
-
-# Optional VIM Service WSDL Location e.g
-# http://<server>/vimService.wsdl. Optional over-ride to
-# default location for bug work-arounds (string value)
-#vmwareapi_wsdl_loc=<None>
-
-
 #
 # Options defined in nova.virt.xenapi.agent
 #
@@ -3091,6 +3025,72 @@
 
 [vmware]
 
+#
+# Options defined in nova.virt.vmwareapi.driver
+#
+
+# URL for connection to VMware ESX/VC host. Required if
+# compute_driver is vmwareapi.VMwareESXDriver or
+# vmwareapi.VMwareVCDriver. (string value)
+#host_ip=<None>
+
+# Username for connection to VMware ESX/VC host. Used only if
+# compute_driver is vmwareapi.VMwareESXDriver or
+# vmwareapi.VMwareVCDriver. (string value)
+#host_username=<None>
+
+# Password for connection to VMware ESX/VC host. Used only if
+# compute_driver is vmwareapi.VMwareESXDriver or
+# vmwareapi.VMwareVCDriver. (string value)
+#host_password=<None>
+
+# Name of a VMware Cluster ComputeResource. Used only if
+# compute_driver is vmwareapi.VMwareVCDriver. (string value)
+#cluster_name=<None>
+
+# The interval used for polling of remote tasks. Used only if
+# compute_driver is vmwareapi.VMwareESXDriver or
+# vmwareapi.VMwareVCDriver. (floating point value)
+#task_poll_interval=5.0
+
+# The number of times we retry on failures, e.g., socket
+# error, etc. Used only if compute_driver is
+# vmwareapi.VMwareESXDriver or vmwareapi.VMwareVCDriver.
+# (integer value)
+#api_retry_count=10
+
+# VNC starting port (integer value)
+#vnc_port=5900
+
+# Total number of VNC ports (integer value)
+#vnc_port_total=10000
+
+# VNC password (string value)
+#vnc_password=<None>
+
+# Whether to use linked clone (boolean value)
+#use_linked_clone=true
+
+
+#
+# Options defined in nova.virt.vmwareapi.vif
+#
+
+# Physical ethernet adapter name for vlan networking (string
+# value)
+#vlan_interface=vmnic0
+
+
+#
+# Options defined in nova.virt.vmwareapi.vim
+#
+
+# Optional VIM Service WSDL Location e.g
+# http://<server>/vimService.wsdl. Optional over-ride to
+# default location for bug work-arounds (string value)
+#wsdl_location=<None>
+
+
 #
 # Options defined in nova.virt.vmwareapi.vmops
 #
diff --git a/nova/tests/virt/vmwareapi/test_vmwareapi.py b/nova/tests/virt/vmwareapi/test_vmwareapi.py
index d8bbe5f5fe42..af3f83536f4b 100644
--- a/nova/tests/virt/vmwareapi/test_vmwareapi.py
+++ b/nova/tests/virt/vmwareapi/test_vmwareapi.py
@@ -72,7 +72,7 @@ class VMwareAPIConfTestCase(test.TestCase):
         # Test the default configuration behavior. By default,
         # use the WSDL sitting on the host we are talking to in
         # order to bind the SOAP client.
-        wsdl_loc = cfg.CONF.vmwareapi_wsdl_loc
+        wsdl_loc = cfg.CONF.vmware.wsdl_location
         self.assertIsNone(wsdl_loc)
         wsdl_url = vim.Vim.get_wsdl_url("https", "www.example.com")
         url = vim.Vim.get_soap_url("https", "www.example.com")
@@ -91,8 +91,8 @@ class VMwareAPIConfTestCase(test.TestCase):
         # The wsdl_url should point to a different host than the one we
         # are actually going to send commands to.
         fake_wsdl = "https://www.test.com/sdk/foo.wsdl"
-        self.flags(vmwareapi_wsdl_loc=fake_wsdl)
-        wsdl_loc = cfg.CONF.vmwareapi_wsdl_loc
+        self.flags(wsdl_location=fake_wsdl, group='vmware')
+        wsdl_loc = cfg.CONF.vmware.wsdl_location
         self.assertIsNotNone(wsdl_loc)
         self.assertEqual(fake_wsdl, wsdl_loc)
         wsdl_url = vim.Vim.get_wsdl_url("https", "www.example.com")
@@ -107,11 +107,11 @@ class VMwareAPIVMTestCase(test.TestCase):
     def setUp(self):
         super(VMwareAPIVMTestCase, self).setUp()
         self.context = context.RequestContext('fake', 'fake', is_admin=False)
-        self.flags(vmwareapi_host_ip='test_url',
-                   vmwareapi_host_username='test_username',
-                   vmwareapi_host_password='test_pass',
-                   vnc_enabled=False,
-                   use_linked_clone=False)
+        self.flags(host_ip='test_url',
+                   host_username='test_username',
+                   host_password='test_pass',
+                   use_linked_clone=False, group='vmware')
+        self.flags(vnc_enabled=False)
         self.user_id = 'fake'
         self.project_id = 'fake'
         self.node_name = 'test_url'
@@ -597,9 +597,9 @@ class VMwareAPIHostTestCase(test.TestCase):
 
     def setUp(self):
         super(VMwareAPIHostTestCase, self).setUp()
-        self.flags(vmwareapi_host_ip='test_url',
-                   vmwareapi_host_username='test_username',
-                   vmwareapi_host_password='test_pass')
+        self.flags(host_ip='test_url',
+                   host_username='test_username',
+                   host_password='test_pass', group='vmware')
         vmwareapi_fake.reset()
         stubs.set_stubs(self.stubs)
         self.conn = driver.VMwareESXDriver(False)
@@ -644,11 +644,9 @@ class VMwareAPIVCDriverTestCase(VMwareAPIVMTestCase):
 
     def setUp(self):
         super(VMwareAPIVCDriverTestCase, self).setUp()
-        self.flags(
-                   vmwareapi_cluster_name='test_cluster',
-                   vmwareapi_task_poll_interval=10,
-                   vnc_enabled=False
-                   )
+        self.flags(cluster_name='test_cluster',
+                   task_poll_interval=10, group='vmware')
+        self.flags(vnc_enabled=False)
         self.conn = driver.VMwareVCDriver(None, False)
 
     def tearDown(self):
diff --git a/nova/tests/virt/vmwareapi/test_vmwareapi_vif.py b/nova/tests/virt/vmwareapi/test_vmwareapi_vif.py
index 0438855437b6..b97e1ede6405 100644
--- a/nova/tests/virt/vmwareapi/test_vmwareapi_vif.py
+++ b/nova/tests/virt/vmwareapi/test_vmwareapi_vif.py
@@ -24,7 +24,7 @@ from nova.virt.vmwareapi import vif
 class VMwareVifTestCase(test.TestCase):
     def setUp(self):
         super(VMwareVifTestCase, self).setUp()
-        self.flags(vmwareapi_vlan_interface='vmnet0')
+        self.flags(vlan_interface='vmnet0', group='vmware')
         network = network_model.Network(id=0,
                                         bridge='fa0',
                                         label='fake',
diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py
index 6c8e632a72ae..5a2fece81253 100644
--- a/nova/virt/vmwareapi/driver.py
+++ b/nova/virt/vmwareapi/driver.py
@@ -60,56 +60,76 @@ from nova.virt.vmwareapi import volumeops
 LOG = logging.getLogger(__name__)
 
 vmwareapi_opts = [
-    cfg.StrOpt('vmwareapi_host_ip',
+    cfg.StrOpt('host_ip',
                default=None,
+               deprecated_name='vmwareapi_host_ip',
+               deprecated_group='DEFAULT',
                help='URL for connection to VMware ESX/VC host. Required if '
                     'compute_driver is vmwareapi.VMwareESXDriver or '
                     'vmwareapi.VMwareVCDriver.'),
-    cfg.StrOpt('vmwareapi_host_username',
+    cfg.StrOpt('host_username',
                default=None,
+               deprecated_name='vmwareapi_host_username',
+               deprecated_group='DEFAULT',
                help='Username for connection to VMware ESX/VC host. '
                     'Used only if compute_driver is '
                     'vmwareapi.VMwareESXDriver or vmwareapi.VMwareVCDriver.'),
-    cfg.StrOpt('vmwareapi_host_password',
+    cfg.StrOpt('host_password',
                default=None,
+               deprecated_name='vmwareapi_host_password',
+               deprecated_group='DEFAULT',
                help='Password for connection to VMware ESX/VC host. '
                     'Used only if compute_driver is '
                     'vmwareapi.VMwareESXDriver or vmwareapi.VMwareVCDriver.',
                secret=True),
-    cfg.StrOpt('vmwareapi_cluster_name',
+    cfg.StrOpt('cluster_name',
                default=None,
+               deprecated_name='vmwareapi_cluster_name',
+               deprecated_group='DEFAULT',
                help='Name of a VMware Cluster ComputeResource. '
                     'Used only if compute_driver is '
                     'vmwareapi.VMwareVCDriver.'),
-    cfg.FloatOpt('vmwareapi_task_poll_interval',
+    cfg.FloatOpt('task_poll_interval',
                  default=5.0,
+                 deprecated_name='vmwareapi_task_poll_interval',
+                 deprecated_group='DEFAULT',
                  help='The interval used for polling of remote tasks. '
                        'Used only if compute_driver is '
                        'vmwareapi.VMwareESXDriver or '
                        'vmwareapi.VMwareVCDriver.'),
-    cfg.IntOpt('vmwareapi_api_retry_count',
+    cfg.IntOpt('api_retry_count',
                default=10,
+               deprecated_name='vmwareapi_api_retry_count',
+               deprecated_group='DEFAULT',
                help='The number of times we retry on failures, e.g., '
                     'socket error, etc. '
                     'Used only if compute_driver is '
                     'vmwareapi.VMwareESXDriver or vmwareapi.VMwareVCDriver.'),
     cfg.IntOpt('vnc_port',
                default=5900,
+               deprecated_name='vnc_port',
+               deprecated_group='DEFAULT',
                help='VNC starting port'),
     cfg.IntOpt('vnc_port_total',
                default=10000,
+               deprecated_name='vnc_port_total',
+               deprecated_group='DEFAULT',
                help='Total number of VNC ports'),
     cfg.StrOpt('vnc_password',
                default=None,
+               deprecated_name='vnc_password',
+               deprecated_group='DEFAULT',
                help='VNC password',
                secret=True),
     cfg.BoolOpt('use_linked_clone',
                 default=True,
+                deprecated_name='use_linked_clone',
+                deprecated_group='DEFAULT',
                 help='Whether to use linked clone'),
     ]
 
 CONF = cfg.CONF
-CONF.register_opts(vmwareapi_opts)
+CONF.register_opts(vmwareapi_opts, 'vmware')
 
 TIME_BETWEEN_API_CALL_RETRIES = 2.0
 
@@ -136,10 +156,10 @@ class VMwareESXDriver(driver.ComputeDriver):
     def __init__(self, virtapi, read_only=False, scheme="https"):
         super(VMwareESXDriver, self).__init__(virtapi)
 
-        self._host_ip = CONF.vmwareapi_host_ip
-        host_username = CONF.vmwareapi_host_username
-        host_password = CONF.vmwareapi_host_password
-        api_retry_count = CONF.vmwareapi_api_retry_count
+        self._host_ip = CONF.vmware.host_ip
+        host_username = CONF.vmware.host_username
+        host_password = CONF.vmware.host_password
+        api_retry_count = CONF.vmware.api_retry_count
         if not self._host_ip or host_username is None or host_password is None:
             raise Exception(_("Must specify vmwareapi_host_ip,"
                               "vmwareapi_host_username "
@@ -293,9 +313,9 @@ class VMwareESXDriver(driver.ComputeDriver):
 
     def get_console_pool_info(self, console_type):
         """Get info about the host on which the VM resides."""
-        return {'address': CONF.vmwareapi_host_ip,
-                'username': CONF.vmwareapi_host_username,
-                'password': CONF.vmwareapi_host_password}
+        return {'address': CONF.vmware.host_ip,
+                'username': CONF.vmware.host_username,
+                'password': CONF.vmware.host_password}
 
     def get_available_resource(self, nodename):
         """Retrieve resource info.
@@ -376,7 +396,7 @@ class VMwareVCDriver(VMwareESXDriver):
 
     def __init__(self, virtapi, read_only=False, scheme="https"):
         super(VMwareVCDriver, self).__init__(virtapi)
-        self._cluster_name = CONF.vmwareapi_cluster_name
+        self._cluster_name = CONF.vmware.cluster_name
         if not self._cluster_name:
             self._cluster = None
         else:
@@ -596,7 +616,7 @@ class VMwareAPISession(object):
         loop = loopingcall.FixedIntervalLoopingCall(self._poll_task,
                                                     instance_uuid,
                                                     task_ref, done)
-        loop.start(CONF.vmwareapi_task_poll_interval)
+        loop.start(CONF.vmware.task_poll_interval)
         ret_val = done.wait()
         loop.stop()
         return ret_val
diff --git a/nova/virt/vmwareapi/vif.py b/nova/virt/vmwareapi/vif.py
index c98f619e115d..21120e59f3c3 100644
--- a/nova/virt/vmwareapi/vif.py
+++ b/nova/virt/vmwareapi/vif.py
@@ -26,19 +26,21 @@ from nova.virt.vmwareapi import network_util
 CONF = cfg.CONF
 
 vmwareapi_vif_opts = [
-    cfg.StrOpt('vmwareapi_vlan_interface',
+    cfg.StrOpt('vlan_interface',
                default='vmnic0',
+               deprecated_name='vmwareapi_vlan_interface',
+               deprecated_group='DEFAULT',
                help='Physical ethernet adapter name for vlan networking'),
 ]
 
-CONF.register_opts(vmwareapi_vif_opts)
+CONF.register_opts(vmwareapi_vif_opts, 'vmware')
 
 
 def ensure_vlan_bridge(session, vif, cluster=None, create_vlan=True):
     """Create a vlan and bridge unless they already exist."""
     vlan_num = vif['network'].get_meta('vlan')
     bridge = vif['network']['bridge']
-    vlan_interface = CONF.vmwareapi_vlan_interface
+    vlan_interface = CONF.vmware.vlan_interface
 
     network_ref = network_util.get_network_with_the_name(session, bridge,
                                                          cluster)
diff --git a/nova/virt/vmwareapi/vim.py b/nova/virt/vmwareapi/vim.py
index 77c77d060452..deb4262db5f2 100644
--- a/nova/virt/vmwareapi/vim.py
+++ b/nova/virt/vmwareapi/vim.py
@@ -35,14 +35,16 @@ RESP_NOT_XML_ERROR = 'Response is "text/html", not "text/xml"'
 CONN_ABORT_ERROR = 'Software caused connection abort'
 ADDRESS_IN_USE_ERROR = 'Address already in use'
 
-vmwareapi_wsdl_loc_opt = cfg.StrOpt('vmwareapi_wsdl_loc',
+vmwareapi_wsdl_loc_opt = cfg.StrOpt('wsdl_location',
         default=None,
+        deprecated_name='vmwareapi_wsdl_loc',
+        deprecated_group='DEFAULT',
         help='Optional VIM Service WSDL Location '
              'e.g http://<server>/vimService.wsdl. '
              'Optional over-ride to default location for bug work-arounds')
 
 CONF = cfg.CONF
-CONF.register_opt(vmwareapi_wsdl_loc_opt)
+CONF.register_opt(vmwareapi_wsdl_loc_opt, 'vmware')
 
 
 if suds:
@@ -105,7 +107,7 @@ class Vim:
         :return: string to WSDL location for vSphere WS Management API
         """
         # optional WSDL location over-ride for work-arounds
-        wsdl_url = CONF.vmwareapi_wsdl_loc
+        wsdl_url = CONF.vmware.wsdl_location
         if wsdl_url is None:
             # calculate default WSDL location if no override supplied
             wsdl_url = '%s://%s/sdk/vimService.wsdl' % (protocol, host_name)
diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py
index eb83a836fb7d..d7e37a4fbc68 100644
--- a/nova/virt/vmwareapi/vmops.py
+++ b/nova/virt/vmwareapi/vmops.py
@@ -217,7 +217,7 @@ class VMwareVMOps(object):
         # Set the vnc configuration of the instance, vnc port starts from 5900
         if CONF.vnc_enabled:
             vnc_port = self._get_vnc_port(vm_ref)
-            vnc_pass = CONF.vnc_password or ''
+            vnc_pass = CONF.vmware.vnc_password or ''
             self._set_vnc_config(client_factory, instance, vnc_port, vnc_pass)
 
         def _create_virtual_disk():
@@ -345,7 +345,7 @@ class VMwareVMOps(object):
                 self._default_root_device, block_device_info)
 
         if not ebs_root:
-            linked_clone = CONF.use_linked_clone
+            linked_clone = CONF.vmware.use_linked_clone
             if linked_clone:
                 upload_folder = self._instance_path_base
                 upload_name = instance['image_ref']
@@ -1087,7 +1087,7 @@ class VMwareVMOps(object):
         """Return connection info for a vnc console."""
         vm_ref = vm_util.get_vm_ref(self._session, instance)
 
-        return {'host': CONF.vmwareapi_host_ip,
+        return {'host': CONF.vmware.host_ip,
                 'port': self._get_vnc_port(vm_ref),
                 'internal_access_path': None}
 
@@ -1115,7 +1115,7 @@ class VMwareVMOps(object):
     def _get_vnc_port(vm_ref):
         """Return VNC port for an VM."""
         vm_id = int(vm_ref.value.replace('vm-', ''))
-        port = CONF.vnc_port + vm_id % CONF.vnc_port_total
+        port = CONF.vmware.vnc_port + vm_id % CONF.vmware.vnc_port_total
 
         return port
 
diff --git a/nova/virt/vmwareapi/volumeops.py b/nova/virt/vmwareapi/volumeops.py
index 23b615bc6e47..a5fb0f2027e8 100644
--- a/nova/virt/vmwareapi/volumeops.py
+++ b/nova/virt/vmwareapi/volumeops.py
@@ -123,9 +123,9 @@ class VMwareVolumeOps(object):
         """Return volume connector information."""
         iqn = volume_util.get_host_iqn(self._session, self._cluster)
         return {
-            'ip': CONF.vmwareapi_host_ip,
+            'ip': CONF.vmware.host_ip,
             'initiator': iqn,
-            'host': CONF.vmwareapi_host_ip
+            'host': CONF.vmware.host_ip
         }
 
     def attach_volume(self, connection_info, instance, mountpoint):