From 51c20f6f85d76bc14f394221a8836d2aac9a1aea Mon Sep 17 00:00:00 2001 From: Jimmy Bergman Date: Wed, 22 Jun 2011 12:01:18 +0200 Subject: Add a socket server responding with an allowing flash socket policy for all requests from flash on port 843 to nova-vncproxy --- bin/nova-vncproxy | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/bin/nova-vncproxy b/bin/nova-vncproxy index ccb97e3a3..467d1eba3 100755 --- a/bin/nova-vncproxy +++ b/bin/nova-vncproxy @@ -39,6 +39,8 @@ from nova import wsgi from nova import version from nova.vnc import auth from nova.vnc import proxy +from twisted.internet import protocol, reactor +from twisted.protocols import basic LOG = logging.getLogger('nova.vnc-proxy') @@ -62,6 +64,16 @@ flags.DEFINE_flag(flags.HelpFlag()) flags.DEFINE_flag(flags.HelpshortFlag()) flags.DEFINE_flag(flags.HelpXMLFlag()) +class FlashSocketPolicyProtocol(basic.LineReceiver): + delimiter = "\0" + + def lineReceived(self, request): + if '' in request: + self.transport.write('' % (FLAGS.vncproxy_port)) + self.transport.loseConnection() + +class FlashSocketPolicyFactory(protocol.ServerFactory): + protocol = FlashSocketPolicyProtocol if __name__ == "__main__": utils.default_flagfile() @@ -96,6 +108,11 @@ if __name__ == "__main__": service.serve() - server = wsgi.Server() - server.start(with_auth, FLAGS.vncproxy_port, host=FLAGS.vncproxy_host) - server.wait() + flash_socket_policy_pid = os.fork() + if flash_socket_policy_pid == 0: + reactor.listenTCP(843, FlashSocketPolicyFactory()) + reactor.run() + else: + server = wsgi.Server() + server.start(with_auth, FLAGS.vncproxy_port, host=FLAGS.vncproxy_host) + server.wait() -- cgit From 3d1c8463d80932ddbe677ea1b8aee357642018a8 Mon Sep 17 00:00:00 2001 From: Jimmy Bergman Date: Thu, 23 Jun 2011 13:34:01 +0200 Subject: Change so that the flash socket policy server is using eventlet instead of twisted and is running in the same process as the main vnx proxy --- bin/nova-vncproxy | 32 +++++++++++++------------------- nova/wsgi.py | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/bin/nova-vncproxy b/bin/nova-vncproxy index 467d1eba3..60e01e7f8 100755 --- a/bin/nova-vncproxy +++ b/bin/nova-vncproxy @@ -39,8 +39,6 @@ from nova import wsgi from nova import version from nova.vnc import auth from nova.vnc import proxy -from twisted.internet import protocol, reactor -from twisted.protocols import basic LOG = logging.getLogger('nova.vnc-proxy') @@ -64,16 +62,16 @@ flags.DEFINE_flag(flags.HelpFlag()) flags.DEFINE_flag(flags.HelpshortFlag()) flags.DEFINE_flag(flags.HelpXMLFlag()) -class FlashSocketPolicyProtocol(basic.LineReceiver): - delimiter = "\0" +def handle_flash_socket_policy(socket): + LOG.info(_("Received connection on flash socket policy port")) - def lineReceived(self, request): - if '' in request: - self.transport.write('' % (FLAGS.vncproxy_port)) - self.transport.loseConnection() - -class FlashSocketPolicyFactory(protocol.ServerFactory): - protocol = FlashSocketPolicyProtocol + fd = socket.makefile('rw') + expected_command = "" + if expected_command in fd.read(len(expected_command)+1): + LOG.info(_("Received valid flash socket policy request")) + fd.write('' % (FLAGS.vncproxy_port)) + fd.flush() + socket.close() if __name__ == "__main__": utils.default_flagfile() @@ -108,11 +106,7 @@ if __name__ == "__main__": service.serve() - flash_socket_policy_pid = os.fork() - if flash_socket_policy_pid == 0: - reactor.listenTCP(843, FlashSocketPolicyFactory()) - reactor.run() - else: - server = wsgi.Server() - server.start(with_auth, FLAGS.vncproxy_port, host=FLAGS.vncproxy_host) - server.wait() + server = wsgi.Server() + server.start(with_auth, FLAGS.vncproxy_port, host=FLAGS.vncproxy_host) + server.start_tcp(handle_flash_socket_policy, 843, host=FLAGS.vncproxy_host) + server.wait() diff --git a/nova/wsgi.py b/nova/wsgi.py index 33ba852bc..700142f42 100644 --- a/nova/wsgi.py +++ b/nova/wsgi.py @@ -70,6 +70,15 @@ class Server(object): if key: self.socket_info[key] = socket.getsockname() + def start_tcp(self, listener, port, host='0.0.0.0', key=None, backlog=128): + """Run a raw TCP server with the given application.""" + arg0 = sys.argv[0] + logging.audit(_('Starting TCP server %(arg0)s on %(host)s:%(port)s') % locals()) + socket = eventlet.listen((host, port), backlog=backlog) + self.pool.spawn_n(self._run_tcp, listener, socket) + if key: + self.socket_info[key] = socket.getsockname() + def wait(self): """Wait until all servers have completed running.""" try: @@ -83,6 +92,15 @@ class Server(object): eventlet.wsgi.server(socket, application, custom_pool=self.pool, log=WritableLogger(logger)) + def _run_tcp(self, listener, socket): + """Start a raw TCP server in a new green thread.""" + while True: + try: + new_sock, address = socket.accept() + self.pool.spawn_n(listener, new_sock) + except (SystemExit, KeyboardInterrupt): + pass + class Request(webob.Request): pass -- cgit From 81ea3d5fc47bed84c5f4bf722b02dfa58792e19e Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Wed, 29 Jun 2011 18:26:51 -0400 Subject: Updated v1.1 links in flavors to represent the curret spec --- nova/api/openstack/views/flavors.py | 2 -- nova/tests/api/openstack/test_flavors.py | 10 ---------- 2 files changed, 12 deletions(-) diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index 462890ab2..beef67a88 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -79,12 +79,10 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "type": "application/json", "href": href, }, { "rel": "bookmark", - "type": "application/xml", "href": href, }, ] diff --git a/nova/tests/api/openstack/test_flavors.py b/nova/tests/api/openstack/test_flavors.py index d1c62e454..47e6a3fd3 100644 --- a/nova/tests/api/openstack/test_flavors.py +++ b/nova/tests/api/openstack/test_flavors.py @@ -146,12 +146,10 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", "href": "http://localhost/v1.1/flavors/12", }, { "rel": "bookmark", - "type": "application/xml", "href": "http://localhost/v1.1/flavors/12", }, ], @@ -175,12 +173,10 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", "href": "http://localhost/v1.1/flavors/1", }, { "rel": "bookmark", - "type": "application/xml", "href": "http://localhost/v1.1/flavors/1", }, ], @@ -195,12 +191,10 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", "href": "http://localhost/v1.1/flavors/2", }, { "rel": "bookmark", - "type": "application/xml", "href": "http://localhost/v1.1/flavors/2", }, ], @@ -227,12 +221,10 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", "href": "http://localhost/v1.1/flavors/1", }, { "rel": "bookmark", - "type": "application/xml", "href": "http://localhost/v1.1/flavors/1", }, ], @@ -249,12 +241,10 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", "href": "http://localhost/v1.1/flavors/2", }, { "rel": "bookmark", - "type": "application/xml", "href": "http://localhost/v1.1/flavors/2", }, ], -- cgit From 3d697627408897e9103663970c1615cf0f9a7a05 Mon Sep 17 00:00:00 2001 From: Jimmy Bergman Date: Thu, 30 Jun 2011 08:55:56 +0200 Subject: Adapt flash socket policy branch to new nova/wsgi.py refactoring --- nova/wsgi.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nova/wsgi.py b/nova/wsgi.py index b48233280..6a6881d88 100644 --- a/nova/wsgi.py +++ b/nova/wsgi.py @@ -67,6 +67,7 @@ class Server(object): self.host = host or "0.0.0.0" self.port = port or 0 self._server = None + self._tcp_server = None self._socket = None self._pool = eventlet.GreenPool(pool_size or self.default_pool_size) self._logger = logging.getLogger("eventlet.wsgi.server") @@ -106,15 +107,16 @@ class Server(object): """ LOG.info(_("Stopping WSGI server.")) self._server.kill() + if self._tcp_server is not None: + LOG.info(_("Stopping raw TCP server.")) + self._tcp_server.kill() def start_tcp(self, listener, port, host='0.0.0.0', key=None, backlog=128): """Run a raw TCP server with the given application.""" arg0 = sys.argv[0] - logging.audit(_('Starting TCP server %(arg0)s on %(host)s:%(port)s') % locals()) + LOG.info(_('Starting TCP server %(arg0)s on %(host)s:%(port)s') % locals()) socket = eventlet.listen((host, port), backlog=backlog) - self.pool.spawn_n(self._run_tcp, listener, socket) - if key: - self.socket_info[key] = socket.getsockname() + self._tcp_server = self._pool.spawn_n(self._run_tcp, listener, socket) def wait(self): """Block, until the server has stopped. @@ -134,7 +136,7 @@ class Server(object): while True: try: new_sock, address = socket.accept() - self.pool.spawn_n(listener, new_sock) + self._pool.spawn_n(listener, new_sock) except (SystemExit, KeyboardInterrupt): pass -- cgit From 8133b9af105f7924f03b710b30cf4f0acb52f143 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 30 Jun 2011 10:29:31 -0400 Subject: refactored flavors viewbuilder --- nova/api/openstack/views/flavors.py | 15 ++++++++++----- nova/tests/api/openstack/test_flavors.py | 30 +++++------------------------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index beef67a88..4e609930c 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -71,6 +71,7 @@ class ViewBuilderV11(ViewBuilder): def _build_links(self, flavor_obj): """Generate a container of links that refer to the provided flavor.""" href = self.generate_href(flavor_obj["id"]) + bookmark = self.generate_bookmark(flavor_obj["id"]) links = [ { @@ -79,11 +80,7 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "href": href, - }, - { - "rel": "bookmark", - "href": href, + "href": bookmark, }, ] @@ -92,3 +89,11 @@ class ViewBuilderV11(ViewBuilder): def generate_href(self, flavor_id): """Create an url that refers to a specific flavor id.""" return "%s/flavors/%s" % (self.base_url, flavor_id) + + def generate_bookmark(self, flavor_id): + """Create an url that refers to a specific flavor id.""" + return "%s/flavors/%s" % (self._remove_version(self.base_url), + flavor_id) + + def _remove_version(self, base_url): + return base_url.rsplit('/', 1).pop(0) diff --git a/nova/tests/api/openstack/test_flavors.py b/nova/tests/api/openstack/test_flavors.py index 47e6a3fd3..7b4bd12f3 100644 --- a/nova/tests/api/openstack/test_flavors.py +++ b/nova/tests/api/openstack/test_flavors.py @@ -146,11 +146,7 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/12", - }, - { - "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/12", + "href": "http://localhost/flavors/12", }, ], } @@ -173,11 +169,7 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/1", - }, - { - "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/1", + "href": "http://localhost/flavors/1", }, ], }, @@ -191,11 +183,7 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/2", - }, - { - "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/2", + "href": "http://localhost/flavors/2", }, ], }, @@ -221,11 +209,7 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/1", - }, - { - "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/1", + "href": "http://localhost/flavors/1", }, ], }, @@ -241,11 +225,7 @@ class FlavorsTest(test.TestCase): }, { "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/2", - }, - { - "rel": "bookmark", - "href": "http://localhost/v1.1/flavors/2", + "href": "http://localhost/flavors/2", }, ], }, -- cgit From 5f772ea10c22549a7149f608cfc2ff932878d6fe Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 30 Jun 2011 11:18:19 -0400 Subject: updated servers --- nova/api/openstack/views/servers.py | 17 ++++++++++------- nova/tests/api/openstack/test_servers.py | 16 ++-------------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index cbfa5aae7..1c6dbf87d 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -156,6 +156,7 @@ class ViewBuilderV11(ViewBuilder): def _build_links(self, response, inst): href = self.generate_href(inst["id"]) + bookmark = self.generate_bookmark(inst["id"]) links = [ { @@ -164,13 +165,7 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "type": "application/json", - "href": href, - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": href, + "href": bookmark, }, ] @@ -179,3 +174,11 @@ class ViewBuilderV11(ViewBuilder): def generate_href(self, server_id): """Create an url that refers to a specific server id.""" return os.path.join(self.base_url, "servers", str(server_id)) + + def generate_bookmark(self, server_id): + """Create an url that refers to a specific flavor id.""" + return os.path.join(self._remove_version(self.base_url), + "servers", str(server_id)) + + def _remove_version(self, base_url): + return base_url.rsplit('/', 1).pop(0) diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index b53c6c9be..110445935 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -290,13 +290,7 @@ class ServersTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/servers/1", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/servers/1", + "href": "http://localhost/servers/1", }, ] @@ -514,13 +508,7 @@ class ServersTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/servers/%d" % (i,), - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/servers/%d" % (i,), + "href": "http://localhost/servers/%d" % (i,), }, ] -- cgit From 386e2a28f2d92dea30a726722b49e97e1c7ebba7 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 30 Jun 2011 11:29:45 -0400 Subject: updated images --- nova/api/openstack/views/images.py | 17 ++++--- nova/tests/api/openstack/test_images.py | 78 ++++++--------------------------- 2 files changed, 24 insertions(+), 71 deletions(-) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index d6a054102..175bcb109 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -104,6 +104,7 @@ class ViewBuilderV11(ViewBuilder): """Return a standardized image structure for display by the API.""" image = ViewBuilder.build(self, image_obj, detail) href = self.generate_href(image_obj["id"]) + bookmark = self.generate_bookmark(image_obj["id"]) image["links"] = [{ "rel": "self", @@ -111,13 +112,15 @@ class ViewBuilderV11(ViewBuilder): }, { "rel": "bookmark", - "type": "application/json", - "href": href, - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": href, + "href": bookmark, }] return image + + def generate_bookmark(self, image_id): + """Create an url that refers to a specific flavor id.""" + return os.path.join(self._remove_version(self._url), + "images", str(image_id)) + + def _remove_version(self, base_url): + return base_url.rsplit('/', 1).pop(0) diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index e11e1c046..b864ae9f4 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -400,6 +400,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): actual_image = json.loads(response.body) href = "http://localhost/v1.1/images/123" + bookmark = "http://localhost/images/123" expected_image = { "image": { @@ -414,13 +415,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": href, - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": href, + "href": bookmark, }], }, } @@ -473,6 +468,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): actual_image = minidom.parseString(response.body.replace(" ", "")) expected_href = "http://localhost/v1.1/images/123" + expected_bookmark = "http://localhost/images/123" expected_now = self.NOW_API_FORMAT expected_image = minidom.parseString(""" - - + """.replace(" ", "") % (locals())) @@ -580,22 +573,17 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): continue href = "http://localhost/v1.1/images/%s" % image["id"] + bookmark = "http://localhost/images/%s" % image["id"] test_image = { "id": image["id"], "name": image["name"], "links": [{ "rel": "self", - "href": "http://localhost/v1.1/images/%s" % image["id"], - }, - { - "rel": "bookmark", - "type": "application/json", "href": href, }, { "rel": "bookmark", - "type": "application/xml", - "href": href, + "href": bookmark, }], } self.assertTrue(test_image in response_list) @@ -674,13 +662,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/123", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/123", + "href": "http://localhost/images/123", }], }, { @@ -696,13 +678,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/124", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/124", + "href": "http://localhost/images/124", }], }, { @@ -719,13 +695,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/125", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/125", + "href": "http://localhost/images/125", }], }, { @@ -741,13 +711,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/126", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/126", + "href": "http://localhost/images/126", }], }, { @@ -763,13 +727,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/127", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/127", + "href": "http://localhost/images/127", }], }, { @@ -784,13 +742,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): }, { "rel": "bookmark", - "type": "application/json", - "href": "http://localhost/v1.1/images/129", - }, - { - "rel": "bookmark", - "type": "application/xml", - "href": "http://localhost/v1.1/images/129", + "href": "http://localhost/images/129", }], }, ] @@ -1120,6 +1072,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): self.assertEqual(200, response.status_int) resp_xml = minidom.parseString(response.body.replace(" ", "")) expected_href = "http://localhost/v1.1/images/123" + expected_bookmark = "http://localhost/images/123" expected_image = minidom.parseString(""" - - + """.replace(" ", "") % (locals())) -- cgit From 7c270b077ac916375dfbaeb5aea2a15387debe89 Mon Sep 17 00:00:00 2001 From: Thierry Carrez Date: Mon, 4 Jul 2011 17:31:24 +0200 Subject: Silence warning in case tests.sqlite doesn't exist --- run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run_tests.sh b/run_tests.sh index ddeb1dc4a..b8078e150 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -114,7 +114,7 @@ if [ $just_pep8 -eq 1 ]; then fi if [ $recreate_db -eq 1 ]; then - rm tests.sqlite + rm -f tests.sqlite fi run_tests || exit -- cgit From efb5363356b13c3492ae895a1778428d06e6ca9c Mon Sep 17 00:00:00 2001 From: Jimmy Bergman Date: Thu, 7 Jul 2011 08:10:45 +0200 Subject: pep8 compliance --- bin/nova-vncproxy | 9 ++++++--- nova/wsgi.py | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/nova-vncproxy b/bin/nova-vncproxy index 5d3dbf610..bdbb30a7f 100755 --- a/bin/nova-vncproxy +++ b/bin/nova-vncproxy @@ -62,14 +62,17 @@ flags.DEFINE_flag(flags.HelpFlag()) flags.DEFINE_flag(flags.HelpshortFlag()) flags.DEFINE_flag(flags.HelpXMLFlag()) + def handle_flash_socket_policy(socket): LOG.info(_("Received connection on flash socket policy port")) fd = socket.makefile('rw') expected_command = "" - if expected_command in fd.read(len(expected_command)+1): - LOG.info(_("Received valid flash socket policy request")) - fd.write('' % (FLAGS.vncproxy_port)) + if expected_command in fd.read(len(expected_command) + 1): + LOG.info(_("Received valid flash socket policy request")) + fd.write('' % (FLAGS.vncproxy_port)) fd.flush() socket.close() diff --git a/nova/wsgi.py b/nova/wsgi.py index 6a6881d88..eae3afcb4 100644 --- a/nova/wsgi.py +++ b/nova/wsgi.py @@ -114,7 +114,8 @@ class Server(object): def start_tcp(self, listener, port, host='0.0.0.0', key=None, backlog=128): """Run a raw TCP server with the given application.""" arg0 = sys.argv[0] - LOG.info(_('Starting TCP server %(arg0)s on %(host)s:%(port)s') % locals()) + LOG.info(_('Starting TCP server %(arg0)s on %(host)s:%(port)s') + % locals()) socket = eventlet.listen((host, port), backlog=backlog) self._tcp_server = self._pool.spawn_n(self._run_tcp, listener, socket) -- cgit From a92158cee2a57316252ec6fd0d6c0c4f1e7a1fcf Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 09:26:25 -0400 Subject: moved remove_version to common.py --- nova/api/openstack/common.py | 3 +++ nova/api/openstack/views/flavors.py | 5 +---- nova/api/openstack/views/images.py | 7 +++---- nova/api/openstack/views/servers.py | 5 +---- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index aa8911b62..8794bca6d 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -134,3 +134,6 @@ def get_id_from_href(href): except: LOG.debug(_("Error extracting id from href: %s") % href) raise webob.exc.HTTPBadRequest(_('could not parse id from href')) + +def remove_version(base_url): + return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index 4e609930c..d967c2af0 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -92,8 +92,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, flavor_id): """Create an url that refers to a specific flavor id.""" - return "%s/flavors/%s" % (self._remove_version(self.base_url), + return "%s/flavors/%s" % (common.remove_version(self.base_url), flavor_id) - - def _remove_version(self, base_url): - return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index 5ab02671c..9d6722326 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -17,6 +17,8 @@ import os.path +from nova.api.openstack import common + class ViewBuilder(object): """Base class for generating responses to OpenStack API image requests.""" @@ -122,8 +124,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, image_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(self._remove_version(self._url), + return os.path.join(common.remove_version(self._url), "images", str(image_id)) - - def _remove_version(self, base_url): - return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index 1c6dbf87d..b85fceb19 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -177,8 +177,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, server_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(self._remove_version(self.base_url), + return os.path.join(common.remove_version(self.base_url), "servers", str(server_id)) - - def _remove_version(self, base_url): - return base_url.rsplit('/', 1).pop(0) -- cgit From bf851c7f403c7be8d8f27274fa5216cfa6eaf4f4 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 09:42:13 -0400 Subject: Renamed function --- nova/api/openstack/common.py | 9 ++++++++- nova/api/openstack/views/flavors.py | 2 +- nova/api/openstack/views/images.py | 2 +- nova/api/openstack/views/servers.py | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 8794bca6d..48773291c 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -135,5 +135,12 @@ def get_id_from_href(href): LOG.debug(_("Error extracting id from href: %s") % href) raise webob.exc.HTTPBadRequest(_('could not parse id from href')) -def remove_version(base_url): + +def remove_version_from_href(base_url): + """Removes the api version from the href. + + Given: 'http://www.nova.com/v1.1/123' + Returns: 'http://www.nova.com/123' + + """ return base_url.rsplit('/', 1).pop(0) diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index d967c2af0..d2f7e3e56 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -92,5 +92,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, flavor_id): """Create an url that refers to a specific flavor id.""" - return "%s/flavors/%s" % (common.remove_version(self.base_url), + return "%s/flavors/%s" % (common.remove_version_from_href(self.base_url), flavor_id) diff --git a/nova/api/openstack/views/images.py b/nova/api/openstack/views/images.py index 9d6722326..005341c62 100644 --- a/nova/api/openstack/views/images.py +++ b/nova/api/openstack/views/images.py @@ -124,5 +124,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, image_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(common.remove_version(self._url), + return os.path.join(common.remove_version_from_href(self._url), "images", str(image_id)) diff --git a/nova/api/openstack/views/servers.py b/nova/api/openstack/views/servers.py index b85fceb19..67fb6a84e 100644 --- a/nova/api/openstack/views/servers.py +++ b/nova/api/openstack/views/servers.py @@ -177,5 +177,5 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, server_id): """Create an url that refers to a specific flavor id.""" - return os.path.join(common.remove_version(self.base_url), + return os.path.join(common.remove_version_from_href(self.base_url), "servers", str(server_id)) -- cgit From 19e4cef2518e2c1e02e27137cadea55861d092c4 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Thu, 7 Jul 2011 10:02:06 -0400 Subject: pep8 --- nova/api/openstack/common.py | 2 +- nova/api/openstack/views/flavors.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py index 48773291c..9aa384f33 100644 --- a/nova/api/openstack/common.py +++ b/nova/api/openstack/common.py @@ -138,7 +138,7 @@ def get_id_from_href(href): def remove_version_from_href(base_url): """Removes the api version from the href. - + Given: 'http://www.nova.com/v1.1/123' Returns: 'http://www.nova.com/123' diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py index d2f7e3e56..0403ece1b 100644 --- a/nova/api/openstack/views/flavors.py +++ b/nova/api/openstack/views/flavors.py @@ -92,5 +92,7 @@ class ViewBuilderV11(ViewBuilder): def generate_bookmark(self, flavor_id): """Create an url that refers to a specific flavor id.""" - return "%s/flavors/%s" % (common.remove_version_from_href(self.base_url), - flavor_id) + return "%s/flavors/%s" % ( + common.remove_version_from_href(self.base_url), + flavor_id, + ) -- cgit