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
This commit is contained in:
fujioka yuuichi 2013-10-10 20:54:40 +09:00
parent bc18247313
commit 6096dd5892
27 changed files with 76 additions and 47 deletions

View File

@ -18,7 +18,10 @@
import abc import abc
import contextlib import contextlib
import six
@six.add_metaclass(abc.ABCMeta)
class FirewallDriver(object): class FirewallDriver(object):
"""Firewall Driver base class. """Firewall Driver base class.
@ -52,8 +55,6 @@ class FirewallDriver(object):
remote_group_id will also remaining membership update management remote_group_id will also remaining membership update management
""" """
__metaclass__ = abc.ABCMeta
def prepare_port_filter(self, port): def prepare_port_filter(self, port):
"""Prepare filters for the port. """Prepare filters for the port.

View File

@ -20,12 +20,13 @@
import abc import abc
from oslo.config import cfg from oslo.config import cfg
import six
from neutron.common import log from neutron.common import log
@six.add_metaclass(abc.ABCMeta)
class L2populationRpcCallBackMixin(object): class L2populationRpcCallBackMixin(object):
__metaclass__ = abc.ABCMeta
@log.log @log.log
def add_fdb_entries(self, context, fdb_entries, host=None): def add_fdb_entries(self, context, fdb_entries, host=None):

View File

@ -26,6 +26,7 @@ import uuid
import netaddr import netaddr
from oslo.config import cfg from oslo.config import cfg
import six
from neutron.agent.linux import ip_lib from neutron.agent.linux import ip_lib
from neutron.agent.linux import utils from neutron.agent.linux import utils
@ -101,8 +102,8 @@ class NetModel(DictModel):
return self._ns_name return self._ns_name
@six.add_metaclass(abc.ABCMeta)
class DhcpBase(object): class DhcpBase(object):
__metaclass__ = abc.ABCMeta
def __init__(self, conf, network, root_helper='sudo', def __init__(self, conf, network, root_helper='sudo',
version=None, plugin=None): version=None, plugin=None):

View File

@ -19,6 +19,7 @@ import abc
import netaddr import netaddr
from oslo.config import cfg from oslo.config import cfg
import six
from neutron.agent.common import config from neutron.agent.common import config
from neutron.agent.linux import ip_lib from neutron.agent.linux import ip_lib
@ -59,8 +60,8 @@ OPTS = [
] ]
@six.add_metaclass(abc.ABCMeta)
class LinuxInterfaceDriver(object): class LinuxInterfaceDriver(object):
__metaclass__ = abc.ABCMeta
# from linux IF_NAMESIZE # from linux IF_NAMESIZE
DEV_NAME_LEN = 14 DEV_NAME_LEN = 14

View File

@ -22,6 +22,7 @@ import os
from oslo.config import cfg from oslo.config import cfg
import routes import routes
import six
import webob.dec import webob.dec
import webob.exc import webob.exc
@ -36,8 +37,8 @@ from neutron import wsgi
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@six.add_metaclass(ABCMeta)
class PluginInterface(object): class PluginInterface(object):
__metaclass__ = ABCMeta
@classmethod @classmethod
def __subclasshook__(cls, klass): def __subclasshook__(cls, klass):

View File

@ -20,6 +20,7 @@
import abc import abc
from oslo.config import cfg from oslo.config import cfg
import six
from neutron.api import extensions from neutron.api import extensions
from neutron.api.v2 import attributes as attr from neutron.api.v2 import attributes as attr
@ -376,8 +377,8 @@ class Firewall(extensions.ExtensionDescriptor):
return {} return {}
@six.add_metaclass(abc.ABCMeta)
class FirewallPluginBase(ServicePluginBase): class FirewallPluginBase(ServicePluginBase):
__metaclass__ = abc.ABCMeta
def get_plugin_name(self): def get_plugin_name(self):
return constants.FIREWALL return constants.FIREWALL

View File

@ -18,6 +18,7 @@
import abc import abc
from oslo.config import cfg from oslo.config import cfg
import six
from neutron.api import extensions from neutron.api import extensions
from neutron.api.v2 import attributes as attr from neutron.api.v2 import attributes as attr
@ -376,8 +377,8 @@ class Loadbalancer(extensions.ExtensionDescriptor):
return {} return {}
@six.add_metaclass(abc.ABCMeta)
class LoadBalancerPluginBase(ServicePluginBase): class LoadBalancerPluginBase(ServicePluginBase):
__metaclass__ = abc.ABCMeta
def get_plugin_name(self): def get_plugin_name(self):
return constants.LOADBALANCER return constants.LOADBALANCER

