]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
pep8 fixes (1st batch)
authorSalvatore Orlando <salvatore.orlando@eu.citrix.com>
Tue, 31 May 2011 17:15:00 +0000 (18:15 +0100)
committerSalvatore Orlando <salvatore.orlando@eu.citrix.com>
Tue, 31 May 2011 17:15:00 +0000 (18:15 +0100)
quantum/api/__init__.py
quantum/api/api_common.py
quantum/api/faults.py
quantum/api/networks.py
quantum/api/versions.py
quantum/cli.py
quantum/manager.py
quantum/quantum_plugin_base.py
quantum/service.py
quantum/utils.py

index 0b459e1772f124865b28a0cbdb994d533edc47cf..25b66f55730140495a9ee157fa5d9fe25e1231bb 100644 (file)
@@ -48,31 +48,30 @@ class APIRouterV01(wsgi.Router):
     def _setup_routes(self, mapper):
 
         uri_prefix = '/tenants/{tenant_id}/'
-        mapper.resource('network', 
-                        'networks',
+        mapper.resource('network', 'networks',
                         controller=networks.Controller(),
                         path_prefix=uri_prefix)
-        mapper.resource("port", "ports", controller=ports.Controller(),
+        mapper.resource('port', 'ports', 
+                        controller=ports.Controller(),
                         parent_resource=dict(member_name='network',
-                                             collection_name= uri_prefix + 'networks'))
+                                             collection_name=\
+                                             uri_prefix + 'networks'))
 
         mapper.connect("get_resource",
-                       uri_prefix + 'networks/{network_id}/ports/{id}/attachment{.format}',
+                       uri_prefix + 'networks/{network_id}/' \
+                                    'ports/{id}/attachment{.format}',
                        controller=ports.Controller(),
                        action="get_resource",
                        conditions=dict(method=['GET']))
         mapper.connect("attach_resource",
-                       uri_prefix + 'networks/{network_id}/ports/{id}/attachment{.format}',
+                       uri_prefix + 'networks/{network_id}/' \
+                                    'ports/{id}/attachment{.format}',
                        controller=ports.Controller(),
                        action="attach_resource",
                        conditions=dict(method=['PUT']))
         mapper.connect("detach_resource",
-                       uri_prefix + 'networks/{network_id}/ports/{id}/attachment{.format}',
+                       uri_prefix + 'networks/{network_id}/' \
+                                    'ports/{id}/attachment{.format}',
                        controller=ports.Controller(),
                        action="detach_resource",
                        conditions=dict(method=['DELETE']))
-
-        print "AFTER MAPPING"
-        print mapper
-        for route in mapper.matchlist:
-            print "Found route:%s %s" %(route.defaults,route.conditions)            
index 90de5092191c82d75ebd4f6171601c7ddb630e57..df8608df3b3158102fe12130646af55ad43d9d8b 100644 (file)
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
-import logging 
+import logging
 
 from webob import exc
 
 from quantum import manager
-from quantum.common import wsgi 
+from quantum.common import wsgi
 
 XML_NS_V01 = 'http://netstack.org/quantum/api/v0.1'
 XML_NS_V10 = 'http://netstack.org/quantum/api/v1.0'
 LOG = logging.getLogger('quantum.api.api_common')
 
+
 class QuantumController(wsgi.Controller):
     """ Base controller class for Quantum API """
 
@@ -40,7 +41,8 @@ class QuantumController(wsgi.Controller):
             param_value = None
             # 1- parse request body
             if req.body:
-                des_body = self._deserialize(req.body, req.best_match_content_type())
+                des_body = self._deserialize(req.body,
+                                             req.best_match_content_type())
                 data = des_body and des_body.get(self._resource_name, None)
                 param_value = data and data.get(param_name, None)
             if not param_value:
@@ -52,17 +54,17 @@ class QuantumController(wsgi.Controller):
                     try:
                         param_value = req.str_GET[param_name]
                     except KeyError:
-                        #param not found 
+                        #param not found
                         pass
