VMware: Support for non-default port

Currently the VMDK driver fails to connect to vCenter server
if vCenter is configured to listen to any port other than the
default port 443. This patch fixes it by adding support for a
new config option 'vmware_host_port' which specifies the port
number to connect to vCenter server.

DocImpact
  Added config option 'vmware_host_port' which specifies the
  port number to connect to vCenter server.

Change-Id: I71846cdc09bc1ff2a7e35d45aa7c639c468f1418
Co-Authored-By: Johnson koil raj <johnson.raj@hp.com>
Closes-Bug: #1387074
This commit is contained in:
Vipin Balachandran 2016-01-14 00:05:28 -08:00
parent 4fcf249df8
commit 55b442ce19
3 changed files with 43 additions and 16 deletions

View File

@ -54,7 +54,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
"""Unit tests for VMwareVcVmdkDriver."""
IP = 'localhost'
PORT = 443
PORT = 2321
USERNAME = 'username'
PASSWORD = 'password'
VOLUME_FOLDER = 'cinder-volumes'
@ -84,6 +84,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
self._config = mock.Mock(spec=configuration.Configuration)
self._config.vmware_host_ip = self.IP
self._config.vmware_host_port = self.PORT
self._config.vmware_host_username = self.USERNAME
self._config.vmware_host_password = self.PASSWORD
self._config.vmware_wsdl_location = None
@ -790,7 +791,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
image_id,
session=session,
host=self._config.vmware_host_ip,
port=443,
port=self._config.vmware_host_port,
resource_pool=rp,
vm_folder=folder,
vm_import_spec=import_spec,
@ -849,7 +850,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
volume['project_id'],
session=session,
host=self._config.vmware_host_ip,
port=443,
port=self._config.vmware_host_port,
vm=backing,
vmdk_file_path=vmdk_file_path,
vmdk_size=volume['size'] * units.Gi,
@ -1362,9 +1363,11 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
extra_config=extra_config)
file_open.assert_called_once_with(tmp_file_path, "rb")
download_data.assert_called_once_with(
context, self.IMG_TX_TIMEOUT, tmp_file, session=session,
host=self.IP, port=self.PORT, resource_pool=rp, vm_folder=folder,
vm_import_spec=import_spec, image_size=file_size_bytes)
context, self._config.vmware_image_transfer_timeout_secs, tmp_file,
session=session, host=self._config.vmware_host_ip,
port=self._config.vmware_host_port, resource_pool=rp,
vm_folder=folder, vm_import_spec=import_spec,
image_size=file_size_bytes)
download_data.side_effect = exceptions.VimException("error")
backing = mock.sentinel.backing
@ -2028,10 +2031,18 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
vops.get_entity_name.assert_called_once_with(dc_ref)
cookies = session.vim.client.options.transport.cookiejar
download_flat_image.assert_called_once_with(
context, self.IMG_TX_TIMEOUT, image_service, image_id,
image_size=image_size_in_bytes, host=self.IP, port=self.PORT,
data_center_name=dc_name, datastore_name=ds_name, cookies=cookies,
file_path=upload_file_path, cacerts=expected_cacerts)
context,
self._config.vmware_image_transfer_timeout_secs,
image_service,
image_id,
image_size=image_size_in_bytes,
host=self._config.vmware_host_ip,
port=self._config.vmware_host_port,
data_center_name=dc_name,
datastore_name=ds_name,
cookies=cookies,
file_path=upload_file_path,
cacerts=expected_cacerts)
@mock.patch.object(VMDK_DRIVER, 'volumeops')
@mock.patch.object(VMDK_DRIVER, 'session')
@ -2481,6 +2492,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
self._config.vmware_task_poll_interval,
wsdl_loc=self._config.safe_get('vmware_wsdl_location'),
pbm_wsdl_loc=None,
port=self._config.vmware_host_port,
cacert=self._config.vmware_ca_file,
insecure=self._config.vmware_insecure)

View File