View File

@ -16,6 +16,8 @@
import abc import abc
import six
from neutron.api import extensions from neutron.api import extensions
from neutron.api.v2 import attributes as attr from neutron.api.v2 import attributes as attr
from neutron.api.v2 import base from neutron.api.v2 import base
@ -147,8 +149,8 @@ class Metering(extensions.ExtensionDescriptor):
return {} return {}
@six.add_metaclass(abc.ABCMeta)
class MeteringPluginBase(service_base.ServicePluginBase): class MeteringPluginBase(service_base.ServicePluginBase):
__metaclass__ = abc.ABCMeta
def get_plugin_name(self): def get_plugin_name(self):
return constants.METERING return constants.METERING

View File

@ -19,6 +19,7 @@ from abc import ABCMeta
from abc import abstractmethod from abc import abstractmethod
from oslo.config import cfg from oslo.config import cfg
import six
from neutron.api import extensions from neutron.api import extensions
from neutron.api.v2 import attributes as attr from neutron.api.v2 import attributes as attr
@ -291,8 +292,8 @@ class Securitygroup(extensions.ExtensionDescriptor):
return {} return {}
@six.add_metaclass(ABCMeta)
class SecurityGroupPluginBase(object): class SecurityGroupPluginBase(object):
__metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def create_security_group(self, context, security_group): def create_security_group(self, context, security_group):

View File

@ -20,6 +20,7 @@
import abc import abc
from oslo.config import cfg from oslo.config import cfg
import six
from neutron.api import extensions from neutron.api import extensions
from neutron.api.v2 import attributes as attr from neutron.api.v2 import attributes as attr
@ -405,8 +406,8 @@ class Vpnaas(extensions.ExtensionDescriptor):
return {} return {}
@six.add_metaclass(abc.ABCMeta)
class VPNPluginBase(ServicePluginBase): class VPNPluginBase(ServicePluginBase):
__metaclass__ = abc.ABCMeta
def get_plugin_name(self): def get_plugin_name(self):
return constants.VPN return constants.VPN

View File

@ -23,11 +23,12 @@ methods that needs to be implemented by a v2 Neutron Plug-in.
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import six
@six.add_metaclass(ABCMeta)
class NeutronPluginBaseV2(object): class NeutronPluginBaseV2(object):
__metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def create_subnet(self, context, subnet): def create_subnet(self, context, subnet):
"""Create a subnet. """Create a subnet.

View File

@ -19,7 +19,10 @@
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import inspect import inspect
import six
@six.add_metaclass(ABCMeta)
class L2DevicePluginBase(object): class L2DevicePluginBase(object):
"""Base class for a device-specific plugin. """Base class for a device-specific plugin.
@ -28,8 +31,6 @@ class L2DevicePluginBase(object):
the configuration on each device. the configuration on each device.
""" """
__metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def get_all_networks(self, tenant_id, **kwargs): def get_all_networks(self, tenant_id, **kwargs):
"""Get newtorks. """Get newtorks.

View File

@ -19,7 +19,10 @@
import abc import abc
import six
@six.add_metaclass(abc.ABCMeta)
class SupportBase(object): class SupportBase(object):
"""abstract support class. """abstract support class.
@ -27,7 +30,6 @@ class SupportBase(object):
the L2 base for Embrane plugin. the L2 base for Embrane plugin.
""" """
__metaclass__ = abc.ABCMeta
@abc.abstractmethod @abc.abstractmethod
def __init__(self): def __init__(self):

View File