-                if not param_value and param['required']: 
+                if not param_value and param['required']:
                     msg = ("Failed to parse request. " +
-                           "Parameter: %(param_name)s not specified" % locals())
+                           "Parameter: %(param_name)s " +
+                           "not specified" % locals())
                     for line in msg.split('\n'):
                         LOG.error(line)
                     raise exc.HTTPBadRequest(msg)
-            results[param_name]=param_value or param.get('default-value')
-        return results             
-        
-    def _setup_network_manager(self):
-        self.network_manager=manager.QuantumManager().get_manager()
+            results[param_name] = param_value or param.get('default-value')
+        return results
 
+    def _setup_network_manager(self):
+        self.network_manager = manager.QuantumManager().get_manager()
index 03a33c4b3c64b4ad0c5c38aff015176d13f67b54..a10364df19a90e3fe0c2fb6d9f6f6fa88c012c39 100644 (file)
@@ -22,6 +22,7 @@ import webob.exc
 from quantum.api import api_common as common
 from quantum.common import wsgi
 
+
 class Fault(webob.exc.HTTPException):
     """Error codes for API faults"""
 
@@ -29,7 +30,7 @@ class Fault(webob.exc.HTTPException):
             400: "malformedRequest",
             401: "unauthorized",
             420: "networkNotFound",
-            421: "networkInUse",            
+            421: "networkInUse",
             430: "portNotFound",
             431: "requestedStateInvalid",
             432: "portInUse",
@@ -61,20 +62,21 @@ class Fault(webob.exc.HTTPException):
         self.wrapped_exc.body = serializer.serialize(fault_data, content_type)
         self.wrapped_exc.content_type = content_type
         return self.wrapped_exc
-    
+
+
 class NetworkNotFound(webob.exc.HTTPClientError):
     """
     subclass of :class:`~HTTPClientError`
 
     This indicates that the server did not find the network specified
     in the HTTP request
-    
+
     code: 420, title: Network not Found
     """
     code = 420
     title = 'Network not Found'
     explanation = ('Unable to find a network with the specified identifier.')
-    
+
 
 class NetworkInUse(webob.exc.HTTPClientError):
     """
@@ -82,7 +84,7 @@ class NetworkInUse(webob.exc.HTTPClientError):
 
     This indicates that the server could not delete the network as there is
     at least an attachment plugged into its ports
-    
+
     code: 421, title: Network In Use
     """
     code = 421
@@ -96,27 +98,27 @@ class PortNotFound(webob.exc.HTTPClientError):
 
     This indicates that the server did not find the port specified
     in the HTTP request for a given network
-    
+
     code: 430, title: Port not Found
     """
     code = 430
     title = 'Port not Found'
     explanation = ('Unable to find a port with the specified identifier.')
-    
+
 
 class RequestedStateInvalid(webob.exc.HTTPClientError):
     """
     subclass of :class:`~HTTPClientError`
 
-    This indicates that the server could not update the port state to 
+    This indicates that the server could not update the port state to
     to the request value
-    
+
     code: 431, title: Requested State Invalid
     """
     code = 431
     title = 'Requested State Invalid'
     explanation = ('Unable to update port state with specified value.')
-    
+
 
 class PortInUse(webob.exc.HTTPClientError):
     """
@@ -124,20 +126,21 @@ class PortInUse(webob.exc.HTTPClientError):
 
     This indicates that the server could not remove o port or attach
     a resource to it because there is an attachment plugged into the port
-    
+
     code: 432, title: PortInUse
     """
     code = 432
     title = 'Port in Use'
     explanation = ('A resource is currently attached to the logical port')
 
+
 class AlreadyAttached(webob.exc.HTTPClientError):
     """
     subclass of :class:`~HTTPClientError`
 
     This indicates that the server refused an attempt to re-attach a resource
     already attached to the network
