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:
parent
4fcf249df8
commit
55b442ce19
@ -54,7 +54,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
|||||||
"""Unit tests for VMwareVcVmdkDriver."""
|
"""Unit tests for VMwareVcVmdkDriver."""
|
||||||
|
|
||||||
IP = 'localhost'
|
IP = 'localhost'
|
||||||
PORT = 443
|
PORT = 2321
|
||||||
USERNAME = 'username'
|
USERNAME = 'username'
|
||||||
PASSWORD = 'password'
|
PASSWORD = 'password'
|
||||||
VOLUME_FOLDER = 'cinder-volumes'
|
VOLUME_FOLDER = 'cinder-volumes'
|
||||||
@ -84,6 +84,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
|||||||
|
|
||||||
self._config = mock.Mock(spec=configuration.Configuration)
|
self._config = mock.Mock(spec=configuration.Configuration)
|
||||||
self._config.vmware_host_ip = self.IP
|
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_username = self.USERNAME
|
||||||
self._config.vmware_host_password = self.PASSWORD
|
self._config.vmware_host_password = self.PASSWORD
|
||||||
self._config.vmware_wsdl_location = None
|
self._config.vmware_wsdl_location = None
|
||||||
@ -790,7 +791,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
|||||||
image_id,
|
image_id,
|
||||||
session=session,
|
session=session,
|
||||||
host=self._config.vmware_host_ip,
|
host=self._config.vmware_host_ip,
|
||||||
port=443,
|
port=self._config.vmware_host_port,
|
||||||
resource_pool=rp,
|
resource_pool=rp,
|
||||||
vm_folder=folder,
|
vm_folder=folder,
|
||||||
vm_import_spec=import_spec,
|
vm_import_spec=import_spec,
|
||||||
@ -849,7 +850,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
|||||||
volume['project_id'],
|
volume['project_id'],
|
||||||
session=session,
|
session=session,
|
||||||
host=self._config.vmware_host_ip,
|
host=self._config.vmware_host_ip,
|
||||||
port=443,
|
port=self._config.vmware_host_port,
|
||||||
vm=backing,
|
vm=backing,
|
||||||
vmdk_file_path=vmdk_file_path,
|
vmdk_file_path=vmdk_file_path,
|
||||||
vmdk_size=volume['size'] * units.Gi,
|
vmdk_size=volume['size'] * units.Gi,
|
||||||
@ -1362,9 +1363,11 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
|||||||
extra_config=extra_config)
|
extra_config=extra_config)
|
||||||
file_open.assert_called_once_with(tmp_file_path, "rb")
|
file_open.assert_called_once_with(tmp_file_path, "rb")
|
||||||
download_data.assert_called_once_with(
|
download_data.assert_called_once_with(
|
||||||
context, self.IMG_TX_TIMEOUT, tmp_file, session=session,
|
context, self._config.vmware_image_transfer_timeout_secs, tmp_file,
|
||||||
host=self.IP, port=self.PORT, resource_pool=rp, vm_folder=folder,
|
session=session, host=self._config.vmware_host_ip,
|
||||||
vm_import_spec=import_spec, image_size=file_size_bytes)
|
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")
|
download_data.side_effect = exceptions.VimException("error")
|
||||||
backing = mock.sentinel.backing
|
backing = mock.sentinel.backing
|
||||||
@ -2028,10 +2031,18 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
|||||||
vops.get_entity_name.assert_called_once_with(dc_ref)
|
vops.get_entity_name.assert_called_once_with(dc_ref)
|
||||||
cookies = session.vim.client.options.transport.cookiejar
|
cookies = session.vim.client.options.transport.cookiejar
|
||||||
download_flat_image.assert_called_once_with(
|
download_flat_image.assert_called_once_with(
|
||||||
context, self.IMG_TX_TIMEOUT, image_service, image_id,
|
context,
|
||||||
image_size=image_size_in_bytes, host=self.IP, port=self.PORT,
|
self._config.vmware_image_transfer_timeout_secs,
|
||||||
data_center_name=dc_name, datastore_name=ds_name, cookies=cookies,
|
image_service,
|
||||||
file_path=upload_file_path, cacerts=expected_cacerts)
|
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, 'volumeops')
|
||||||
@mock.patch.object(VMDK_DRIVER, 'session')
|
@mock.patch.object(VMDK_DRIVER, 'session')
|
||||||
@ -2481,6 +2492,7 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
|||||||
self._config.vmware_task_poll_interval,
|
self._config.vmware_task_poll_interval,
|
||||||
wsdl_loc=self._config.safe_get('vmware_wsdl_location'),
|
wsdl_loc=self._config.safe_get('vmware_wsdl_location'),
|
||||||
pbm_wsdl_loc=None,
|
pbm_wsdl_loc=None,
|
||||||
|
port=self._config.vmware_host_port,
|
||||||
cacert=self._config.vmware_ca_file,
|
cacert=self._config.vmware_ca_file,
|
||||||
insecure=self._config.vmware_insecure)
|
insecure=self._config.vmware_insecure)
|
||||||
|
|
||||||
|
@ -67,6 +67,9 @@ EXTRA_CONFIG_VOLUME_ID_KEY = "cinder.volume.id"
|
|||||||
vmdk_opts = [
|
vmdk_opts = [
|
||||||
cfg.StrOpt('vmware_host_ip',
|
cfg.StrOpt('vmware_host_ip',
|
||||||
help='IP address for connecting to VMware vCenter server.'),
|
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',
|
cfg.StrOpt('vmware_host_username',
|
||||||
help='Username for authenticating with VMware vCenter '
|
help='Username for authenticating with VMware vCenter '
|
||||||
'server.'),
|
'server.'),
|
||||||
@ -255,7 +258,8 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
'vmware_host_password']
|
'vmware_host_password']
|
||||||
for param in required_params:
|
for param in required_params:
|
||||||
if not getattr(self.configuration, param, None):
|
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):
|
def check_for_setup_error(self):
|
||||||
pass
|
pass
|
||||||
@ -665,6 +669,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
|
|
||||||
timeout = self.configuration.vmware_image_transfer_timeout_secs
|
timeout = self.configuration.vmware_image_transfer_timeout_secs
|
||||||
host_ip = self.configuration.vmware_host_ip
|
host_ip = self.configuration.vmware_host_ip
|
||||||
|
port = self.configuration.vmware_host_port
|
||||||
ca_file = self.configuration.vmware_ca_file
|
ca_file = self.configuration.vmware_ca_file
|
||||||
insecure = self.configuration.vmware_insecure
|
insecure = self.configuration.vmware_insecure
|
||||||
cookies = self.session.vim.client.options.transport.cookiejar
|
cookies = self.session.vim.client.options.transport.cookiejar
|
||||||
@ -687,7 +692,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
image_id,
|
image_id,
|
||||||
image_size=image_size_in_bytes,
|
image_size=image_size_in_bytes,
|
||||||
host=host_ip,
|
host=host_ip,
|
||||||
port=443,
|
port=port,
|
||||||
data_center_name=dc_name,
|
data_center_name=dc_name,
|
||||||
datastore_name=ds_name,
|
datastore_name=ds_name,
|
||||||
cookies=cookies,
|
cookies=cookies,
|
||||||
@ -1016,6 +1021,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
# fetching image from glance will also create the backing
|
# fetching image from glance will also create the backing
|
||||||
timeout = self.configuration.vmware_image_transfer_timeout_secs
|
timeout = self.configuration.vmware_image_transfer_timeout_secs
|
||||||
host_ip = self.configuration.vmware_host_ip
|
host_ip = self.configuration.vmware_host_ip
|
||||||
|
port = self.configuration.vmware_host_port
|
||||||
LOG.debug("Fetching glance image: %(id)s to server: %(host)s.",
|
LOG.debug("Fetching glance image: %(id)s to server: %(host)s.",
|
||||||
{'id': image_id, 'host': host_ip})
|
{'id': image_id, 'host': host_ip})
|
||||||
backing = image_transfer.download_stream_optimized_image(
|
backing = image_transfer.download_stream_optimized_image(
|
||||||
@ -1025,7 +1031,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
image_id,
|
image_id,
|
||||||
session=self.session,
|
session=self.session,
|
||||||
host=host_ip,
|
host=host_ip,
|
||||||
port=443,
|
port=port,
|
||||||
resource_pool=rp,
|
resource_pool=rp,
|
||||||
vm_folder=folder,
|
vm_folder=folder,
|
||||||
vm_import_spec=vm_import_spec,
|
vm_import_spec=vm_import_spec,
|
||||||
@ -1169,6 +1175,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
# Upload image from vmdk
|
# Upload image from vmdk
|
||||||
timeout = self.configuration.vmware_image_transfer_timeout_secs
|
timeout = self.configuration.vmware_image_transfer_timeout_secs
|
||||||
host_ip = self.configuration.vmware_host_ip
|
host_ip = self.configuration.vmware_host_ip
|
||||||
|
port = self.configuration.vmware_host_port
|
||||||
|
|
||||||
image_transfer.upload_image(context,
|
image_transfer.upload_image(context,
|
||||||
timeout,
|
timeout,
|
||||||
@ -1177,7 +1184,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
volume['project_id'],
|
volume['project_id'],
|
||||||
session=self.session,
|
session=self.session,
|
||||||
host=host_ip,
|
host=host_ip,
|
||||||
port=443,
|
port=port,
|
||||||
vm=backing,
|
vm=backing,
|
||||||
vmdk_file_path=vmdk_file_path,
|
vmdk_file_path=vmdk_file_path,
|
||||||
vmdk_size=volume['size'] * units.Gi,
|
vmdk_size=volume['size'] * units.Gi,
|
||||||
@ -1432,6 +1439,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
"""Download virtual disk in streamOptimized format."""
|
"""Download virtual disk in streamOptimized format."""
|
||||||
timeout = self.configuration.vmware_image_transfer_timeout_secs
|
timeout = self.configuration.vmware_image_transfer_timeout_secs
|
||||||
host_ip = self.configuration.vmware_host_ip
|
host_ip = self.configuration.vmware_host_ip
|
||||||
|
port = self.configuration.vmware_host_port
|
||||||
vmdk_ds_file_path = self.volumeops.get_vmdk_path(backing)
|
vmdk_ds_file_path = self.volumeops.get_vmdk_path(backing)
|
||||||
|
|
||||||
with open(tmp_file_path, "wb") as tmp_file:
|
with open(tmp_file_path, "wb") as tmp_file:
|
||||||
@ -1441,7 +1449,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
tmp_file,
|
tmp_file,
|
||||||
session=self.session,
|
session=self.session,
|
||||||
host=host_ip,
|
host=host_ip,
|
||||||
port=443,
|
port=port,
|
||||||
vm=backing,
|
vm=backing,
|
||||||
vmdk_file_path=vmdk_ds_file_path,
|
vmdk_file_path=vmdk_ds_file_path,
|
||||||
vmdk_size=volume['size'] * units.Gi)
|
vmdk_size=volume['size'] * units.Gi)
|
||||||
@ -1506,6 +1514,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
|
|
||||||
timeout = self.configuration.vmware_image_transfer_timeout_secs
|
timeout = self.configuration.vmware_image_transfer_timeout_secs
|
||||||
host_ip = self.configuration.vmware_host_ip
|
host_ip = self.configuration.vmware_host_ip
|
||||||
|
port = self.configuration.vmware_host_port
|
||||||
try:
|
try:
|
||||||
with open(tmp_file_path, "rb") as tmp_file:
|
with open(tmp_file_path, "rb") as tmp_file:
|
||||||
vm_ref = image_transfer.download_stream_optimized_data(
|
vm_ref = image_transfer.download_stream_optimized_data(
|
||||||
@ -1514,7 +1523,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
tmp_file,
|
tmp_file,
|
||||||
session=self.session,
|
session=self.session,
|
||||||
host=host_ip,
|
host=host_ip,
|
||||||
port=443,
|
port=port,
|
||||||
resource_pool=rp,
|
resource_pool=rp,
|
||||||
vm_folder=folder,
|
vm_folder=folder,
|
||||||
vm_import_spec=vm_import_spec,
|
vm_import_spec=vm_import_spec,
|
||||||
@ -1740,6 +1749,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
def session(self):
|
def session(self):
|
||||||
if not self._session:
|
if not self._session:
|
||||||
ip = self.configuration.vmware_host_ip
|
ip = self.configuration.vmware_host_ip
|
||||||
|
port = self.configuration.vmware_host_port
|
||||||
username = self.configuration.vmware_host_username
|
username = self.configuration.vmware_host_username
|
||||||
password = self.configuration.vmware_host_password
|
password = self.configuration.vmware_host_password
|
||||||
api_retry_count = self.configuration.vmware_api_retry_count
|
api_retry_count = self.configuration.vmware_api_retry_count
|
||||||
@ -1753,6 +1763,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
|||||||
task_poll_interval,
|
task_poll_interval,
|
||||||
wsdl_loc=wsdl_loc,
|
wsdl_loc=wsdl_loc,
|
||||||
pbm_wsdl_loc=pbm_wsdl,
|
pbm_wsdl_loc=pbm_wsdl,
|
||||||
|
port=port,
|
||||||
cacert=ca_file,
|
cacert=ca_file,
|
||||||
insecure=insecure)
|
insecure=insecure)
|
||||||
return self._session
|
return self._session
|
||||||
|
@ -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.
|
Loading…
Reference in New Issue
Block a user