@ -15,6 +15,8 @@
from abc import ABCMeta, abstractmethod, abstractproperty from abc import ABCMeta, abstractmethod, abstractproperty
import six
# The following keys are used in the segment dictionaries passed via # The following keys are used in the segment dictionaries passed via
# the driver API. These are defined separately from similar keys in # the driver API. These are defined separately from similar keys in
# neutron.extensions.providernet so that drivers don't need to change # neutron.extensions.providernet so that drivers don't need to change
@ -26,6 +28,7 @@ PHYSICAL_NETWORK = 'physical_network'
SEGMENTATION_ID = 'segmentation_id' SEGMENTATION_ID = 'segmentation_id'
@six.add_metaclass(ABCMeta)
class TypeDriver(object): class TypeDriver(object):
"""Define stable abstract interface for ML2 type drivers. """Define stable abstract interface for ML2 type drivers.
@ -43,8 +46,6 @@ class TypeDriver(object):
either be excluded or stored as None. either be excluded or stored as None.
""" """
__metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def get_type(self): def get_type(self):
"""Get driver's network type. """Get driver's network type.
@ -128,6 +129,7 @@ class TypeDriver(object):
pass pass
@six.add_metaclass(ABCMeta)
class NetworkContext(object): class NetworkContext(object):
"""Context passed to MechanismDrivers for changes to network resources. """Context passed to MechanismDrivers for changes to network resources.
@ -137,8 +139,6 @@ class NetworkContext(object):
MechanismDrivers can freely access the same information. MechanismDrivers can freely access the same information.
""" """
__metaclass__ = ABCMeta
@abstractproperty @abstractproperty
def current(self): def current(self):
"""Return the current state of the network. """Return the current state of the network.
@ -165,6 +165,7 @@ class NetworkContext(object):
pass pass
@six.add_metaclass(ABCMeta)
class SubnetContext(object): class SubnetContext(object):
"""Context passed to MechanismDrivers for changes to subnet resources. """Context passed to MechanismDrivers for changes to subnet resources.
@ -174,8 +175,6 @@ class SubnetContext(object):
MechanismDrivers can freely access the same information. MechanismDrivers can freely access the same information.
""" """
__metaclass__ = ABCMeta
@abstractproperty @abstractproperty
def current(self): def current(self):
"""Return the current state of the subnet. """Return the current state of the subnet.
@ -197,6 +196,7 @@ class SubnetContext(object):
pass pass
@six.add_metaclass(ABCMeta)
class PortContext(object): class PortContext(object):
"""Context passed to MechanismDrivers for changes to port resources. """Context passed to MechanismDrivers for changes to port resources.
@ -206,8 +206,6 @@ class PortContext(object):
freely access the same information. freely access the same information.
""" """
__metaclass__ = ABCMeta
@abstractproperty @abstractproperty
def current(self): def current(self):
"""Return the current state of the port. """Return the current state of the port.
@ -262,6 +260,7 @@ class PortContext(object):
pass pass
@six.add_metaclass(ABCMeta)
class MechanismDriver(object): class MechanismDriver(object):
"""Define stable abstract interface for ML2 mechanism drivers. """Define stable abstract interface for ML2 mechanism drivers.
@ -283,8 +282,6 @@ class MechanismDriver(object):
methods that are part of the database transaction. methods that are part of the database transaction.
""" """
__metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def initialize(self): def initialize(self):
"""Perform driver initialization. """Perform driver initialization.

View File

@ -15,12 +15,15 @@
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import six
from neutron.openstack.common import log from neutron.openstack.common import log
from neutron.plugins.ml2 import driver_api as api from neutron.plugins.ml2 import driver_api as api
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@six.add_metaclass(ABCMeta)
class AgentMechanismDriverBase(api.MechanismDriver): class AgentMechanismDriverBase(api.MechanismDriver):
"""Base class for drivers that attach to networks using an L2 agent. """Base class for drivers that attach to networks using an L2 agent.
@ -35,8 +38,6 @@ class AgentMechanismDriverBase(api.MechanismDriver):
check_segment_for_agent(). check_segment_for_agent().
""" """
__metaclass__ = ABCMeta
def __init__(self, agent_type, vif_type, cap_port_filter): def __init__(self, agent_type, vif_type, cap_port_filter):
"""Initialize base class for specific L2 agent type. """Initialize base class for specific L2 agent type.

View File

@ -14,6 +14,8 @@
# under the License. # under the License.
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import six
from neutron.common import exceptions as exc from neutron.common import exceptions as exc
from neutron.common import topics from neutron.common import topics
from neutron.openstack.common import log from neutron.openstack.common import log
@ -24,6 +26,7 @@ LOG = log.getLogger(__name__)
TUNNEL = 'tunnel' TUNNEL = 'tunnel'
@six.add_metaclass(ABCMeta)
class TunnelTypeDriver(api.TypeDriver): class TunnelTypeDriver(api.TypeDriver):
"""Define stable abstract interface for ML2 type drivers. """Define stable abstract interface for ML2 type drivers.
@ -31,8 +34,6 @@ class TunnelTypeDriver(api.TypeDriver):
methods to manage these endpoints. methods to manage these endpoints.
""" """
__metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def add_endpoint(self, ip): def add_endpoint(self, ip):
"""Register the endpoint in the type_driver database. """Register the endpoint in the type_driver database.