-    
+
     code: 440, title: AlreadyAttached
     """
     code = 440
index cccd48cf1015cb9841d99fb38be145ca29cd3b0e..98dd5e305d40c23e76394f76ff932aea53961d6c 100644 (file)
@@ -29,13 +29,13 @@ class Controller(common.QuantumController):
     """ Network API controller for Quantum API """
 
     _network_ops_param_list = [{
-        'param-name': 'network-name', 
-        'required': True},]
-    
+        'param-name': 'network-name',
+        'required': True}, ]
+
     _serialization_metadata = {
         "application/xml": {
             "attributes": {
-                "network": ["id","name"],
+                "network": ["id", "name"],
             },
         },
     }
@@ -56,12 +56,12 @@ class Controller(common.QuantumController):
         result = [builder.build(network, is_detail)['network']
                   for network in networks]
         return dict(networks=result)
-    
+
     def show(self, req, tenant_id, id):
         """ Returns network details for the given network id """
         try:
             network = self.network_manager.get_network_details(
-                            tenant_id,id)
+                            tenant_id, id)
             builder = networks_view.get_view_builder(req)
             #build response with details
             result = builder.build(network, True)
@@ -77,7 +77,8 @@ class Controller(common.QuantumController):
                 self._parse_request_params(req, self._network_ops_param_list)
         except exc.HTTPError as e:
             return faults.Fault(e)
-        network = self.network_manager.create_network(tenant_id, req_params['network-name'])
+        network = self.network_manager.\
+                       create_network(tenant_id,req_params['network-name'])
         builder = networks_view.get_view_builder(req)
         result = builder.build(network)
         return dict(networks=result)
@@ -89,15 +90,15 @@ class Controller(common.QuantumController):
                 self._parse_request_params(req, self._network_ops_param_list)
         except exc.HTTPError as e:
             return faults.Fault(e)
-        try: 
+        try:
             network = self.network_manager.rename_network(tenant_id,
-                        id,req_params['network-name'])
+                        id, req_params['network-name'])
 
             builder = networks_view.get_view_builder(req)
             result = builder.build(network, True)
             return dict(networks=result)
         except exception.NetworkNotFound as e:
-            return faults.Fault(faults.NetworkNotFound(e))    
+            return faults.Fault(faults.NetworkNotFound(e))
 
     def delete(self, req, tenant_id, id):
         """ Destroys the network with the given id """
@@ -105,6 +106,6 @@ class Controller(common.QuantumController):
             self.network_manager.delete_network(tenant_id, id)
             return exc.HTTPAccepted()
         except exception.NetworkNotFound as e:
-            return faults.Fault(faults.NetworkNotFound(e))            
+            return faults.Fault(faults.NetworkNotFound(e))
         except exception.NetworkInUse as e:
-            return faults.Fault(faults.NetworkInUse(e))            
+            return faults.Fault(faults.NetworkInUse(e))
index 36cd274d1f5fbc4324d9b188d87c0734f94596ca..18635040a06a8673285b7dbf304c2b78147f5b35 100644 (file)
@@ -23,6 +23,7 @@ from quantum.api.views import versions as versions_view
 
 LOG = logging.getLogger('quantum.api.versions')
 
+
 class Versions(wsgi.Application):
 
     @webob.dec.wsgify(RequestClass=wsgi.Request)
@@ -42,7 +43,6 @@ class Versions(wsgi.Application):
         builder = versions_view.get_view_builder(req)
         versions = [builder.build(version) for version in version_objs]
         response = dict(versions=versions)
-        LOG.debug("response:%s",response)
         metadata = {
             "application/xml": {
                 "attributes": {
@@ -51,12 +51,13 @@ class Versions(wsgi.Application):
                 }
             }
         }
-        
+
         content_type = req.best_match_content_type()
-        body = wsgi.Serializer(metadata=metadata).serialize(response, content_type)
+        body = wsgi.Serializer(metadata=metadata). \
+                    serialize(response, content_type)
 
         response = webob.Response()
         response.content_type = content_type
         response.body = body
 
-        return response
\ No newline at end of file
+        return response
index 0614f95f2917b6883c269c22e1642b9e0b2ba02b..78f1a6b4811719ddcdbcbec6c3cebb5b283c5aa0 100644 (file)
@@ -20,37 +20,37 @@ import sys
 from manager import QuantumManager
 
 
-def usage(): 
-    print "\nUsage:" 
-    print "list_nets <tenant-id>" 
+def usage():
+    print "\nUsage:"
+    print "list_nets <tenant-id>"
     print "create_net <tenant-id> <net-name>"
-    print "delete_net <tenant-id> <net-id>" 
+    print "delete_net <tenant-id> <net-id>"
     print "detail_net <tenant-id> <net-id>"
     print "rename_net <tenant-id> <net-id> <new name>"
     print "list_ports <tenant-id> <net-id>"
     print "create_port <tenant-id> <net-id>"
     print "delete_port <tenant-id> <net-id> <port-id>"
-    print "detail_port <tenant-id> <net-id> <port-id>"  
+    print "detail_port <tenant-id> <net-id> <port-id>"
     print "plug_iface <tenant-id> <net-id> <port-id> <iface-id>"
     print "unplug_iface <tenant-id> <net-id> <port-id>"
     print "detail_iface <tenant-id> <net-id> <port-id>"
     print "list_iface <tenant-id> <net-id>\n"
 
 if len(sys.argv) < 2 or len(sys.argv) > 6: 
-    usage() 
-    exit(1) 
-    
+    usage()
+    exit(1)
+
 quantum = QuantumManager()
 manager = quantum.get_manager()
 
-if sys.argv[1] == "list_nets" and len(sys.argv) == 3: 
+if sys.argv[1] == "list_nets" and len(sys.argv) == 3:
     network_on_tenant = manager.get_all_networks(sys.argv[2])
     print "Virtual Networks on Tenant:%s\n" % sys.argv[2]
     for k, v in network_on_tenant.iteritems():
         print"\tNetwork ID:%s \n\tNetwork Name:%s \n" % (k, v)
 elif sys.argv[1] == "create_net" and len(sys.argv) == 4:
     new_net_id = manager.create_network(sys.argv[2], sys.argv[3])
-    print "Created a new Virtual Network with ID:%s\n" % new_net_id 
+    print "Created a new Virtual Network with ID:%s\n" % new_net_id
 elif sys.argv[1] == "delete_net" and len(sys.argv) == 4:
     manager.delete_network(sys.argv[2], sys.argv[3])
     print "Deleted Virtual Network with ID:%s" % sys.argv[3]
@@ -58,7 +58,7 @@ elif sys.argv[1] == "detail_net" and len(sys.argv) == 4:
     vif_list = manager.get_network_details(sys.argv[2], sys.argv[3])
     print "Remote Interfaces on Virtual Network:%s\n" % sys.argv[3]
     for iface in vif_list:
-        print "\tRemote interface :%s" % iface 
+        print "\tRemote interface :%s" % iface
 elif sys.argv[1] == "rename_net" and len(sys.argv) == 5:
     manager.rename_network(sys.argv[2], sys.argv[3], sys.argv[4])
     print "Renamed Virtual Network with ID:%s" % sys.argv[3]
@@ -66,33 +66,45 @@ elif sys.argv[1] == "list_ports" and len(sys.argv) == 4:
     ports = manager.get_all_ports(sys.argv[2], sys.argv[3])
     print " Virtual Ports on Virtual Network:%s\n" % sys.argv[3]
     for port in ports:
-        print "\tVirtual Port:%s" % port   
+        print "\tVirtual Port:%s" % port
 elif sys.argv[1] == "create_port" and len(sys.argv) == 4:
     new_port = manager.create_port(sys.argv[2], sys.argv[3])
-    print "Created Virtual Port:%s on Virtual Network:%s" % (new_port, sys.argv[3]) 
+    print "Created Virtual Port:%s " \
+          "on Virtual Network:%s" % (new_port, sys.argv[3])
 elif sys.argv[1] == "delete_port" and len(sys.argv) == 5:
     manager.delete_port(sys.argv[2], sys.argv[3], sys.argv[4])
-    print "Deleted Virtual Port:%s on Virtual Network:%s" % (sys.argv[3], sys.argv[4])
+    print "Deleted Virtual Port:%s " \
+          "on Virtual Network:%s" % (sys.argv[3], sys.argv[4])
 elif sys.argv[1] == "detail_port" and len(sys.argv) == 5:
-    port_detail = manager.get_port_details(sys.argv[2], sys.argv[3], sys.argv[4])
-    print "Virtual Port:%s on Virtual Network:%s contains remote interface:%s" % (sys.argv[3], sys.argv[4], port_detail)
+    port_detail = manager.get_port_details(sys.argv[2],
+                                           sys.argv[3], sys.argv[4])
+    print "Virtual Port:%s on Virtual Network:%s " \
+          "contains remote interface:%s" % (sys.argv[3],
+                                            sys.argv[4],
+                                            port_detail)
 elif sys.argv[1] == "plug_iface" and len(sys.argv) == 6:
     manager.plug_interface(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
-    print "Plugged remote interface:%s into Virtual Network:%s" % (sys.argv[5], sys.argv[3])
+    print "Plugged remote interface:%s " \
+          "into Virtual Network:%s" % (sys.argv[5], sys.argv[3])
 elif sys.argv[1] == "unplug_iface" and len(sys.argv) == 5:
     manager.unplug_interface(sys.argv[2], sys.argv[3], sys.argv[4])
-    print "UnPlugged remote interface from Virtual Port:%s Virtual Network:%s" % (sys.argv[4], sys.argv[3])
+    print "UnPlugged remote interface " \
+          "from Virtual Port:%s Virtual Network:%s" % (sys.argv[4], 
+                                                       sys.argv[3])
 elif sys.argv[1] == "detail_iface" and len(sys.argv) == 5:
-    remote_iface = manager.get_interface_details(sys.argv[2], sys.argv[3], sys.argv[4])
-    print "Remote interface on Virtual Port:%s Virtual Network:%s is %s" % (sys.argv[4], sys.argv[3], remote_iface)
+    remote_iface = manager.get_interface_details(sys.argv[2], 
+                                                 sys.argv[3], sys.argv[4])
+    print "Remote interface on Virtual Port:%s " \
+          "Virtual Network:%s is %s" % (sys.argv[4], 
+                                        sys.argv[3], remote_iface)
 elif sys.argv[1] == "list_iface" and len(sys.argv) == 4:
     iface_list = manager.get_all_attached_interfaces(sys.argv[2], sys.argv[3])
     print "Remote Interfaces on Virtual Network:%s\n" % sys.argv[3]
     for iface in iface_list:
-        print "\tRemote interface :%s" % iface 
+        print "\tRemote interface :%s" % iface
 elif sys.argv[1] == "all" and len(sys.argv) == 2:
     print "Not Implemented"
-else: 
-    print "invalid arguments: %s" % str(sys.argv) 
+else:
+    print "invalid arguments: %s" % str(sys.argv)
     usage()
 
index 69e78561a8d3f51608de2eaaaac44c157f53fed9..dc3f39d754995b6e919c038a6ed38575f2014988 100644 (file)
@@ -25,29 +25,30 @@ The caller should make sure that QuantumManager is a singleton.
 """
 import gettext
 gettext.install('quantum', unicode=1)
