VMware Compute Driver Rename

blueprint vmware-compute-driver

Rename VMWare to VMware
Rename network_utils to network_util to conform to the util class naming convention
Remove the infinite loop in vim.__getattr__

Change-Id: I5bdad331a86c7aa4ca36e7a8345b53e455678c0f
This commit is contained in:
Sean Chen 2013-01-10 13:29:20 -08:00
parent cd2008c8f7
commit b2e0598d3f
15 changed files with 113 additions and 116 deletions

View File

@ -495,7 +495,7 @@ class ComputeManager(manager.SchedulerDependentManager):
'resume guests'), instance=instance)
elif drv_state == power_state.RUNNING:
# VMWareAPI drivers will raise an exception
# VMwareAPI drivers will raise an exception
try:
self.driver.ensure_filtering_rules_for_instance(
instance,

View File

@ -49,7 +49,7 @@ class ConsoleVMRCManager(manager.Manager):
"""Get VIM session for the pool specified."""
vim_session = None
if pool['id'] not in self.sessions.keys():
vim_session = vmwareapi_conn.VMWareAPISession(
vim_session = vmwareapi_conn.VMwareAPISession(
pool['address'],
pool['username'],
pool['password'],

View File

@ -7538,7 +7538,7 @@ msgstr ""
#: nova/virt/vmwareapi/driver.py:107
msgid ""
"Must specify vmwareapi_host_ip,vmwareapi_host_username and "
"vmwareapi_host_password to usecompute_driver=vmwareapi.VMWareESXDriver"
"vmwareapi_host_password to usecompute_driver=vmwareapi.VMwareESXDriver"
msgstr ""
#: nova/virt/vmwareapi/driver.py:258
@ -7635,7 +7635,7 @@ msgstr ""
#: nova/virt/vmwareapi/read_write_util.py:142
#, python-format
msgid "Exception during HTTP connection close in VMWareHTTpWrite. Exception is %s"
msgid "Exception during HTTP connection close in VMwareHTTPWrite. Exception is %s"
msgstr ""
#: nova/virt/vmwareapi/vim.py:83

View File

@ -16,7 +16,7 @@
# under the License.
"""
Test suite for VMWareAPI.
Test suite for VMwareAPI.
"""
from nova.compute import power_state
@ -33,11 +33,11 @@ from nova.virt.vmwareapi import driver
from nova.virt.vmwareapi import fake as vmwareapi_fake
class VMWareAPIVMTestCase(test.TestCase):
class VMwareAPIVMTestCase(test.TestCase):
"""Unit tests for Vmware API connection calls."""
def setUp(self):
super(VMWareAPIVMTestCase, self).setUp()
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',
@ -48,7 +48,7 @@ class VMWareAPIVMTestCase(test.TestCase):
vmwareapi_fake.reset()
db_fakes.stub_out_db_instance_api(self.stubs)
stubs.set_stubs(self.stubs)
self.conn = driver.VMWareESXDriver(None, False)
self.conn = driver.VMwareESXDriver(None, False)
# NOTE(vish): none of the network plugging code is actually
# being tested
self.network_info = [({'bridge': 'fa0',
@ -78,7 +78,7 @@ class VMWareAPIVMTestCase(test.TestCase):
nova.tests.image.fake.stub_out_image_service(self.stubs)
def tearDown(self):
super(VMWareAPIVMTestCase, self).tearDown()
super(VMwareAPIVMTestCase, self).tearDown()
vmwareapi_fake.cleanup()
nova.tests.image.fake.FakeImageService_reset()

View File

@ -21,31 +21,31 @@ Stubouts for the test suite
from nova.virt.vmwareapi import driver
from nova.virt.vmwareapi import fake
from nova.virt.vmwareapi import network_utils
from nova.virt.vmwareapi import network_util
from nova.virt.vmwareapi import vmops
from nova.virt.vmwareapi import vmware_images
def fake_get_vim_object(arg):
"""Stubs out the VMWareAPISession's get_vim_object method."""
"""Stubs out the VMwareAPISession's get_vim_object method."""
return fake.FakeVim()
def fake_is_vim_object(arg, module):
"""Stubs out the VMWareAPISession's is_vim_object method."""
"""Stubs out the VMwareAPISession's is_vim_object method."""
return isinstance(module, fake.FakeVim)
def set_stubs(stubs):
"""Set the stubs."""
stubs.Set(vmops.VMWareVMOps, 'plug_vifs', fake.fake_plug_vifs)
stubs.Set(network_utils, 'get_network_with_the_name',
stubs.Set(vmops.VMwareVMOps, 'plug_vifs', fake.fake_plug_vifs)
stubs.Set(network_util, 'get_network_with_the_name',
fake.fake_get_network)
stubs.Set(vmware_images, 'fetch_image', fake.fake_fetch_image)
stubs.Set(vmware_images, 'get_vmdk_size_and_properties',
fake.fake_get_vmdk_size_and_properties)
stubs.Set(vmware_images, 'upload_image', fake.fake_upload_image)
stubs.Set(driver.VMWareAPISession, "_get_vim_object",
stubs.Set(driver.VMwareAPISession, "_get_vim_object",
fake_get_vim_object)
stubs.Set(driver.VMWareAPISession, "_is_vim_object",
stubs.Set(driver.VMwareAPISession, "_is_vim_object",
fake_is_vim_object)

View File

@ -18,4 +18,4 @@
:mod:`vmwareapi` -- Nova support for VMware ESX/ESXi Server through VMware API.
"""
# NOTE(sdague) for nicer compute_driver specification
from nova.virt.vmwareapi.driver import VMWareESXDriver
from nova.virt.vmwareapi.driver import VMwareESXDriver

View File

@ -52,29 +52,29 @@ LOG = logging.getLogger(__name__)
vmwareapi_opts = [
cfg.StrOpt('vmwareapi_host_ip',
default=None,
help='URL for connection to VMWare ESX host.Required if '
'compute_driver is vmwareapi.VMWareESXDriver.'),
help='URL for connection to VMware ESX host.Required if '
'compute_driver is vmwareapi.VMwareESXDriver.'),
cfg.StrOpt('vmwareapi_host_username',
default=None,
help='Username for connection to VMWare ESX host. '
help='Username for connection to VMware ESX host. '
'Used only if compute_driver is '
'vmwareapi.VMWareESXDriver.'),
'vmwareapi.VMwareESXDriver.'),
cfg.StrOpt('vmwareapi_host_password',
default=None,
help='Password for connection to VMWare ESX host. '
help='Password for connection to VMware ESX host. '
'Used only if compute_driver is '
'vmwareapi.VMWareESXDriver.'),
'vmwareapi.VMwareESXDriver.'),
cfg.FloatOpt('vmwareapi_task_poll_interval',
default=5.0,
help='The interval used for polling of remote tasks. '
'Used only if compute_driver is '
'vmwareapi.VMWareESXDriver.'),
'vmwareapi.VMwareESXDriver.'),
cfg.IntOpt('vmwareapi_api_retry_count',
default=10,
help='The number of times we retry on failures, e.g., '
'socket error, etc. '
'Used only if compute_driver is '
'vmwareapi.VMWareESXDriver.'),
'vmwareapi.VMwareESXDriver.'),
]
CONF = cfg.CONF
@ -93,11 +93,11 @@ class Failure(Exception):
return str(self.details)
class VMWareESXDriver(driver.ComputeDriver):
class VMwareESXDriver(driver.ComputeDriver):
"""The ESX host connection object."""
def __init__(self, virtapi, read_only=False, scheme="https"):
super(VMWareESXDriver, self).__init__(virtapi)
super(VMwareESXDriver, self).__init__(virtapi)
host_ip = CONF.vmwareapi_host_ip
host_username = CONF.vmwareapi_host_username
@ -107,11 +107,11 @@ class VMWareESXDriver(driver.ComputeDriver):
raise Exception(_("Must specify vmwareapi_host_ip,"
"vmwareapi_host_username "
"and vmwareapi_host_password to use"
"compute_driver=vmwareapi.VMWareESXDriver"))
"compute_driver=vmwareapi.VMwareESXDriver"))
session = VMWareAPISession(host_ip, host_username, host_password,
session = VMwareAPISession(host_ip, host_username, host_password,
api_retry_count, scheme=scheme)
self._vmops = vmops.VMWareVMOps(session)
self._vmops = vmops.VMwareVMOps(session)
def init_host(self, host):
"""Do the initialization that needs to be done."""
@ -209,7 +209,7 @@ class VMWareESXDriver(driver.ComputeDriver):
self._vmops.unplug_vifs(instance, network_info)
class VMWareAPISession(object):
class VMwareAPISession(object):
"""
Sets up a session with the ESX host and handles all
the calls made to the host.

View File

@ -16,7 +16,7 @@
# under the License.
"""
A fake VMWare VI API implementation.
A fake VMware VI API implementation.
"""
import pprint

View File

@ -108,8 +108,8 @@ class VMwareHTTPFile(object):
raise NotImplementedError
class VMWareHTTPWriteFile(VMwareHTTPFile):
"""VMWare file write handler class."""
class VMwareHTTPWriteFile(VMwareHTTPFile):
"""VMware file write handler class."""
def __init__(self, host, data_center_name, datastore_name, cookies,
file_path, file_size, scheme="https"):
@ -140,12 +140,12 @@ class VMWareHTTPWriteFile(VMwareHTTPFile):
self.conn.getresponse()
except Exception, excep:
LOG.debug(_("Exception during HTTP connection close in "
"VMWareHTTpWrite. Exception is %s") % excep)
super(VMWareHTTPWriteFile, self).close()
"VMwareHTTpWrite. Exception is %s") % excep)
super(VMwareHTTPWriteFile, self).close()
class VmWareHTTPReadFile(VMwareHTTPFile):
"""VMWare file read handler class."""
class VMwareHTTPReadFile(VMwareHTTPFile):
"""VMware file read handler class."""
def __init__(self, host, data_center_name, datastore_name, cookies,
file_path, scheme="https"):

View File

@ -15,12 +15,12 @@
# License for the specific language governing permissions and limitations
# under the License.
"""VIF drivers for VMWare."""
"""VIF drivers for VMware."""
from nova import exception
from nova.openstack.common import cfg
from nova.openstack.common import log as logging
from nova.virt.vmwareapi import network_utils
from nova.virt.vmwareapi import network_util
LOG = logging.getLogger(__name__)
@ -44,28 +44,28 @@ def ensure_vlan_bridge(self, session, network):
# Check if the vlan_interface physical network adapter exists on the
# host.
if not network_utils.check_if_vlan_interface_exists(session,
if not network_util.check_if_vlan_interface_exists(session,
vlan_interface):
raise exception.NetworkAdapterNotFound(adapter=vlan_interface)
# Get the vSwitch associated with the Physical Adapter
vswitch_associated = network_utils.get_vswitch_for_vlan_interface(
vswitch_associated = network_util.get_vswitch_for_vlan_interface(
session, vlan_interface)
if vswitch_associated is None:
raise exception.SwitchNotFoundForNetworkAdapter(
adapter=vlan_interface)
# Check whether bridge already exists and retrieve the the ref of the
# network whose name_label is "bridge"
network_ref = network_utils.get_network_with_the_name(session, bridge)
network_ref = network_util.get_network_with_the_name(session, bridge)
if network_ref is None:
# Create a port group on the vSwitch associated with the
# vlan_interface corresponding physical network adapter on the ESX
# host.
network_utils.create_port_group(session, bridge,
network_util.create_port_group(session, bridge,
vswitch_associated, vlan_num)
else:
# Get the vlan id and vswitch corresponding to the port group
_get_pg_info = network_utils.get_vlanid_and_vswitch_for_portgroup
_get_pg_info = network_util.get_vlanid_and_vswitch_for_portgroup
pg_vlanid, pg_vswitch = _get_pg_info(session, bridge)
# Check if the vswitch associated is proper

View File

@ -1,5 +1,6 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2012 VMware, Inc.
# Copyright (c) 2011 Citrix Systems, Inc.
# Copyright 2011 OpenStack LLC.
#
@ -101,69 +102,65 @@ class Vim:
def __getattr__(self, attr_name):
"""Makes the API calls and gets the result."""
try:
return getattr(self, attr_name)
except AttributeError:
def vim_request_handler(managed_object, **kwargs):
"""
Builds the SOAP message and parses the response for fault
checking and other errors.
def vim_request_handler(managed_object, **kwargs):
"""
Builds the SOAP message and parses the response for fault
checking and other errors.
managed_object : Managed Object Reference or Managed
Object Name
**kwargs : Keyword arguments of the call
"""
# Dynamic handler for VI SDK Calls
try:
request_mo = self._request_managed_object_builder(
managed_object)
request = getattr(self.client.service, attr_name)
response = request(request_mo, **kwargs)
# To check for the faults that are part of the message body
# and not returned as Fault object response from the ESX
# SOAP server
if hasattr(error_util.FaultCheckers,
attr_name.lower() + "_fault_checker"):
fault_checker = getattr(error_util.FaultCheckers,
attr_name.lower() + "_fault_checker")
fault_checker(response)
return response
# Catch the VimFaultException that is raised by the fault
# check of the SOAP response
except error_util.VimFaultException, excep:
raise
except suds.WebFault, excep:
doc = excep.document
detail = doc.childAtPath("/Envelope/Body/Fault/detail")
fault_list = []
for child in detail.getChildren():
fault_list.append(child.get("type"))
raise error_util.VimFaultException(fault_list, excep)
except AttributeError, excep:
raise error_util.VimAttributeError(_("No such SOAP method "
"'%s' provided by VI SDK") % (attr_name), excep)
except (httplib.CannotSendRequest,
httplib.ResponseNotReady,
httplib.CannotSendHeader), excep:
raise error_util.SessionOverLoadException(_("httplib "
"error in %s: ") % (attr_name), excep)
except Exception, excep:
# Socket errors which need special handling for they
# might be caused by ESX API call overload
if (str(excep).find(ADDRESS_IN_USE_ERROR) != -1 or
str(excep).find(CONN_ABORT_ERROR)) != -1:
raise error_util.SessionOverLoadException(_("Socket "
"error in %s: ") % (attr_name), excep)
# Type error that needs special handling for it might be
# caused by ESX host API call overload
elif str(excep).find(RESP_NOT_XML_ERROR) != -1:
raise error_util.SessionOverLoadException(_("Type "
"error in %s: ") % (attr_name), excep)
else:
raise error_util.VimException(
_("Exception in %s ") % (attr_name), excep)
return vim_request_handler
managed_object : Managed Object Reference or Managed
Object Name
**kwargs : Keyword arguments of the call
"""
# Dynamic handler for VI SDK Calls
try:
request_mo = self._request_managed_object_builder(
managed_object)
request = getattr(self.client.service, attr_name)
response = request(request_mo, **kwargs)
# To check for the faults that are part of the message body
# and not returned as Fault object response from the ESX
# SOAP server
if hasattr(error_util.FaultCheckers,
attr_name.lower() + "_fault_checker"):
fault_checker = getattr(error_util.FaultCheckers,
attr_name.lower() + "_fault_checker")
fault_checker(response)
return response
# Catch the VimFaultException that is raised by the fault
# check of the SOAP response
except error_util.VimFaultException, excep:
raise
except suds.WebFault, excep:
doc = excep.document
detail = doc.childAtPath("/Envelope/Body/Fault/detail")
fault_list = []
for child in detail.getChildren():
fault_list.append(child.get("type"))
raise error_util.VimFaultException(fault_list, excep)
except AttributeError, excep:
raise error_util.VimAttributeError(_("No such SOAP method "
"'%s' provided by VI SDK") % (attr_name), excep)
except (httplib.CannotSendRequest,
httplib.ResponseNotReady,
httplib.CannotSendHeader), excep:
raise error_util.SessionOverLoadException(_("httplib "
"error in %s: ") % (attr_name), excep)
except Exception, excep:
# Socket errors which need special handling for they
# might be caused by ESX API call overload
if (str(excep).find(ADDRESS_IN_USE_ERROR) != -1 or
str(excep).find(CONN_ABORT_ERROR)) != -1:
raise error_util.SessionOverLoadException(_("Socket "
"error in %s: ") % (attr_name), excep)
# Type error that needs special handling for it might be
# caused by ESX host API call overload
elif str(excep).find(RESP_NOT_XML_ERROR) != -1:
raise error_util.SessionOverLoadException(_("Type "
"error in %s: ") % (attr_name), excep)
else:
raise error_util.VimException(
_("Exception in %s ") % (attr_name), excep)
return vim_request_handler
def _request_managed_object_builder(self, managed_object):
"""Builds the request managed object."""

View File

@ -26,7 +26,7 @@ def build_datastore_path(datastore_name, path):
def split_datastore_path(datastore_path):
"""
Split the VMWare style datastore path to get the Datastore
Split the VMware style datastore path to get the Datastore
name and the entity path.
"""
spl = datastore_path.split('[', 1)[1].split(']', 1)

View File

@ -32,7 +32,7 @@ from nova import exception
from nova.openstack.common import cfg
from nova.openstack.common import importutils
from nova.openstack.common import log as logging
from nova.virt.vmwareapi import network_utils
from nova.virt.vmwareapi import network_util
from nova.virt.vmwareapi import vif as vmwarevif
from nova.virt.vmwareapi import vim_util
from nova.virt.vmwareapi import vm_util
@ -49,7 +49,7 @@ VMWARE_POWER_STATES = {
'suspended': power_state.PAUSED}
class VMWareVMOps(object):
class VMwareVMOps(object):
"""Management class for VM-related tasks."""
def __init__(self, session):
@ -157,7 +157,7 @@ class VMWareVMOps(object):
vm_folder_mor, res_pool_mor = _get_vmfolder_and_res_pool_mors()
def _check_if_network_bridge_exists(network_name):
network_ref = network_utils.get_network_with_the_name(
network_ref = network_util.get_network_with_the_name(
self._session, network_name)
if network_ref is None:
raise exception.NetworkNotFoundForBridge(bridge=network_name)

View File

@ -50,11 +50,11 @@ def start_transfer(context, read_file_handle, data_size,
# to read.
read_thread = io_util.IOThread(read_file_handle, thread_safe_pipe)
# In case of Glance - VMWare transfer, we just need a handle to the
# HTTP Connection that is to send transfer data to the VMWare datastore.
# In case of Glance - VMware transfer, we just need a handle to the
# HTTP Connection that is to send transfer data to the VMware datastore.
if write_file_handle:
write_thread = io_util.IOThread(thread_safe_pipe, write_file_handle)
# In case of VMWare - Glance transfer, we relinquish VMWare HTTP file read
# In case of VMware - Glance transfer, we relinquish VMware HTTP file read
# handle to Glance Client instance, but to be sure of the transfer we need
# to be sure of the status of the image on glnace changing to active.
# The GlanceWriteThread handles the same for us.
@ -96,7 +96,7 @@ def fetch_image(context, image, instance, **kwargs):
f = StringIO.StringIO()
image_service.download(context, image_id, f)
read_file_handle = read_write_util.GlanceFileRead(f)
write_file_handle = read_write_util.VMWareHTTPWriteFile(
write_file_handle = read_write_util.VMwareHTTPWriteFile(
kwargs.get("host"),
kwargs.get("data_center_name"),
kwargs.get("datastore_name"),
@ -113,7 +113,7 @@ def upload_image(context, image, instance, **kwargs):
"""Upload the snapshotted vm disk file to Glance image server."""
LOG.debug(_("Uploading image %s to the Glance image server") % image,
instance=instance)
read_file_handle = read_write_util.VmWareHTTPReadFile(
read_file_handle = read_write_util.VMwareHTTPReadFile(
kwargs.get("host"),
kwargs.get("data_center_name"),
kwargs.get("datastore_name"),