View File

@ -18,7 +18,10 @@
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
import six
@six.add_metaclass(ABCMeta)
class OFCDriverBase(object): class OFCDriverBase(object):
"""OpenFlow Controller (OFC) Driver Specification. """OpenFlow Controller (OFC) Driver Specification.
@ -26,8 +29,6 @@ class OFCDriverBase(object):
It would be better that other methods like update_* are implemented. It would be better that other methods like update_* are implemented.
""" """
__metaclass__ = ABCMeta
@abstractmethod @abstractmethod
def create_tenant(self, description, tenant_id=None): def create_tenant(self, description, tenant_id=None):
"""Create a new tenant at OpenFlow Controller. """Create a new tenant at OpenFlow Controller.

View File

@ -19,6 +19,8 @@
import abc import abc
import httplib import httplib
import six
from neutron.common import log as call_log from neutron.common import log as call_log
from neutron.common import utils from neutron.common import utils
from neutron.openstack.common import excutils from neutron.openstack.common import excutils
@ -31,10 +33,9 @@ LOG = logging.getLogger(__name__)
PROVIDER_OPENFLOW = nconst.ROUTER_PROVIDER_OPENFLOW PROVIDER_OPENFLOW = nconst.ROUTER_PROVIDER_OPENFLOW
@six.add_metaclass(abc.ABCMeta)
class RouterDriverBase(object): class RouterDriverBase(object):
__metaclass__ = abc.ABCMeta
def __init__(self, plugin, ofc_manager): def __init__(self, plugin, ofc_manager):
self.plugin = plugin self.plugin = plugin
self.ofc = ofc_manager self.ofc = ofc_manager

View File

@ -24,6 +24,7 @@ import httplib
import logging import logging
import time import time
import six
from neutron.plugins.nicira.api_client.common import ( from neutron.plugins.nicira.api_client.common import (
_conn_str) _conn_str)
@ -37,6 +38,7 @@ DEFAULT_CONCURRENT_CONNECTIONS = 3
DEFAULT_CONNECT_TIMEOUT = 5 DEFAULT_CONNECT_TIMEOUT = 5
@six.add_metaclass(ABCMeta)
class NvpApiClient(object): class NvpApiClient(object):
'''An abstract baseclass for all NvpApiClient implementations. '''An abstract baseclass for all NvpApiClient implementations.
@ -44,8 +46,6 @@ class NvpApiClient(object):
coroutine-based classes. coroutine-based classes.
''' '''
__metaclass__ = ABCMeta
CONN_IDLE_TIMEOUT = 60 * 15 CONN_IDLE_TIMEOUT = 60 * 15
def _create_connection(self, host, port, is_ssl): def _create_connection(self, host, port, is_ssl):

View File