-    
+
 from common import utils
 from quantum_plugin_base import QuantumPluginBase
 
 CONFIG_FILE = "quantum/plugins.ini"
 
+
 class QuantumManager(object):
-    
-   def __init__(self,config=CONFIG_FILE):
+
+    def __init__(self,config=CONFIG_FILE):
         self.configuration_file = CONFIG_FILE
         plugin_location = utils.getPluginFromConfig(CONFIG_FILE)
-        print "PLUGIN LOCATION:%s" %plugin_location 
+        print "PLUGIN LOCATION:%s" % plugin_location
         plugin_klass = utils.import_class(plugin_location)
         if not issubclass(plugin_klass, QuantumPluginBase):
-            raise Exception("Configured Quantum plug-in didn't pass compatibility test")
+            raise Exception("Configured Quantum plug-in " \
+                            "didn't pass compatibility test")
         else:
-            print("Successfully imported Quantum plug-in. All compatibility tests passed\n") 
+            print("Successfully imported Quantum plug-in." \
+                  "All compatibility tests passed\n")
         self.plugin = plugin_klass()
-        
-   def get_manager(self):
-       return self.plugin
-
 
+    def get_manager(self):
+        return self.plugin
 
 
 # TODO(somik): rmove the main class
@@ -61,4 +62,3 @@ def main():
 # Standard boilerplate to call the main() function.
 if __name__ == '__main__':
     main()
