fix some pylint warnings.
1. Parent class should have instance variables used in its method(s). 2. remove some unused imports Patch 2: fix according to comments Patch 4: fix problem under pep8 1.1 Change-Id: Iafd89a6017b30484fb8da50219be6b4ae073f083
This commit is contained in:
parent
686982198c
commit
d2a21ec921
@ -40,6 +40,7 @@ class APIRouter(wsgi.Router):
|
|||||||
"""
|
"""
|
||||||
Base class for Quantum API routes.
|
Base class for Quantum API routes.
|
||||||
"""
|
"""
|
||||||
|
_version = None
|
||||||
|
|
||||||
def __init__(self, options=None):
|
def __init__(self, options=None):
|
||||||
mapper = self._mapper()
|
mapper = self._mapper()
|
||||||
|
@ -165,6 +165,8 @@ class HeaderSerializer11(HeaderSerializer10):
|
|||||||
|
|
||||||
class QuantumController(object):
|
class QuantumController(object):
|
||||||
""" Base controller class for Quantum API """
|
""" Base controller class for Quantum API """
|
||||||
|
# _resource_name will be redefined in sub concrete controller
|
||||||
|
_resource_name = None
|
||||||
|
|
||||||
def __init__(self, plugin):
|
def __init__(self, plugin):
|
||||||
self._plugin = plugin
|
self._plugin = plugin
|
||||||
|
@ -37,7 +37,9 @@ def create_resource(plugin, version):
|
|||||||
|
|
||||||
class Controller(common.QuantumController):
|
class Controller(common.QuantumController):
|
||||||
""" Port API controller for Quantum API """
|
""" Port API controller for Quantum API """
|
||||||
|
_resource_name = 'attachment'
|
||||||
|
# version will be redefined by in child class
|
||||||
|
version = None
|
||||||
_attachment_ops_param_list = [
|
_attachment_ops_param_list = [
|
||||||
{
|
{
|
||||||
'param-name': 'id',
|
'param-name': 'id',
|
||||||
@ -53,10 +55,6 @@ class Controller(common.QuantumController):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, plugin):
|
|
||||||
self._resource_name = 'attachment'
|
|
||||||
super(Controller, self).__init__(plugin)
|
|
||||||
|
|
||||||
@common.APIFaultWrapper([exception.NetworkNotFound,
|
@common.APIFaultWrapper([exception.NetworkNotFound,
|
||||||
exception.PortNotFound])
|
exception.PortNotFound])
|
||||||
def get_resource(self, request, tenant_id, network_id, id):
|
def get_resource(self, request, tenant_id, network_id, id):
|
||||||
@ -83,15 +81,9 @@ class Controller(common.QuantumController):
|
|||||||
|
|
||||||
class ControllerV10(Controller):
|
class ControllerV10(Controller):
|
||||||
"""Attachment resources controller for Quantum v1.0 API"""
|
"""Attachment resources controller for Quantum v1.0 API"""
|
||||||
|
version = "1.0"
|
||||||
def __init__(self, plugin):
|
|
||||||
self.version = "1.0"
|
|
||||||
super(ControllerV10, self).__init__(plugin)
|
|
||||||
|
|
||||||
|
|
||||||
class ControllerV11(Controller):
|
class ControllerV11(Controller):
|
||||||
"""Attachment resources controller for Quantum v1.1 API"""
|
"""Attachment resources controller for Quantum v1.1 API"""
|
||||||
|
version = "1.1"
|
||||||
def __init__(self, plugin):
|
|
||||||
self.version = "1.1"
|
|
||||||
super(ControllerV11, self).__init__(plugin)
|
|
||||||
|
@ -15,10 +15,8 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from webob import exc
|
|
||||||
|
|
||||||
from quantum.api import api_common as common
|
from quantum.api import api_common as common
|
||||||
from quantum.api import faults
|
|
||||||
from quantum.api.views import filters
|
from quantum.api.views import filters
|
||||||
from quantum.api.views import networks as networks_view
|
from quantum.api.views import networks as networks_view
|
||||||
from quantum.common import exceptions as exception
|
from quantum.common import exceptions as exception
|
||||||
@ -41,15 +39,13 @@ def create_resource(plugin, version):
|
|||||||
|
|
||||||
class Controller(common.QuantumController):
|
class Controller(common.QuantumController):
|
||||||
""" Network API controller for Quantum API """
|
""" Network API controller for Quantum API """
|
||||||
|
_resource_name = 'network'
|
||||||
|
# version will be redefined in child class
|
||||||
|
version = None
|
||||||
_network_ops_param_list = [
|
_network_ops_param_list = [
|
||||||
{'param-name': 'name', 'required': True},
|
{'param-name': 'name', 'required': True},
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, plugin):
|
|
||||||
self._resource_name = 'network'
|
|
||||||
super(Controller, self).__init__(plugin)
|
|
||||||
|
|
||||||
def _item(self, request, tenant_id, network_id,
|
def _item(self, request, tenant_id, network_id,
|
||||||
net_details=True, port_details=False):
|
net_details=True, port_details=False):
|
||||||
# We expect get_network_details to return information
|
# We expect get_network_details to return information
|
||||||
@ -165,9 +161,7 @@ class ControllerV10(Controller):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, plugin):
|
version = "1.0"
|
||||||
self.version = "1.0"
|
|
||||||
super(ControllerV10, self).__init__(plugin)
|
|
||||||
|
|
||||||
|
|
||||||
class ControllerV11(Controller):
|
class ControllerV11(Controller):
|
||||||
@ -191,6 +185,4 @@ class ControllerV11(Controller):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, plugin):
|
version = "1.1"
|
||||||
self.version = "1.1"
|
|
||||||
super(ControllerV11, self).__init__(plugin)
|
|
||||||
|
@ -38,15 +38,13 @@ def create_resource(plugin, version):
|
|||||||
|
|
||||||
class Controller(common.QuantumController):
|
class Controller(common.QuantumController):
|
||||||
""" Port API controller for Quantum API """
|
""" Port API controller for Quantum API """
|
||||||
|
_resource_name = 'port'
|
||||||
|
# version will be redefined in child class
|
||||||
|
version = None
|
||||||
_port_ops_param_list = [
|
_port_ops_param_list = [
|
||||||
{'param-name': 'state', 'default-value': 'DOWN', 'required': False},
|
{'param-name': 'state', 'default-value': 'DOWN', 'required': False},
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, plugin):
|
|
||||||
self._resource_name = 'port'
|
|
||||||
super(Controller, self).__init__(plugin)
|
|
||||||
|
|
||||||
def _items(self, request, tenant_id, network_id,
|
def _items(self, request, tenant_id, network_id,
|
||||||
port_details=False):
|
port_details=False):
|
||||||
""" Returns a list of ports.
|
""" Returns a list of ports.
|
||||||
@ -168,9 +166,7 @@ class ControllerV10(Controller):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, plugin):
|
version = "1.0"
|
||||||
self.version = "1.0"
|
|
||||||
super(ControllerV10, self).__init__(plugin)
|
|
||||||
|
|
||||||
|
|
||||||
class ControllerV11(Controller):
|
class ControllerV11(Controller):
|
||||||
@ -186,6 +182,4 @@ class ControllerV11(Controller):
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, plugin):
|
version = "1.1"
|
||||||
self.version = "1.1"
|
|
||||||
super(ControllerV11, self).__init__(plugin)
|
|
||||||
|
@ -25,7 +25,11 @@ from quantum.api.views import versions as versions_view
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Versions(wsgi.Application):
|
class Versions(object):
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def factory(cls, global_config, **local_config):
|
||||||
|
return cls()
|
||||||
|
|
||||||
@webob.dec.wsgify(RequestClass=wsgi.Request)
|
@webob.dec.wsgify(RequestClass=wsgi.Request)
|
||||||
def __call__(self, req):
|
def __call__(self, req):
|
||||||
@ -37,7 +41,7 @@ class Versions(wsgi.Application):
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "v1.1",
|
"id": "v1.1",
|
||||||
"status": "PROPOSED",
|
"status": "CURRENT",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -21,23 +21,15 @@
|
|||||||
"""Utilities and helper functions."""
|
"""Utilities and helper functions."""
|
||||||
|
|
||||||
|
|
||||||
import base64
|
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import datetime
|
import datetime
|
||||||
import functools
|
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import re
|
|
||||||
import socket
|
|
||||||
import string
|
|
||||||
import struct
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
|
||||||
import types
|
|
||||||
|
|
||||||
from quantum.common import exceptions as exception
|
from quantum.common import exceptions as exception
|
||||||
from quantum.common.exceptions import ProcessExecutionError
|
from quantum.common.exceptions import ProcessExecutionError
|
||||||
|
@ -364,7 +364,7 @@ class ExtensionManager(object):
|
|||||||
resources = []
|
resources = []
|
||||||
resources.append(ResourceExtension('extensions',
|
resources.append(ResourceExtension('extensions',
|
||||||
ExtensionController(self)))
|
ExtensionController(self)))
|
||||||
for alias, ext in self.extensions.iteritems():
|
for ext in self.extensions.itervalues():
|
||||||
try:
|
try:
|
||||||
resources.extend(ext.get_resources())
|
resources.extend(ext.get_resources())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@ -376,7 +376,7 @@ class ExtensionManager(object):
|
|||||||
def get_actions(self):
|
def get_actions(self):
|
||||||
"""Returns a list of ActionExtension objects."""
|
"""Returns a list of ActionExtension objects."""
|
||||||
actions = []
|
actions = []
|
||||||
for alias, ext in self.extensions.iteritems():
|
for ext in self.extensions.itervalues():
|
||||||
try:
|
try:
|
||||||
actions.extend(ext.get_actions())
|
actions.extend(ext.get_actions())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
@ -388,7 +388,7 @@ class ExtensionManager(object):
|
|||||||
def get_request_extensions(self):
|
def get_request_extensions(self):
|
||||||
"""Returns a list of RequestExtension objects."""
|
"""Returns a list of RequestExtension objects."""
|
||||||
request_exts = []
|
request_exts = []
|
||||||
for alias, ext in self.extensions.iteritems():
|
for ext in self.extensions.itervalues():
|
||||||
try:
|
try:
|
||||||
request_exts.extend(ext.get_request_extensions())
|
request_exts.extend(ext.get_request_extensions())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -97,7 +97,7 @@ def network_list(tenant_id):
|
|||||||
def network_id(net_name):
|
def network_id(net_name):
|
||||||
session = get_session()
|
session = get_session()
|
||||||
try:
|
try:
|
||||||
return session.query(models.Network).\
|
return session.query(models.Network).\
|
||||||
options(joinedload(models.Network.ports)). \
|
options(joinedload(models.Network.ports)). \
|
||||||
filter_by(name=net_name).\
|
filter_by(name=net_name).\
|
||||||
all()
|
all()
|
||||||
@ -108,7 +108,7 @@ def network_id(net_name):
|
|||||||
def network_get(net_id):
|
def network_get(net_id):
|
||||||
session = get_session()
|
session = get_session()
|
||||||
try:
|
try:
|
||||||
return session.query(models.Network).\
|
return session.query(models.Network).\
|
||||||
options(joinedload(models.Network.ports)). \
|
options(joinedload(models.Network.ports)). \
|
||||||
filter_by(uuid=net_id).\
|
filter_by(uuid=net_id).\
|
||||||
one()
|
one()
|
||||||
@ -142,7 +142,7 @@ def network_destroy(net_id):
|
|||||||
def validate_network_ownership(tenant_id, net_id):
|
def validate_network_ownership(tenant_id, net_id):
|
||||||
session = get_session()
|
session = get_session()
|
||||||
try:
|
try:
|
||||||
return session.query(models.Network).\
|
return session.query(models.Network).\
|
||||||
filter_by(uuid=net_id).\
|
filter_by(uuid=net_id).\
|
||||||
filter_by(tenant_id=tenant_id).\
|
filter_by(tenant_id=tenant_id).\
|
||||||
one()
|
one()
|
||||||
@ -176,7 +176,7 @@ def port_get(net_id, port_id):
|
|||||||
network_get(net_id)
|
network_get(net_id)
|
||||||
session = get_session()
|
session = get_session()
|
||||||
try:
|
try:
|
||||||
return session.query(models.Port).\
|
return session.query(models.Port).\
|
||||||
filter_by(uuid=port_id).\
|
filter_by(uuid=port_id).\
|
||||||
filter_by(network_id=net_id).\
|
filter_by(network_id=net_id).\
|
||||||
one()
|
one()
|
||||||
@ -266,7 +266,7 @@ def port_destroy(net_id, port_id):
|
|||||||
def port_get_by_id(port_id):
|
def port_get_by_id(port_id):
|
||||||
session = get_session()
|
session = get_session()
|
||||||
try:
|
try:
|
||||||
return session.query(models.Port).\
|
return session.query(models.Port).\
|
||||||
filter_by(uuid=port_id).one()
|
filter_by(uuid=port_id).one()
|
||||||
except exc.NoResultFound:
|
except exc.NoResultFound:
|
||||||
raise q_exc.PortNotFound(port_id=port_id)
|
raise q_exc.PortNotFound(port_id=port_id)
|
||||||
|
@ -80,7 +80,9 @@ class QuantumApiService(WsgiService):
|
|||||||
items = dict([(k, v) for k, v in conf.items()
|
items = dict([(k, v) for k, v in conf.items()
|
||||||
if k not in ('__file__', 'here')])
|
if k not in ('__file__', 'here')])
|
||||||
for key, value in sorted(items.items()):
|
for key, value in sorted(items.items()):
|
||||||
LOG.debug("%(key)-30s %(value)s" % locals())
|
LOG.debug("%(key)-30s %(value)s" % {'key': key,
|
||||||
|
'value': value,
|
||||||
|
})
|
||||||
LOG.debug("*" * 80)
|
LOG.debug("*" * 80)
|
||||||
service = cls(app_name, conf_file, conf)
|
service = cls(app_name, conf_file, conf)
|
||||||
return service
|
return service
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from quantum.extensions import extensions
|
from quantum.extensions import extensions
|
||||||
@ -66,10 +66,10 @@ class Foxinsocks(object):
|
|||||||
return resources
|
return resources
|
||||||
|
|
||||||
def get_actions(self):
|
def get_actions(self):
|
||||||
return [extensions.ActionExtension('dummy_resources',
|
return [extensions.ActionExtension('dummy_resources',
|
||||||
'FOXNSOX:add_tweedle',
|
'FOXNSOX:add_tweedle',
|
||||||
self._add_tweedle_handler),
|
self._add_tweedle_handler),
|
||||||
extensions.ActionExtension('dummy_resources',
|
extensions.ActionExtension('dummy_resources',
|
||||||
'FOXNSOX:delete_tweedle',
|
'FOXNSOX:delete_tweedle',
|
||||||
self._delete_tweedle_handler)]
|
self._delete_tweedle_handler)]
|
||||||
|
|
||||||
|
@ -15,8 +15,6 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import routes
|
import routes
|
||||||
@ -39,7 +37,6 @@ from quantum.tests.unit.extension_stubs import (
|
|||||||
StubBaseAppController,
|
StubBaseAppController,
|
||||||
StubExtension,
|
StubExtension,
|
||||||
StubPlugin,
|
StubPlugin,
|
||||||
StubPluginInterface,
|
|
||||||
)
|
)
|
||||||
import quantum.tests.unit.extensions
|
import quantum.tests.unit.extensions
|
||||||
from quantum import wsgi
|
from quantum import wsgi
|
||||||
|
@ -310,7 +310,7 @@ class ResponseSerializer(object):
|
|||||||
self.body_serializers.update(body_serializers or {})
|
self.body_serializers.update(body_serializers or {})
|
||||||
|
|
||||||
self.headers_serializer = (headers_serializer or
|
self.headers_serializer = (headers_serializer or
|
||||||
ResponseHeadersSerializer())
|
ResponseHeaderSerializer())
|
||||||
|
|
||||||
def serialize(self, response_data, content_type, action='default'):
|
def serialize(self, response_data, content_type, action='default'):
|
||||||
"""Serialize a dict into a string and wrap in a wsgi.Request object.
|
"""Serialize a dict into a string and wrap in a wsgi.Request object.
|
||||||
|
Loading…
Reference in New Issue
Block a user