From b2e0598d3fb82455383fe4a6128b5a0a980667e2 Mon Sep 17 00:00:00 2001 From: Sean Chen Date: Thu, 10 Jan 2013 13:29:20 -0800 Subject: 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 --- nova/compute/manager.py | 2 +- nova/console/vmrc_manager.py | 2 +- nova/locale/nova.pot | 4 +- nova/tests/test_vmwareapi.py | 10 +- nova/tests/vmwareapi/stubs.py | 14 +-- nova/virt/vmwareapi/__init__.py | 2 +- nova/virt/vmwareapi/driver.py | 28 +++--- nova/virt/vmwareapi/fake.py | 2 +- nova/virt/vmwareapi/network_util.py | 170 +++++++++++++++++++++++++++++++++ nova/virt/vmwareapi/network_utils.py | 170 --------------------------------- nova/virt/vmwareapi/read_write_util.py | 12 +-- nova/virt/vmwareapi/vif.py | 14 +-- nova/virt/vmwareapi/vim.py | 123 ++++++++++++------------ nova/virt/vmwareapi/vm_util.py | 2 +- nova/virt/vmwareapi/vmops.py | 6 +- nova/virt/vmwareapi/vmware_images.py | 10 +- 16 files changed, 284 insertions(+), 287 deletions(-) create mode 100644 nova/virt/vmwareapi/network_util.py delete mode 100644 nova/virt/vmwareapi/network_utils.py diff --git a/nova/compute/manager.py b/nova/compute/manager.py index f138a3708..1479710fa 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -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, diff --git a/nova/console/vmrc_manager.py b/nova/console/vmrc_manager.py index e8eab4db2..041e5ce89 100644 --- a/nova/console/vmrc_manager.py +++ b/nova/console/vmrc_manager.py @@ -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'], diff --git a/nova/locale/nova.pot b/nova/locale/nova.pot index 3fb397298..347b98733 100644 --- a/nova/locale/nova.pot +++ b/nova/locale/nova.pot @@ -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 diff --git a/nova/tests/test_vmwareapi.py b/nova/tests/test_vmwareapi.py index 86b3a5730..577d227ce 100644 --- a/nova/tests/test_vmwareapi.py +++ b/nova/tests/test_vmwareapi.py @@ -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() diff --git a/nova/tests/vmwareapi/stubs.py b/nova/tests/vmwareapi/stubs.py index 494b201d0..0330246e2 100644 --- a/nova/tests/vmwareapi/stubs.py +++ b/nova/tests/vmwareapi/stubs.py @@ -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) diff --git a/nova/virt/vmwareapi/__init__.py b/nova/virt/vmwareapi/__init__.py index fa6f6ceb5..66e7d9b02 100644 --- a/nova/virt/vmwareapi/__init__.py +++ b/nova/virt/vmwareapi/__init__.py @@ -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 diff --git a/nova/virt/vmwareapi/driver.py b/nova/virt/vmwareapi/driver.py index 8734df1f6..986c4ef28 100644 --- a/nova/virt/vmwareapi/driver.py +++ b/nova/virt/vmwareapi/driver.py @@ -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. diff --git a/nova/virt/vmwareapi/fake.py b/nova/virt/vmwareapi/fake.py index fdf85dc8b..3f5041c22 100644 --- a/nova/virt/vmwareapi/fake.py +++ b/nova/virt/vmwareapi/fake.py @@ -16,7 +16,7 @@ # under the License. """ -A fake VMWare VI API implementation. +A fake VMware VI API implementation. """ import pprint diff --git a/nova/virt/vmwareapi/network_util.py b/nova/virt/vmwareapi/network_util.py new file mode 100644 index 000000000..a3b20137d --- /dev/null +++ b/nova/virt/vmwareapi/network_util.py @@ -0,0 +1,170 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2011 Citrix Systems, Inc. +# Copyright 2011 OpenStack LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Utility functions for ESX Networking. +""" + +from nova import exception +from nova.openstack.common import log as logging +from nova.virt.vmwareapi import error_util +from nova.virt.vmwareapi import vim_util +from nova.virt.vmwareapi import vm_util + +LOG = logging.getLogger(__name__) + + +def get_network_with_the_name(session, network_name="vmnet0"): + """ + Gets reference to the network whose name is passed as the + argument. + """ + hostsystems = session._call_method(vim_util, "get_objects", + "HostSystem", ["network"]) + vm_networks_ret = hostsystems[0].propSet[0].val + # Meaning there are no networks on the host. suds responds with a "" + # in the parent property field rather than a [] in the + # ManagedObjectRefernce property field of the parent + if not vm_networks_ret: + return None + vm_networks = vm_networks_ret.ManagedObjectReference + networks = session._call_method(vim_util, + "get_properties_for_a_collection_of_objects", + "Network", vm_networks, ["summary.name"]) + network_obj = {} + LOG.warn(vm_networks) + for network in vm_networks: + # Get network properties + if network._type == 'DistributedVirtualPortgroup': + props = session._call_method(vim_util, + "get_dynamic_property", network, + "DistributedVirtualPortgroup", "config") + # NOTE(asomya): This only works on ESXi if the port binding is + # set to ephemeral + if props.name == network_name: + network_obj['type'] = 'DistributedVirtualPortgroup' + network_obj['dvpg'] = props.key + network_obj['dvsw'] = props.distributedVirtualSwitch.value + else: + props = session._call_method(vim_util, + "get_dynamic_property", network, + "Network", "summary.name") + if props == network_name: + network_obj['type'] = 'Network' + network_obj['name'] = network_name + if (len(network_obj) > 0): + return network_obj + else: + return None + + +def get_vswitch_for_vlan_interface(session, vlan_interface): + """ + Gets the vswitch associated with the physical network adapter + with the name supplied. + """ + # Get the list of vSwicthes on the Host System + host_mor = session._call_method(vim_util, "get_objects", + "HostSystem")[0].obj + vswitches_ret = session._call_method(vim_util, + "get_dynamic_property", host_mor, + "HostSystem", "config.network.vswitch") + # Meaning there are no vSwitches on the host. Shouldn't be the case, + # but just doing code check + if not vswitches_ret: + return + vswitches = vswitches_ret.HostVirtualSwitch + # Get the vSwitch associated with the network adapter + for elem in vswitches: + try: + for nic_elem in elem.pnic: + if str(nic_elem).split('-')[-1].find(vlan_interface) != -1: + return elem.name + # Catching Attribute error as a vSwitch may not be associated with a + # physical NIC. + except AttributeError: + pass + + +def check_if_vlan_interface_exists(session, vlan_interface): + """Checks if the vlan_inteface exists on the esx host.""" + host_net_system_mor = session._call_method(vim_util, "get_objects", + "HostSystem", ["configManager.networkSystem"])[0].propSet[0].val + physical_nics_ret = session._call_method(vim_util, + "get_dynamic_property", host_net_system_mor, + "HostNetworkSystem", "networkInfo.pnic") + # Meaning there are no physical nics on the host + if not physical_nics_ret: + return False + physical_nics = physical_nics_ret.PhysicalNic + for pnic in physical_nics: + if vlan_interface == pnic.device: + return True + return False + + +def get_vlanid_and_vswitch_for_portgroup(session, pg_name): + """Get the vlan id and vswicth associated with the port group.""" + host_mor = session._call_method(vim_util, "get_objects", + "HostSystem")[0].obj + port_grps_on_host_ret = session._call_method(vim_util, + "get_dynamic_property", host_mor, + "HostSystem", "config.network.portgroup") + if not port_grps_on_host_ret: + msg = _("ESX SOAP server returned an empty port group " + "for the host system in its response") + LOG.error(msg) + raise exception.NovaException(msg) + port_grps_on_host = port_grps_on_host_ret.HostPortGroup + for p_gp in port_grps_on_host: + if p_gp.spec.name == pg_name: + p_grp_vswitch_name = p_gp.vswitch.split("-")[-1] + return p_gp.spec.vlanId, p_grp_vswitch_name + + +def create_port_group(session, pg_name, vswitch_name, vlan_id=0): + """ + Creates a port group on the host system with the vlan tags + supplied. VLAN id 0 means no vlan id association. + """ + client_factory = session._get_vim().client.factory + add_prt_grp_spec = vm_util.get_add_vswitch_port_group_spec( + client_factory, + vswitch_name, + pg_name, + vlan_id) + host_mor = session._call_method(vim_util, "get_objects", + "HostSystem")[0].obj + network_system_mor = session._call_method(vim_util, + "get_dynamic_property", host_mor, + "HostSystem", "configManager.networkSystem") + LOG.debug(_("Creating Port Group with name %s on " + "the ESX host") % pg_name) + try: + session._call_method(session._get_vim(), + "AddPortGroup", network_system_mor, + portgrp=add_prt_grp_spec) + except error_util.VimFaultException, exc: + # There can be a race condition when two instances try + # adding port groups at the same time. One succeeds, then + # the other one will get an exception. Since we are + # concerned with the port group being created, which is done + # by the other call, we can ignore the exception. + if error_util.FAULT_ALREADY_EXISTS not in exc.fault_list: + raise exception.NovaException(exc) + LOG.debug(_("Created Port Group with name %s on " + "the ESX host") % pg_name) diff --git a/nova/virt/vmwareapi/network_utils.py b/nova/virt/vmwareapi/network_utils.py deleted file mode 100644 index a3b20137d..000000000 --- a/nova/virt/vmwareapi/network_utils.py +++ /dev/null @@ -1,170 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright (c) 2011 Citrix Systems, Inc. -# Copyright 2011 OpenStack LLC. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Utility functions for ESX Networking. -""" - -from nova import exception -from nova.openstack.common import log as logging -from nova.virt.vmwareapi import error_util -from nova.virt.vmwareapi import vim_util -from nova.virt.vmwareapi import vm_util - -LOG = logging.getLogger(__name__) - - -def get_network_with_the_name(session, network_name="vmnet0"): - """ - Gets reference to the network whose name is passed as the - argument. - """ - hostsystems = session._call_method(vim_util, "get_objects", - "HostSystem", ["network"]) - vm_networks_ret = hostsystems[0].propSet[0].val - # Meaning there are no networks on the host. suds responds with a "" - # in the parent property field rather than a [] in the - # ManagedObjectRefernce property field of the parent - if not vm_networks_ret: - return None - vm_networks = vm_networks_ret.ManagedObjectReference - networks = session._call_method(vim_util, - "get_properties_for_a_collection_of_objects", - "Network", vm_networks, ["summary.name"]) - network_obj = {} - LOG.warn(vm_networks) - for network in vm_networks: - # Get network properties - if network._type == 'DistributedVirtualPortgroup': - props = session._call_method(vim_util, - "get_dynamic_property", network, - "DistributedVirtualPortgroup", "config") - # NOTE(asomya): This only works on ESXi if the port binding is - # set to ephemeral - if props.name == network_name: - network_obj['type'] = 'DistributedVirtualPortgroup' - network_obj['dvpg'] = props.key - network_obj['dvsw'] = props.distributedVirtualSwitch.value - else: - props = session._call_method(vim_util, - "get_dynamic_property", network, - "Network", "summary.name") - if props == network_name: - network_obj['type'] = 'Network' - network_obj['name'] = network_name - if (len(network_obj) > 0): - return network_obj - else: - return None - - -def get_vswitch_for_vlan_interface(session, vlan_interface): - """ - Gets the vswitch associated with the physical network adapter - with the name supplied. - """ - # Get the list of vSwicthes on the Host System - host_mor = session._call_method(vim_util, "get_objects", - "HostSystem")[0].obj - vswitches_ret = session._call_method(vim_util, - "get_dynamic_property", host_mor, - "HostSystem", "config.network.vswitch") - # Meaning there are no vSwitches on the host. Shouldn't be the case, - # but just doing code check - if not vswitches_ret: - return - vswitches = vswitches_ret.HostVirtualSwitch - # Get the vSwitch associated with the network adapter - for elem in vswitches: - try: - for nic_elem in elem.pnic: - if str(nic_elem).split('-')[-1].find(vlan_interface) != -1: - return elem.name - # Catching Attribute error as a vSwitch may not be associated with a - # physical NIC. - except AttributeError: - pass - - -def check_if_vlan_interface_exists(session, vlan_interface): - """Checks if the vlan_inteface exists on the esx host.""" - host_net_system_mor = session._call_method(vim_util, "get_objects", - "HostSystem", ["configManager.networkSystem"])[0].propSet[0].val - physical_nics_ret = session._call_method(vim_util, - "get_dynamic_property", host_net_system_mor, - "HostNetworkSystem", "networkInfo.pnic") - # Meaning there are no physical nics on the host - if not physical_nics_ret: - return False - physical_nics = physical_nics_ret.PhysicalNic - for pnic in physical_nics: - if vlan_interface == pnic.device: - return True - return False - - -def get_vlanid_and_vswitch_for_portgroup(session, pg_name): - """Get the vlan id and vswicth associated with the port group.""" - host_mor = session._call_method(vim_util, "get_objects", - "HostSystem")[0].obj - port_grps_on_host_ret = session._call_method(vim_util, - "get_dynamic_property", host_mor, - "HostSystem", "config.network.portgroup") - if not port_grps_on_host_ret: - msg = _("ESX SOAP server returned an empty port group " - "for the host system in its response") - LOG.error(msg) - raise exception.NovaException(msg) - port_grps_on_host = port_grps_on_host_ret.HostPortGroup - for p_gp in port_grps_on_host: - if p_gp.spec.name == pg_name: - p_grp_vswitch_name = p_gp.vswitch.split("-")[-1] - return p_gp.spec.vlanId, p_grp_vswitch_name - - -def create_port_group(session, pg_name, vswitch_name, vlan_id=0): - """ - Creates a port group on the host system with the vlan tags - supplied. VLAN id 0 means no vlan id association. - """ - client_factory = session._get_vim().client.factory - add_prt_grp_spec = vm_util.get_add_vswitch_port_group_spec( - client_factory, - vswitch_name, - pg_name, - vlan_id) - host_mor = session._call_method(vim_util, "get_objects", - "HostSystem")[0].obj - network_system_mor = session._call_method(vim_util, - "get_dynamic_property", host_mor, - "HostSystem", "configManager.networkSystem") - LOG.debug(_("Creating Port Group with name %s on " - "the ESX host") % pg_name) - try: - session._call_method(session._get_vim(), - "AddPortGroup", network_system_mor, - portgrp=add_prt_grp_spec) - except error_util.VimFaultException, exc: - # There can be a race condition when two instances try - # adding port groups at the same time. One succeeds, then - # the other one will get an exception. Since we are - # concerned with the port group being created, which is done - # by the other call, we can ignore the exception. - if error_util.FAULT_ALREADY_EXISTS not in exc.fault_list: - raise exception.NovaException(exc) - LOG.debug(_("Created Port Group with name %s on " - "the ESX host") % pg_name) diff --git a/nova/virt/vmwareapi/read_write_util.py b/nova/virt/vmwareapi/read_write_util.py index 52d095ad3..39ea8e2e8 100644 --- a/nova/virt/vmwareapi/read_write_util.py +++ b/nova/virt/vmwareapi/read_write_util.py @@ -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"): diff --git a/nova/virt/vmwareapi/vif.py b/nova/virt/vmwareapi/vif.py index 4d53e266d..c5b524186 100644 --- a/nova/virt/vmwareapi/vif.py +++ b/nova/virt/vmwareapi/vif.py @@ -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 diff --git a/nova/virt/vmwareapi/vim.py b/nova/virt/vmwareapi/vim.py index 194b78a1d..83d120df5 100644 --- a/nova/virt/vmwareapi/vim.py +++ b/nova/virt/vmwareapi/vim.py @@ -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. - - 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 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 def _request_managed_object_builder(self, managed_object): """Builds the request managed object.""" diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py index 740355679..e03b88804 100644 --- a/nova/virt/vmwareapi/vm_util.py +++ b/nova/virt/vmwareapi/vm_util.py @@ -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) diff --git a/nova/virt/vmwareapi/vmops.py b/nova/virt/vmwareapi/vmops.py index e591245e2..883e751a8 100644 --- a/nova/virt/vmwareapi/vmops.py +++ b/nova/virt/vmwareapi/vmops.py @@ -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) diff --git a/nova/virt/vmwareapi/vmware_images.py b/nova/virt/vmwareapi/vmware_images.py index 15237fd5b..7c4480ea0 100644 --- a/nova/virt/vmwareapi/vmware_images.py +++ b/nova/virt/vmwareapi/vmware_images.py @@ -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"), -- cgit