-
index d90cb5595423ced05395743b8cac69a14490dc4a..3d79d3a19f57d887bc78082de778f12d43ea4929 100644 (file)
@@ -88,11 +88,11 @@ class QuantumPluginBase(object):
     @abstractmethod
     def update_port(self, tenant_id, net_id, port_id, port_state):
         """
-        Updates the state of a specific port on the 
+        Updates the state of a specific port on the
         specified Virtual Network
         """
         pass
-    
+
     @abstractmethod
     def delete_port(self, tenant_id, net_id, port_id):
         """
@@ -142,13 +142,13 @@ class QuantumPluginBase(object):
         a particular Virtual Network.
         """
         pass
-   
+
     @classmethod
     def __subclasshook__(cls, klass):
         """
         The __subclasshook__ method is a class method
         that will be called everytime a class is tested
-        using issubclass(klass, Plugin). 
+        using issubclass(klass, Plugin).
         In that case, it will check that every method
         marked with the abstractmethod decorator is
         provided by the plugin class.
@@ -160,5 +160,3 @@ class QuantumPluginBase(object):
                 return NotImplemented
             return True
         return NotImplemented
-
-
index 760263bf935458cebdc33791c56df75cf0c8c365..193725ef3eee50d7da8299b7fd7ae571c08e4f7c 100644 (file)
 #    under the License.
 
 import logging
-import json
-import routes
 from quantum.common import config
 from quantum.common import wsgi
 from quantum.common import exceptions as exception
-from webob import Response
+
 
 LOG = logging.getLogger('quantum.service')
 
+
 class WsgiService(object):
     """Base class for WSGI based services.
 
