Juan Hernandez has uploaded a new change for review.

Change subject: sdk: Use /api if the URL doesn't have a path
......................................................................

sdk: Use /api if the URL doesn't have a path

Previous versions of the SDK hardcoded the location of the API, and some
clients rely on that and use URLs that don't have a path. This patch
changes the SDK so that it will automaticallu use /api in that case.

Change-Id: I334ec9b7010b9469dd5be78e51febeda39e404f3
Bug-Url: https://bugzilla.redhat.com/1066036
Signed-off-by: Juan Hernandez <juan.hernan...@redhat.com>
---
M src/codegen/templates/entrypointtemplate
M src/ovirtsdk/api.py
2 files changed, 20 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/95/24595/1

diff --git a/src/codegen/templates/entrypointtemplate 
b/src/codegen/templates/entrypointtemplate
index 6729b62..d09aa95 100644
--- a/src/codegen/templates/entrypointtemplate
+++ b/src/codegen/templates/entrypointtemplate
@@ -39,6 +39,16 @@
         if context.manager.has_key(self.__id):
             self.disconnect()
 
+        # Remove trailing slashes from the URL:
+        url = url.rstrip('/')
+
+        # For backwards compatibility we need to support URLs that don't
+        # contain a path, and in that case the path should be the old /api:
+        prefix = urlparse.urlparse(url).path
+        if prefix == '':
+            prefix = '/api'
+            url = url + prefix
+
         # Create the connection pool:
         pool = ConnectionsPool(
             url=url,
@@ -55,10 +65,6 @@
             validate_cert_chain=validate_cert_chain,
             debug=debug
         )
-
-        # Extract from the entry point URL the prefix common to paths
-        # of all requests and remove trailing slashes:
-        prefix = urlparse.urlparse(url).path.rstrip('/')
 
         # Create the proxy:
         proxy = Proxy(
diff --git a/src/ovirtsdk/api.py b/src/ovirtsdk/api.py
index de1eb60..f3cf68c 100644
--- a/src/ovirtsdk/api.py
+++ b/src/ovirtsdk/api.py
@@ -96,6 +96,16 @@
         if context.manager.has_key(self.__id):
             self.disconnect()
 
+        # Remove trailing slashes from the URL:
+        url = url.rstrip('/')
+
+        # For backwards compatibility we need to support URLs that don't
+        # contain a path, and in that case the path should be the old /api:
+        prefix = urlparse.urlparse(url).path
+        if prefix == '':
+            prefix = '/api'
+            url = url + prefix
+
         # Create the connection pool:
         pool = ConnectionsPool(
             url=url,
@@ -112,10 +122,6 @@
             validate_cert_chain=validate_cert_chain,
             debug=debug
         )
-
-        # Extract from the entry point URL the prefix common to paths
-        # of all requests and remove trailing slashes:
-        prefix = urlparse.urlparse(url).path.rstrip('/')
 
         # Create the proxy:
         proxy = Proxy(


-- 
To view, visit http://gerrit.ovirt.org/24595
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I334ec9b7010b9469dd5be78e51febeda39e404f3
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to