@ -26,6 +26,8 @@ import logging
import time import time
import urlparse import urlparse
import six
from neutron.openstack.common import excutils from neutron.openstack.common import excutils
from neutron.plugins.nicira.api_client.common import ( from neutron.plugins.nicira.api_client.common import (
_conn_str) _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 # for downloads, see: django/nvp_console/views.py
@six.add_metaclass(ABCMeta)
class NvpApiRequest(object): class NvpApiRequest(object):
'''An abstract baseclass for all ApiRequest implementations. '''An abstract baseclass for all ApiRequest implementations.
@ -52,8 +55,6 @@ class NvpApiRequest(object):
gevent-based ApiRequest classes. gevent-based ApiRequest classes.
''' '''
__metaclass__ = ABCMeta
# List of allowed status codes. # List of allowed status codes.
ALLOWED_STATUS_CODES = [ ALLOWED_STATUS_CODES = [
httplib.OK, httplib.OK,

View File

@ -19,7 +19,10 @@
import abc import abc
import six
@six.add_metaclass(abc.ABCMeta)
class FwaasDriverBase(object): class FwaasDriverBase(object):
"""Firewall as a Service Driver base class. """Firewall as a Service Driver base class.
@ -60,8 +63,6 @@ class FwaasDriverBase(object):
application of rules. application of rules.
""" """
__metaclass__ = abc.ABCMeta
@abc.abstractmethod @abc.abstractmethod
def create_firewall(self, apply_list, firewall): def create_firewall(self, apply_list, firewall):
"""Create the Firewall with default (drop all) policy. """Create the Firewall with default (drop all) policy.

View File

@ -18,7 +18,10 @@
import abc import abc
import six
@six.add_metaclass(abc.ABCMeta)
class LoadBalancerAbstractDriver(object): class LoadBalancerAbstractDriver(object):
"""Abstract lbaas driver that expose ~same API as lbaas plugin. """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 Get operations are not part of the API - it will be handled
by the lbaas plugin. by the lbaas plugin.
""" """
__metaclass__ = abc.ABCMeta
@abc.abstractmethod @abc.abstractmethod
def create_vip(self, context, vip): def create_vip(self, context, vip):

View File

@ -16,10 +16,12 @@
import abc import abc
import six
@six.add_metaclass(abc.ABCMeta)
class MeteringAbstractDriver(object): class MeteringAbstractDriver(object):
"""Abstract Metering driver.""" """Abstract Metering driver."""
__metaclass__ = abc.ABCMeta
def __init__(self, plugin, conf): def __init__(self, plugin, conf):
pass pass

View File

@ -17,6 +17,8 @@
import abc import abc
import six
from neutron.api import extensions from neutron.api import extensions
from neutron.db import servicetype_db as sdb from neutron.db import servicetype_db as sdb
from neutron.openstack.common import importutils from neutron.openstack.common import importutils
@ -26,9 +28,9 @@ from neutron.services import provider_configuration as pconf
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@six.add_metaclass(abc.ABCMeta)
class ServicePluginBase(extensions.PluginInterface): class ServicePluginBase(extensions.PluginInterface):
"""Define base interface for any Advanced Service plugin.""" """Define base interface for any Advanced Service plugin."""
__metaclass__ = abc.ABCMeta
supported_extension_aliases = [] supported_extension_aliases = []
@abc.abstractmethod @abc.abstractmethod

View File

@ -16,9 +16,11 @@
# under the License. # under the License.
import abc import abc
import six
@six.add_metaclass(abc.ABCMeta)
class DeviceDriver(object): class DeviceDriver(object):
__metaclass__ = abc.ABCMeta
def __init__(self, agent, host): def __init__(self, agent, host):
pass pass

View File

@ -23,6 +23,7 @@ import shutil
import jinja2 import jinja2
import netaddr import netaddr
from oslo.config import cfg from oslo.config import cfg
import six
from neutron.agent.linux import ip_lib from neutron.agent.linux import ip_lib
from neutron.agent.linux import utils from neutron.agent.linux import utils
@ -85,13 +86,13 @@ def _get_template(template_file):
return JINJA_ENV.get_template(template_file) return JINJA_ENV.get_template(template_file)
@six.add_metaclass(abc.ABCMeta)
class BaseSwanProcess(): class BaseSwanProcess():
"""Swan Family Process Manager """Swan Family Process Manager
This class manages start/restart/stop ipsec process. This class manages start/restart/stop ipsec process.
This class create/delete config template This class create/delete config template
""" """
__metaclass__ = abc.ABCMeta
binary = "ipsec" binary = "ipsec"
CONFIG_DIRS = [ CONFIG_DIRS = [
@ -465,6 +466,7 @@ class IPsecVpnDriverApi(proxy.RpcProxy):
topic=self.topic) topic=self.topic)
@six.add_metaclass(abc.ABCMeta)
class IPsecDriver(device_drivers.DeviceDriver): class IPsecDriver(device_drivers.DeviceDriver):
"""VPN Device Driver for IPSec. """VPN Device Driver for IPSec.
@ -478,7 +480,6 @@ class IPsecDriver(device_drivers.DeviceDriver):
# 1.0 Initial version # 1.0 Initial version
RPC_API_VERSION = '1.0' RPC_API_VERSION = '1.0'
__metaclass__ = abc.ABCMeta
def __init__(self, agent, host): def __init__(self, agent, host):
self.agent = agent self.agent = agent

View File

@ -17,9 +17,11 @@
import abc import abc
import six
@six.add_metaclass(abc.ABCMeta)
class VpnDriver(object): class VpnDriver(object):
__metaclass__ = abc.ABCMeta
@property @property
def service_type(self): def service_type(self):