@@ -60,21 +59,19 @@ class QuantumApiService(WsgiService):
                 message = (_('No paste configuration found for: %s'),
                            app_name)
                 raise exception.Error(message)
-        print "OPTIONS:%s" %options
-        print "CONF:%s" %conf
 
         # Setup logging early, supplying both the CLI options and the
         # configuration mapping from the config file
         # We only update the conf dict for the verbose and debug
         # flags. Everything else must be set up in the conf file...
         # Log the options used when starting if we're in debug mode...
-        
+
         config.setup_logging(options, conf)
         debug = options.get('debug') or \
-                config.get_option(conf, 'debug', 
+                config.get_option(conf, 'debug',
                                   type='bool', default=False)
         verbose = options.get('verbose') or \
-                config.get_option(conf, 'verbose', 
+                config.get_option(conf, 'verbose',
                                   type='bool', default=False)
         conf['debug'] = debug
         conf['verbose'] = verbose
@@ -91,7 +88,7 @@ class QuantumApiService(WsgiService):
         return service
 
 
-def serve_wsgi(cls, conf=None, options = None, args = None):
+def serve_wsgi(cls, conf=None, options = None, args=None):
     try:
         service = cls.create(conf, options, args)
     except Exception:
@@ -104,7 +101,6 @@ def serve_wsgi(cls, conf=None, options = None, args = None):
 
     
 def _run_wsgi(app_name, paste_conf, paste_config_file):
-    print "CICCIO"
     LOG.info(_('Using paste.deploy config at: %s'), paste_config_file)
     app = config.load_paste_app(paste_config_file, app_name)
     if not app:
@@ -112,7 +108,6 @@ def _run_wsgi(app_name, paste_conf, paste_config_file):
                       paste_config_file)
         return
     server = wsgi.Server()
-    server.start(app, 
-                 int(paste_conf['bind_port']),paste_conf['bind_host'])
+    server.start(app,
+                 int(paste_conf['bind_port']), paste_conf['bind_host'])
     return server
-    
index c14135d4701b31996bb7d3a6bdebf883b90cadc8..508debb35ba7a638845ac80a258acbe11fab5f5d 100644 (file)
@@ -58,6 +58,7 @@ def import_object(import_str):
         cls = import_class(import_str)
         return cls()
 
+
 def to_primitive(value):
     if type(value) is type([]) or type(value) is type((None,)):
         o = []
@@ -77,7 +78,8 @@ def to_primitive(value):
         return to_primitive(list(value))
     else:
         return value
-    
+
+
 def dumps(value):
     try:
         return json.dumps(value)