From d74bd786783660eed4f15090b0b24ff519c2a2c8 Mon Sep 17 00:00:00 2001 From: fujioka yuuichi Date: Thu, 10 Oct 2013 20:54:40 +0900 Subject: [PATCH] Apply six for metaclass __metaclass__ cannot be used in python3. six be used in general for python 3 compatibility. Change-Id: Ib0d71b9676dc01390679396443575c05975d3b58 Closes-Bug: #1236648 --- neutron/agent/firewall.py | 5 +++-- neutron/agent/l2population_rpc.py | 3 ++- neutron/agent/linux/dhcp.py | 3 ++- neutron/agent/linux/interface.py | 3 ++- neutron/api/extensions.py | 3 ++- neutron/extensions/firewall.py | 3 ++- neutron/extensions/loadbalancer.py | 3 ++- neutron/extensions/metering.py | 4 +++- neutron/extensions/securitygroup.py | 3 ++- neutron/extensions/vpnaas.py | 3 ++- neutron/neutron_plugin_base_v2.py | 5 +++-- neutron/plugins/cisco/l2device_plugin_base.py | 5 +++-- neutron/plugins/embrane/l2base/support_base.py | 4 +++- neutron/plugins/ml2/driver_api.py | 17 +++++++---------- neutron/plugins/ml2/drivers/mech_agent.py | 5 +++-- neutron/plugins/ml2/drivers/type_tunnel.py | 5 +++-- neutron/plugins/nec/ofc_driver_base.py | 5 +++-- neutron/plugins/nec/router_drivers.py | 5 +++-- neutron/plugins/nicira/api_client/client.py | 4 ++-- neutron/plugins/nicira/api_client/request.py | 5 +++-- neutron/services/firewall/drivers/fwaas_base.py | 5 +++-- .../loadbalancer/drivers/abstract_driver.py | 4 +++- .../metering/drivers/abstract_driver.py | 4 +++- neutron/services/service_base.py | 4 +++- neutron/services/vpn/device_drivers/__init__.py | 4 +++- neutron/services/vpn/device_drivers/ipsec.py | 5 +++-- .../services/vpn/service_drivers/__init__.py | 4 +++- 27 files changed, 76 insertions(+), 47 deletions(-) diff --git a/neutron/agent/firewall.py b/neutron/agent/firewall.py index 8ca6715027..6c9cd25029 100644 --- a/neutron/agent/firewall.py +++ b/neutron/agent/firewall.py @@ -18,7 +18,10 @@ import abc import contextlib +import six + +@six.add_metaclass(abc.ABCMeta) class FirewallDriver(object): """Firewall Driver base class. @@ -52,8 +55,6 @@ class FirewallDriver(object): remote_group_id will also remaining membership update management """ - __metaclass__ = abc.ABCMeta - def prepare_port_filter(self, port): """Prepare filters for the port. diff --git a/neutron/agent/l2population_rpc.py b/neutron/agent/l2population_rpc.py index f108c4ebdc..80c5a97de0 100644 --- a/neutron/agent/l2population_rpc.py +++ b/neutron/agent/l2population_rpc.py @@ -20,12 +20,13 @@ import abc from oslo.config import cfg +import six from neutron.common import log +@six.add_metaclass(abc.ABCMeta) class L2populationRpcCallBackMixin(object): - __metaclass__ = abc.ABCMeta @log.log def add_fdb_entries(self, context, fdb_entries, host=None): diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index fdb6c9b757..4d29405ea3 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -26,6 +26,7 @@ import uuid import netaddr from oslo.config import cfg +import six from neutron.agent.linux import ip_lib from neutron.agent.linux import utils @@ -101,8 +102,8 @@ class NetModel(DictModel): return self._ns_name +@six.add_metaclass(abc.ABCMeta) class DhcpBase(object): - __metaclass__ = abc.ABCMeta def __init__(self, conf, network, root_helper='sudo', version=None, plugin=None): diff --git a/neutron/agent/linux/interface.py b/neutron/agent/linux/interface.py index 42a1f82d15..a39adb360a 100644 --- a/neutron/agent/linux/interface.py +++ b/neutron/agent/linux/interface.py @@ -19,6 +19,7 @@ import abc import netaddr from oslo.config import cfg +import six from neutron.agent.common import config from neutron.agent.linux import ip_lib @@ -59,8 +60,8 @@ OPTS = [ ] +@six.add_metaclass(abc.ABCMeta) class LinuxInterfaceDriver(object): - __metaclass__ = abc.ABCMeta # from linux IF_NAMESIZE DEV_NAME_LEN = 14 diff --git a/neutron/api/extensions.py b/neutron/api/extensions.py index 5919d83965..e425cbb046 100644 --- a/neutron/api/extensions.py +++ b/neutron/api/extensions.py @@ -22,6 +22,7 @@ import os from oslo.config import cfg import routes +import six import webob.dec import webob.exc @@ -36,8 +37,8 @@ from neutron import wsgi LOG = logging.getLogger(__name__) +@six.add_metaclass(ABCMeta) class PluginInterface(object): - __metaclass__ = ABCMeta @classmethod def __subclasshook__(cls, klass): diff --git a/neutron/extensions/firewall.py b/neutron/extensions/firewall.py index a4d1580250..d6e43a5a15 100644 --- a/neutron/extensions/firewall.py +++ b/neutron/extensions/firewall.py @@ -20,6 +20,7 @@ import abc from oslo.config import cfg +import six from neutron.api import extensions from neutron.api.v2 import attributes as attr @@ -376,8 +377,8 @@ class Firewall(extensions.ExtensionDescriptor): return {} +@six.add_metaclass(abc.ABCMeta) class FirewallPluginBase(ServicePluginBase): - __metaclass__ = abc.ABCMeta def get_plugin_name(self): return constants.FIREWALL diff --git a/neutron/extensions/loadbalancer.py b/neutron/extensions/loadbalancer.py index d2dde8adb7..2cbd914e70 100644 --- a/neutron/extensions/loadbalancer.py +++ b/neutron/extensions/loadbalancer.py @@ -18,6 +18,7 @@ import abc from oslo.config import cfg +import six from neutron.api import extensions from neutron.api.v2 import attributes as attr @@ -376,8 +377,8 @@ class Loadbalancer(extensions.ExtensionDescriptor): return {} +@six.add_metaclass(abc.ABCMeta) class LoadBalancerPluginBase(ServicePluginBase): - __metaclass__ = abc.ABCMeta def get_plugin_name(self): return constants.LOADBALANCER diff --git a/neutron/extensions/metering.py b/neutron/extensions/metering.py index 67ec4d5907..f9417b53c2 100644 --- a/neutron/extensions/metering.py +++ b/neutron/extensions/metering.py @@ -16,6 +16,8 @@ import abc +import six + from neutron.api import extensions from neutron.api.v2 import attributes as attr from neutron.api.v2 import base @@ -147,8 +149,8 @@ class Metering(extensions.ExtensionDescriptor): return {} +@six.add_metaclass(abc.ABCMeta) class MeteringPluginBase(service_base.ServicePluginBase): - __metaclass__ = abc.ABCMeta def get_plugin_name(self): return constants.METERING diff --git a/neutron/extensions/securitygroup.py b/neutron/extensions/securitygroup.py index 85d499ad59..3fcf15a78f 100644 --- a/neutron/extensions/securitygroup.py +++ b/neutron/extensions/securitygroup.py @@ -19,6 +19,7 @@ from abc import ABCMeta from abc import abstractmethod from oslo.config import cfg +import six from neutron.api import extensions from neutron.api.v2 import attributes as attr @@ -291,8 +292,8 @@ class Securitygroup(extensions.ExtensionDescriptor): return {} +@six.add_metaclass(ABCMeta) class SecurityGroupPluginBase(object): - __metaclass__ = ABCMeta @abstractmethod def create_security_group(self, context, security_group): diff --git a/neutron/extensions/vpnaas.py b/neutron/extensions/vpnaas.py index 44d12f683b..8e42b62f99 100644 --- a/neutron/extensions/vpnaas.py +++ b/neutron/extensions/vpnaas.py @@ -20,6 +20,7 @@ import abc from oslo.config import cfg +import six from neutron.api import extensions from neutron.api.v2 import attributes as attr @@ -405,8 +406,8 @@ class Vpnaas(extensions.ExtensionDescriptor): return {} +@six.add_metaclass(abc.ABCMeta) class VPNPluginBase(ServicePluginBase): - __metaclass__ = abc.ABCMeta def get_plugin_name(self): return constants.VPN diff --git a/neutron/neutron_plugin_base_v2.py b/neutron/neutron_plugin_base_v2.py index fb60ffe599..43b99f5da8 100644 --- a/neutron/neutron_plugin_base_v2.py +++ b/neutron/neutron_plugin_base_v2.py @@ -23,11 +23,12 @@ methods that needs to be implemented by a v2 Neutron Plug-in. from abc import ABCMeta, abstractmethod +import six + +@six.add_metaclass(ABCMeta) class NeutronPluginBaseV2(object): - __metaclass__ = ABCMeta - @abstractmethod def create_subnet(self, context, subnet): """Create a subnet. diff --git a/neutron/plugins/cisco/l2device_plugin_base.py b/neutron/plugins/cisco/l2device_plugin_base.py index cbac97585f..453302fcbc 100644 --- a/neutron/plugins/cisco/l2device_plugin_base.py +++ b/neutron/plugins/cisco/l2device_plugin_base.py @@ -19,7 +19,10 @@ from abc import ABCMeta, abstractmethod import inspect +import six + +@six.add_metaclass(ABCMeta) class L2DevicePluginBase(object): """Base class for a device-specific plugin. @@ -28,8 +31,6 @@ class L2DevicePluginBase(object): the configuration on each device. """ - __metaclass__ = ABCMeta - @abstractmethod def get_all_networks(self, tenant_id, **kwargs): """Get newtorks. diff --git a/neutron/plugins/embrane/l2base/support_base.py b/neutron/plugins/embrane/l2base/support_base.py index ee4ca65cc5..a2b7e53424 100644 --- a/neutron/plugins/embrane/l2base/support_base.py +++ b/neutron/plugins/embrane/l2base/support_base.py @@ -19,7 +19,10 @@ import abc +import six + +@six.add_metaclass(abc.ABCMeta) class SupportBase(object): """abstract support class. @@ -27,7 +30,6 @@ class SupportBase(object): the L2 base for Embrane plugin. """ - __metaclass__ = abc.ABCMeta @abc.abstractmethod def __init__(self): diff --git a/neutron/plugins/ml2/driver_api.py b/neutron/plugins/ml2/driver_api.py index 8925a7666a..d7663042b9 100644 --- a/neutron/plugins/ml2/driver_api.py +++ b/neutron/plugins/ml2/driver_api.py @@ -15,6 +15,8 @@ from abc import ABCMeta, abstractmethod, abstractproperty +import six + # The following keys are used in the segment dictionaries passed via # the driver API. These are defined separately from similar keys in # neutron.extensions.providernet so that drivers don't need to change @@ -26,6 +28,7 @@ PHYSICAL_NETWORK = 'physical_network' SEGMENTATION_ID = 'segmentation_id' +@six.add_metaclass(ABCMeta) class TypeDriver(object): """Define stable abstract interface for ML2 type drivers. @@ -43,8 +46,6 @@ class TypeDriver(object): either be excluded or stored as None. """ - __metaclass__ = ABCMeta - @abstractmethod def get_type(self): """Get driver's network type. @@ -128,6 +129,7 @@ class TypeDriver(object): pass +@six.add_metaclass(ABCMeta) class NetworkContext(object): """Context passed to MechanismDrivers for changes to network resources. @@ -137,8 +139,6 @@ class NetworkContext(object): MechanismDrivers can freely access the same information. """ - __metaclass__ = ABCMeta - @abstractproperty def current(self): """Return the current state of the network. @@ -165,6 +165,7 @@ class NetworkContext(object): pass +@six.add_metaclass(ABCMeta) class SubnetContext(object): """Context passed to MechanismDrivers for changes to subnet resources. @@ -174,8 +175,6 @@ class SubnetContext(object): MechanismDrivers can freely access the same information. """ - __metaclass__ = ABCMeta - @abstractproperty def current(self): """Return the current state of the subnet. @@ -197,6 +196,7 @@ class SubnetContext(object): pass +@six.add_metaclass(ABCMeta) class PortContext(object): """Context passed to MechanismDrivers for changes to port resources. @@ -206,8 +206,6 @@ class PortContext(object): freely access the same information. """ - __metaclass__ = ABCMeta - @abstractproperty def current(self): """Return the current state of the port. @@ -262,6 +260,7 @@ class PortContext(object): pass +@six.add_metaclass(ABCMeta) class MechanismDriver(object): """Define stable abstract interface for ML2 mechanism drivers. @@ -283,8 +282,6 @@ class MechanismDriver(object): methods that are part of the database transaction. """ - __metaclass__ = ABCMeta - @abstractmethod def initialize(self): """Perform driver initialization. diff --git a/neutron/plugins/ml2/drivers/mech_agent.py b/neutron/plugins/ml2/drivers/mech_agent.py index a89956f906..7bf21a4975 100644 --- a/neutron/plugins/ml2/drivers/mech_agent.py +++ b/neutron/plugins/ml2/drivers/mech_agent.py @@ -15,12 +15,15 @@ from abc import ABCMeta, abstractmethod +import six + from neutron.openstack.common import log from neutron.plugins.ml2 import driver_api as api LOG = log.getLogger(__name__) +@six.add_metaclass(ABCMeta) class AgentMechanismDriverBase(api.MechanismDriver): """Base class for drivers that attach to networks using an L2 agent. @@ -35,8 +38,6 @@ class AgentMechanismDriverBase(api.MechanismDriver): check_segment_for_agent(). """ - __metaclass__ = ABCMeta - def __init__(self, agent_type, vif_type, cap_port_filter): """Initialize base class for specific L2 agent type. diff --git a/neutron/plugins/ml2/drivers/type_tunnel.py b/neutron/plugins/ml2/drivers/type_tunnel.py index a761bf26b1..5081d9e57f 100644 --- a/neutron/plugins/ml2/drivers/type_tunnel.py +++ b/neutron/plugins/ml2/drivers/type_tunnel.py @@ -14,6 +14,8 @@ # under the License. from abc import ABCMeta, abstractmethod +import six + from neutron.common import exceptions as exc from neutron.common import topics from neutron.openstack.common import log @@ -24,6 +26,7 @@ LOG = log.getLogger(__name__) TUNNEL = 'tunnel' +@six.add_metaclass(ABCMeta) class TunnelTypeDriver(api.TypeDriver): """Define stable abstract interface for ML2 type drivers. @@ -31,8 +34,6 @@ class TunnelTypeDriver(api.TypeDriver): methods to manage these endpoints. """ - __metaclass__ = ABCMeta - @abstractmethod def add_endpoint(self, ip): """Register the endpoint in the type_driver database. diff --git a/neutron/plugins/nec/ofc_driver_base.py b/neutron/plugins/nec/ofc_driver_base.py index 680286101d..e367ba3442 100644 --- a/neutron/plugins/nec/ofc_driver_base.py +++ b/neutron/plugins/nec/ofc_driver_base.py @@ -18,7 +18,10 @@ from abc import ABCMeta, abstractmethod +import six + +@six.add_metaclass(ABCMeta) class OFCDriverBase(object): """OpenFlow Controller (OFC) Driver Specification. @@ -26,8 +29,6 @@ class OFCDriverBase(object): It would be better that other methods like update_* are implemented. """ - __metaclass__ = ABCMeta - @abstractmethod def create_tenant(self, description, tenant_id=None): """Create a new tenant at OpenFlow Controller. diff --git a/neutron/plugins/nec/router_drivers.py b/neutron/plugins/nec/router_drivers.py index b16c4d8a0f..9781f0b6e0 100644 --- a/neutron/plugins/nec/router_drivers.py +++ b/neutron/plugins/nec/router_drivers.py @@ -19,6 +19,8 @@ import abc import httplib +import six + from neutron.common import log as call_log from neutron.common import utils from neutron.openstack.common import excutils @@ -31,10 +33,9 @@ LOG = logging.getLogger(__name__) PROVIDER_OPENFLOW = nconst.ROUTER_PROVIDER_OPENFLOW +@six.add_metaclass(abc.ABCMeta) class RouterDriverBase(object): - __metaclass__ = abc.ABCMeta - def __init__(self, plugin, ofc_manager): self.plugin = plugin self.ofc = ofc_manager diff --git a/neutron/plugins/nicira/api_client/client.py b/neutron/plugins/nicira/api_client/client.py index 01a068f77e..6a86695eea 100644 --- a/neutron/plugins/nicira/api_client/client.py +++ b/neutron/plugins/nicira/api_client/client.py @@ -24,6 +24,7 @@ import httplib import logging import time +import six from neutron.plugins.nicira.api_client.common import ( _conn_str) @@ -37,6 +38,7 @@ DEFAULT_CONCURRENT_CONNECTIONS = 3 DEFAULT_CONNECT_TIMEOUT = 5 +@six.add_metaclass(ABCMeta) class NvpApiClient(object): '''An abstract baseclass for all NvpApiClient implementations. @@ -44,8 +46,6 @@ class NvpApiClient(object): coroutine-based classes. ''' - __metaclass__ = ABCMeta - CONN_IDLE_TIMEOUT = 60 * 15 def _create_connection(self, host, port, is_ssl): diff --git a/neutron/plugins/nicira/api_client/request.py b/neutron/plugins/nicira/api_client/request.py index 056e55cd8b..c54ed1bdfe 100644 --- a/neutron/plugins/nicira/api_client/request.py +++ b/neutron/plugins/nicira/api_client/request.py @@ -26,6 +26,8 @@ import logging import time import urlparse +import six + from neutron.openstack.common import excutils from neutron.plugins.nicira.api_client.common import ( _conn_str) @@ -45,6 +47,7 @@ DOWNLOAD_TIMEOUT = 180 # The UI code has a coorespoind 190 sec timeout # for downloads, see: django/nvp_console/views.py +@six.add_metaclass(ABCMeta) class NvpApiRequest(object): '''An abstract baseclass for all ApiRequest implementations. @@ -52,8 +55,6 @@ class NvpApiRequest(object): gevent-based ApiRequest classes. ''' - __metaclass__ = ABCMeta - # List of allowed status codes. ALLOWED_STATUS_CODES = [ httplib.OK, diff --git a/neutron/services/firewall/drivers/fwaas_base.py b/neutron/services/firewall/drivers/fwaas_base.py index 66bf867c11..7128e251a2 100644 --- a/neutron/services/firewall/drivers/fwaas_base.py +++ b/neutron/services/firewall/drivers/fwaas_base.py @@ -19,7 +19,10 @@ import abc +import six + +@six.add_metaclass(abc.ABCMeta) class FwaasDriverBase(object): """Firewall as a Service Driver base class. @@ -60,8 +63,6 @@ class FwaasDriverBase(object): application of rules. """ - __metaclass__ = abc.ABCMeta - @abc.abstractmethod def create_firewall(self, apply_list, firewall): """Create the Firewall with default (drop all) policy. diff --git a/neutron/services/loadbalancer/drivers/abstract_driver.py b/neutron/services/loadbalancer/drivers/abstract_driver.py index 50212d1fc0..b3519bffe5 100644 --- a/neutron/services/loadbalancer/drivers/abstract_driver.py +++ b/neutron/services/loadbalancer/drivers/abstract_driver.py @@ -18,7 +18,10 @@ import abc +import six + +@six.add_metaclass(abc.ABCMeta) class LoadBalancerAbstractDriver(object): """Abstract lbaas driver that expose ~same API as lbaas plugin. @@ -27,7 +30,6 @@ class LoadBalancerAbstractDriver(object): Get operations are not part of the API - it will be handled by the lbaas plugin. """ - __metaclass__ = abc.ABCMeta @abc.abstractmethod def create_vip(self, context, vip): diff --git a/neutron/services/metering/drivers/abstract_driver.py b/neutron/services/metering/drivers/abstract_driver.py index a5e5ca193c..884fbba50a 100644 --- a/neutron/services/metering/drivers/abstract_driver.py +++ b/neutron/services/metering/drivers/abstract_driver.py @@ -16,10 +16,12 @@ import abc +import six + +@six.add_metaclass(abc.ABCMeta) class MeteringAbstractDriver(object): """Abstract Metering driver.""" - __metaclass__ = abc.ABCMeta def __init__(self, plugin, conf): pass diff --git a/neutron/services/service_base.py b/neutron/services/service_base.py index a70c17f271..2730dee6de 100644 --- a/neutron/services/service_base.py +++ b/neutron/services/service_base.py @@ -17,6 +17,8 @@ import abc +import six + from neutron.api import extensions from neutron.db import servicetype_db as sdb from neutron.openstack.common import importutils @@ -26,9 +28,9 @@ from neutron.services import provider_configuration as pconf LOG = logging.getLogger(__name__) +@six.add_metaclass(abc.ABCMeta) class ServicePluginBase(extensions.PluginInterface): """Define base interface for any Advanced Service plugin.""" - __metaclass__ = abc.ABCMeta supported_extension_aliases = [] @abc.abstractmethod diff --git a/neutron/services/vpn/device_drivers/__init__.py b/neutron/services/vpn/device_drivers/__init__.py index c15fcbfd9b..c6d5f69e31 100644 --- a/neutron/services/vpn/device_drivers/__init__.py +++ b/neutron/services/vpn/device_drivers/__init__.py @@ -16,9 +16,11 @@ # under the License. import abc +import six + +@six.add_metaclass(abc.ABCMeta) class DeviceDriver(object): - __metaclass__ = abc.ABCMeta def __init__(self, agent, host): pass diff --git a/neutron/services/vpn/device_drivers/ipsec.py b/neutron/services/vpn/device_drivers/ipsec.py index fda64798bb..ad16996dc5 100644 --- a/neutron/services/vpn/device_drivers/ipsec.py +++ b/neutron/services/vpn/device_drivers/ipsec.py @@ -23,6 +23,7 @@ import shutil import jinja2 import netaddr from oslo.config import cfg +import six from neutron.agent.linux import ip_lib from neutron.agent.linux import utils @@ -85,13 +86,13 @@ def _get_template(template_file): return JINJA_ENV.get_template(template_file) +@six.add_metaclass(abc.ABCMeta) class BaseSwanProcess(): """Swan Family Process Manager This class manages start/restart/stop ipsec process. This class create/delete config template """ - __metaclass__ = abc.ABCMeta binary = "ipsec" CONFIG_DIRS = [ @@ -465,6 +466,7 @@ class IPsecVpnDriverApi(proxy.RpcProxy): topic=self.topic) +@six.add_metaclass(abc.ABCMeta) class IPsecDriver(device_drivers.DeviceDriver): """VPN Device Driver for IPSec. @@ -478,7 +480,6 @@ class IPsecDriver(device_drivers.DeviceDriver): # 1.0 Initial version RPC_API_VERSION = '1.0' - __metaclass__ = abc.ABCMeta def __init__(self, agent, host): self.agent = agent diff --git a/neutron/services/vpn/service_drivers/__init__.py b/neutron/services/vpn/service_drivers/__init__.py index 4996882e1c..edb27abec8 100644 --- a/neutron/services/vpn/service_drivers/__init__.py +++ b/neutron/services/vpn/service_drivers/__init__.py @@ -17,9 +17,11 @@ import abc +import six + +@six.add_metaclass(abc.ABCMeta) class VpnDriver(object): - __metaclass__ = abc.ABCMeta @property def service_type(self):