@ -67,6 +67,9 @@ EXTRA_CONFIG_VOLUME_ID_KEY = "cinder.volume.id"
vmdk_opts = [
cfg.StrOpt('vmware_host_ip',
help='IP address for connecting to VMware vCenter server.'),
cfg.PortOpt('vmware_host_port',
default=443,
help='Port number for connecting to VMware vCenter server.'),
cfg.StrOpt('vmware_host_username',
help='Username for authenticating with VMware vCenter '
'server.'),
@ -255,7 +258,8 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
'vmware_host_password']
for param in required_params:
if not getattr(self.configuration, param, None):
raise exception.InvalidInput(_("%s not set.") % param)
reason = _("%s not set.") % param
raise exception.InvalidInput(reason=reason)
def check_for_setup_error(self):
pass
@ -665,6 +669,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
timeout = self.configuration.vmware_image_transfer_timeout_secs
host_ip = self.configuration.vmware_host_ip
port = self.configuration.vmware_host_port
ca_file = self.configuration.vmware_ca_file
insecure = self.configuration.vmware_insecure
cookies = self.session.vim.client.options.transport.cookiejar
@ -687,7 +692,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
image_id,
image_size=image_size_in_bytes,
host=host_ip,
port=443,
port=port,
data_center_name=dc_name,
datastore_name=ds_name,
cookies=cookies,
@ -1016,6 +1021,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
# fetching image from glance will also create the backing
timeout = self.configuration.vmware_image_transfer_timeout_secs
host_ip = self.configuration.vmware_host_ip
port = self.configuration.vmware_host_port
LOG.debug("Fetching glance image: %(id)s to server: %(host)s.",
{'id': image_id, 'host': host_ip})
backing = image_transfer.download_stream_optimized_image(
@ -1025,7 +1031,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
image_id,
session=self.session,
host=host_ip,
port=443,
port=port,
resource_pool=rp,
vm_folder=folder,
vm_import_spec=vm_import_spec,
@ -1169,6 +1175,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
# Upload image from vmdk
timeout = self.configuration.vmware_image_transfer_timeout_secs
host_ip = self.configuration.vmware_host_ip
port = self.configuration.vmware_host_port
image_transfer.upload_image(context,
timeout,
@ -1177,7 +1184,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
volume['project_id'],
session=self.session,
host=host_ip,
port=443,
port=port,
vm=backing,
vmdk_file_path=vmdk_file_path,
vmdk_size=volume['size'] * units.Gi,
@ -1432,6 +1439,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
"""Download virtual disk in streamOptimized format."""
timeout = self.configuration.vmware_image_transfer_timeout_secs
host_ip = self.configuration.vmware_host_ip
port = self.configuration.vmware_host_port
vmdk_ds_file_path = self.volumeops.get_vmdk_path(backing)
with open(tmp_file_path, "wb") as tmp_file:
@ -1441,7 +1449,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
tmp_file,
session=self.session,
host=host_ip,
port=443,
port=port,
vm=backing,
vmdk_file_path=vmdk_ds_file_path,
vmdk_size=volume['size'] * units.Gi)
@ -1506,6 +1514,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
timeout = self.configuration.vmware_image_transfer_timeout_secs
host_ip = self.configuration.vmware_host_ip
port = self.configuration.vmware_host_port
try:
with open(tmp_file_path, "rb") as tmp_file:
vm_ref = image_transfer.download_stream_optimized_data(
@ -1514,7 +1523,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
tmp_file,
session=self.session,
host=host_ip,
port=443,
port=port,
resource_pool=rp,
vm_folder=folder,
vm_import_spec=vm_import_spec,
@ -1740,6 +1749,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
def session(self):
if not self._session:
ip = self.configuration.vmware_host_ip
port = self.configuration.vmware_host_port
username = self.configuration.vmware_host_username
password = self.configuration.vmware_host_password
api_retry_count = self.configuration.vmware_api_retry_count
@ -1753,6 +1763,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
task_poll_interval,
wsdl_loc=wsdl_loc,
pbm_wsdl_loc=pbm_wsdl,
port=port,
cacert=ca_file,
insecure=insecure)
return self._session

View File

@ -0,0 +1,4 @@
---
upgrade:
- The VMware VMDK driver supports a new config option 'vmware_host_port'
to specify the port number to connect to vCenter server.