Juan Hernandez has uploaded a new change for review.

Change subject: codegen: Use relative paths
......................................................................

codegen: Use relative paths

Currently the SDK assumes that resources are located in the /api URL,
but this might not be true, depending on the configuration of the
server. This patch changes the SDK to use relative paths for all
resources, so it will work with servers configured with any entry point
URL.

Change-Id: I0e39510541e34349fce5a8ad4a643cf65784bccc
Bug-Ur: https://bugzilla.redhat.com/1038952
Signed-off-by: Juan Hernandez <[email protected]>
---
M src/codegen/collection/collection.py
M src/codegen/collection/collectionexceptions.py
M src/codegen/entrypoint/entrypoint.py
M src/codegen/main.py
M src/codegen/resource/resource.py
M src/codegen/rsdl/rsdlcodegen.py
M src/codegen/subcollection/subcollection.py
M src/codegen/subresource/subresource.py
M src/codegen/templates/collectionaddtemplate
M src/codegen/templates/collectiongetcapabilitiestemplate
M src/codegen/templates/collectiongetdiskstemplate
M src/codegen/templates/collectiongetnotsearchabletemplate
M src/codegen/templates/collectiongetsearchabletemplate
M src/codegen/templates/collectionlistcapabilitiestemplate
M src/codegen/templates/collectionlistnotsearchabletemplate
M src/codegen/templates/collectionlistsearchabletemplate
M src/codegen/templates/entrypointdyinamicmethodtemplate
M src/codegen/templates/entrypointmethodstemplate
M src/codegen/templates/entrypointtemplate
M src/codegen/templates/resourceactiontemplate
M src/codegen/templates/resourcedeletetemplate
M src/codegen/templates/resourcedeletewithbodyandparamstemplate
M src/codegen/templates/resourcedeletewithbodytemplate
M src/codegen/templates/resourcedeletewithparamstemplate
M src/codegen/templates/resourceupdatetemplate
M src/codegen/templates/subcollectionaddtemplate
M src/codegen/templates/subcollectiongettemplate
M src/codegen/templates/subcollectionlisttemplate
M src/codegen/templates/subcollectionlistwithparamstemplate
M src/codegen/templates/subresourceactiontemplate
M src/codegen/templates/subresourcecollectionactiontemplate
M src/codegen/templates/subresourcedeletetemplate
M src/codegen/templates/subresourcedeletewithbodytemplate
M src/codegen/templates/subresourcedeletewithurlparamsandbodytemplate
M src/codegen/templates/subresourcedeletewithurlparamstemplate
M src/codegen/templates/subresourceupdatetemplate
M src/codegen/utils/urlutils.py
M src/codegen/xsd/abstractxsdcodegen.py
M src/codegen/xsd/genparams.py
M src/ovirtsdk/api.py
M src/ovirtsdk/infrastructure/proxy.py
41 files changed, 173 insertions(+), 153 deletions(-)


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

diff --git a/src/codegen/collection/collection.py 
b/src/codegen/collection/collection.py
index b2199e0..18f83aa 100644
--- a/src/codegen/collection/collection.py
+++ b/src/codegen/collection/collection.py
@@ -52,7 +52,7 @@
                .generate(collection_resource_template_values)
 
     @staticmethod
-    def get(url, resource_type, link, KNOWN_WRAPPER_TYPES={}):
+    def get(path, resource_type, link, KNOWN_WRAPPER_TYPES={}):
 
         actual_resource_type = \
             TypeUtil.getValueByKeyOrNone(
@@ -76,7 +76,7 @@
                 else headers_method_params_str
 
         collection_get_template_values = {
-          'url':url,
+          'path':path,
           'resource_name_lc':actual_resource_name_lc,
           'headers_method_params_str' : headers_method_params_str,
           'headers_map_params_str' : headers_map_params_str,
@@ -94,9 +94,9 @@
         # Capabilities resource has unique structure which is not
         # fully comply with RESTful collection pattern, but preserved
         # in sake of backward compatibility
-        if url == '/api/capabilities':
+        if path == '/capabilities':
             return CollectionExceptions.get(
-                        url,
+                        path,
                         link,
                         prms_str,
                         method_params,
@@ -106,11 +106,11 @@
                         collection_get_template_values
                     )
 
-        # /api/disks search-by-name paradigm was broken by the engine
+        # /disks search-by-name paradigm was broken by the engine
         # should be fixed later on
-        if url == '/api/disks':
+        if path == '/disks':
             return CollectionExceptions.get(
-                        url,
+                        path,
                         link,
                         prms_str,
                         method_params,
@@ -130,7 +130,7 @@
                    )
 
     @staticmethod
-    def list(url, resource_type, link, KNOWN_WRAPPER_TYPES={}):
+    def list(path, resource_type, link, KNOWN_WRAPPER_TYPES={}):
 
         actual_resource_type = TypeUtil.getValueByKeyOrNone(
             resource_type.lower(),
@@ -153,7 +153,7 @@
         method_params['**kwargs'] = '**kwargs'
 
         collection_list_template_values = {
-           'url':url,
+           'path':path,
            'resource_name_lc':actual_resource_name_lc,
            'resource_type' : actual_resource_type \
                 if actual_resource_type is not None \
@@ -164,7 +164,7 @@
         # Capabilities resource has unique structure which is not
         # fully comply with RESTful collection pattern, but preserved
         # in sake of backward compatibility
-        if url == '/api/capabilities':
+        if path == '/capabilities':
 
             return CollectionExceptions.list()
         elif prms_str != '' or headers_method_params_str != '':
@@ -207,7 +207,7 @@
                    .generate(collection_list_template_values)
 
     @staticmethod
-    def add(url, body_type, response_type, link, KNOWN_WRAPPER_TYPES={}):
+    def add(path, body_type, response_type, link, KNOWN_WRAPPER_TYPES={}):
 
         actual_resource_type = \
                     TypeUtil.getValueByKeyOrNone(
@@ -223,7 +223,7 @@
               else headers_method_params_str
 
         collection_add_template_values = {
-              'url':url,
+              'path':path,
               'resource_to_add_lc':body_type.lower(),
               'headers_method_params_str' : headers_method_params_str,
               'docs' : Documentation.document(link),
diff --git a/src/codegen/collection/collectionexceptions.py 
b/src/codegen/collection/collectionexceptions.py
index 8cfe68f..6913ccf 100644
--- a/src/codegen/collection/collectionexceptions.py
+++ b/src/codegen/collection/collectionexceptions.py
@@ -35,17 +35,17 @@
         return collectionlistcapabilitiestemplate.generate()
 
     @staticmethod
-    def get(url, link, prms_str, method_params, url_params, 
headers_method_params_str,
+    def get(path, link, prms_str, method_params, url_params, 
headers_method_params_str,
             headers_map_params_str, collection_get_template_values):
 
         # Capabilities resource has unique structure which is not
         # fully comply with RESTful collection pattern, but preserved
         # in sake of backward compatibility
-        if url == '/api/capabilities':
+        if path == '/capabilities':
             return collectiongetcapabilitiestemplate\
                    .generate()
 
-        if url == '/api/disks':
+        if path == '/disks':
             collection_get_template_values['docs'] = \
                     Documentation.document(link, {
                               'alias: string (the alias of the entity)': False,
diff --git a/src/codegen/entrypoint/entrypoint.py 
b/src/codegen/entrypoint/entrypoint.py
index 373ffed..7acdbe3 100644
--- a/src/codegen/entrypoint/entrypoint.py
+++ b/src/codegen/entrypoint/entrypoint.py
@@ -65,7 +65,7 @@
         methods_template = entrypointmethodstemplate.generate()
 
         entry_point_resource = context.manager[api.id]\
-                               .get('proxy').request('GET', '/api')
+                               .get('proxy').request('GET', '')
 
         for attr in entry_point_resource.__dict__.keys():
             if attr not in exclude:
diff --git a/src/codegen/main.py b/src/codegen/main.py
old mode 100644
new mode 100755
diff --git a/src/codegen/resource/resource.py b/src/codegen/resource/resource.py
index cf5500a..f623256 100644
--- a/src/codegen/resource/resource.py
+++ b/src/codegen/resource/resource.py
@@ -73,7 +73,7 @@
         return new_tmpl
 
     @staticmethod
-    def action(url, body_type, link, action_name, resource_name_lc, method, 
action_params={}):
+    def action(path, body_type, link, action_name, resource_name_lc, method, 
action_params={}):
 
         headers_method_params_str, headers_map_params_str = \
             HeaderUtils.generate_method_params(link)
@@ -86,7 +86,7 @@
 #        resource_action_template_values['headers_method_params_str'] = 
headers_method_params_str
 
         resource_action_template_values = {
-           'url':url,
+           'path':path,
            'body_type':body_type,
            'body_type_lc':body_type.lower(),
            'action_name':action_name.lower(),
@@ -119,7 +119,7 @@
         return res
 
     @staticmethod
-    def delete(url, body_type, link, resource_name):
+    def delete(path, body_type, link, resource_name):
 
         prms_str, method_params, url_params = \
             ParamUtils.getMethodParamsByUrlParamsMeta(link)
@@ -135,7 +135,7 @@
         body_instance_str = '=' + body_instance if body_instance else ''
 
         resource_delete_template_values = {
-           'url':url,
+           'path':path,
            'body_type':body_type,
            'resource_name_lc':resource_name.lower(),
            'body_type_lc':body_type.lower() if body_type is not None
@@ -185,7 +185,7 @@
             return body_resource_delete_template
 
     @staticmethod
-    def update(url, resource_name, link, KNOWN_WRAPPER_TYPES={}):
+    def update(path, resource_name, link, KNOWN_WRAPPER_TYPES={}):
 
         actual_xml_entity = TypeUtil.getValueByKeyOrNone(
                                      resource_name.lower(),
@@ -200,7 +200,7 @@
             else headers_method_params_str
 
         resource_update_template_values = {
-           'url':url,
+           'path':path,
            'resource_name_lc':resource_name.lower(),
            'docs' : Documentation.document(link),
            'headers_map_params_str': headers_map_params_str,
diff --git a/src/codegen/rsdl/rsdlcodegen.py b/src/codegen/rsdl/rsdlcodegen.py
index 48432cc..9b28d5d 100644
--- a/src/codegen/rsdl/rsdlcodegen.py
+++ b/src/codegen/rsdl/rsdlcodegen.py
@@ -78,9 +78,17 @@
         collectionsHolder = {}
         usedRels = []
 
-        for link in context.manager[self.context].get('proxy') \
-                                                 .request('GET', '/api?rsdl') \
-                                                 .links.link:
+
+        # Get the proxy and the URL prefix from the context:
+        proxy = context.manager[self.context].get('proxy')
+        prefix = proxy.getPrefix()
+
+        # Get all the links from the RSDL document an make them relative:
+        links = proxy.request('GET', '?rsdl').links.link
+        for link in links:
+            link.href = link.href.replace(prefix, "")
+
+        for link in links:
 
             response_type = None
             body_type = None
@@ -106,7 +114,6 @@
 
                 # get relations
                 splitted_url = url.strip()[1:].split('/')
-                splitted_url.pop(0)
 
                 # append resource/method/rel
                 self.__appendResource(rel, url, http_method, body_type, link,
diff --git a/src/codegen/subcollection/subcollection.py 
b/src/codegen/subcollection/subcollection.py
index 626d27e..15219f3 100644
--- a/src/codegen/subcollection/subcollection.py
+++ b/src/codegen/subcollection/subcollection.py
@@ -51,7 +51,7 @@
                .generate(sub_collection_get_template_values)
 
     @staticmethod
-    def get(url, link, parent_resource_name_lc, encapsulating_resource,
+    def get(path, link, parent_resource_name_lc, encapsulating_resource,
             actual_resource_name_candidate, KNOWN_WRAPPER_TYPES={},
             NAMING_ENTITY_EXCEPTIONS={}):
 
@@ -82,7 +82,7 @@
                 else headers_method_params_str
 
         sub_collection_get_template_values = {
-          'url':url,
+          'path':path,
           'parent_resource_name_lc':parent_resource_name_lc.lower(),
           'resource_name_lc':encapsulating_resource.lower(),
           'actual_resource_name_lc':actual_resource_name_lc,
@@ -114,7 +114,7 @@
                .generate(sub_collection_get_template_values)
 
     @staticmethod
-    def list(url, link, parent_resource_name_lc, encapsulating_resource,
+    def list(path, link, parent_resource_name_lc, encapsulating_resource,
              actual_resource_name_candidate, KNOWN_WRAPPER_TYPES={},
              NAMING_ENTITY_EXCEPTIONS={}):
 
@@ -151,7 +151,7 @@
         method_params['**kwargs'] = '**kwargs'
 
         sub_collection_list_template_values = {
-           'url':url,
+           'path':path,
            'parent_resource_name_lc':parent_resource_name_lc.lower(),
            'actual_resource_name_lc':actual_resource_name_lc,
            'combined_method_params':combined_method_params,
@@ -207,7 +207,7 @@
                    .generate(sub_collection_list_template_values)
 
     @staticmethod
-    def add(url, link, body_type, parent_resource_name_lc, 
encapsulating_entity, KNOWN_WRAPPER_TYPES={}):
+    def add(path, link, body_type, parent_resource_name_lc, 
encapsulating_entity, KNOWN_WRAPPER_TYPES={}):
 
         actual_encapsulating_entity = \
             TypeUtil.getValueByKeyOrNone(
@@ -224,7 +224,7 @@
 
         sub_collection_add_template_values = {
           'resource_to_add':body_type.lower(),
-          'url':url,
+          'path':path,
           'headers_map_params_str':headers_map_params_str,
           'headers_method_params_str':headers_method_params_str,
           'parent_resource_name_lc':parent_resource_name_lc.lower(),
diff --git a/src/codegen/subresource/subresource.py 
b/src/codegen/subresource/subresource.py
index 708fbf5..1dd1101 100644
--- a/src/codegen/subresource/subresource.py
+++ b/src/codegen/subresource/subresource.py
@@ -81,7 +81,7 @@
                 .generate(sub_collection_resource_template_values)
 
     @staticmethod
-    def action(url, link, action_name, parent_resource_name_lc,
+    def action(path, link, action_name, parent_resource_name_lc,
                body_type, resource_name_lc, method, action_params={},
                collection_action=False):
 
@@ -94,7 +94,7 @@
 
 
         sub_collection_resource_action_template_values = {
-              'url':url,
+              'path':path,
               'action_name':action_name,
               'method': method,
               'parent_resource_name_lc':parent_resource_name_lc.lower(),
@@ -131,7 +131,7 @@
         return sub_collection_resource_action_template
 
     @staticmethod
-    def update(url, link, parent_resource_name_lc, resource_name,
+    def update(path, link, parent_resource_name_lc, resource_name,
                returned_type, KNOWN_WRAPPER_TYPES):
 
         combined_method_params = ''
@@ -171,7 +171,7 @@
                       )
 
         sub_collection_resource_update_template_values = {
-             'url':url,
+            'path':path,
             'parent_resource_name_lc':parent_resource_name_lc.lower(),
             'resource_name':resource_name,
             'resource_name_lc':resource_name.lower(),
@@ -188,7 +188,7 @@
                 .generate(sub_collection_resource_update_template_values)
 
     @staticmethod
-    def delete(url, link, parent_resource_name_lc, resource_name_lc, 
body_type):
+    def delete(path, link, parent_resource_name_lc, resource_name_lc, 
body_type):
 
         prms_str, method_params, url_params = \
             ParamUtils.getMethodParamsByUrlParamsMeta(link)
@@ -210,7 +210,7 @@
 
 
         sub_collection_resource_delete_template_values = {
-              'url':url,
+              'path':path,
               'body_type_lc':body_type.lower() if body_type is not None
                                                else None,
               'parent_resource_name_lc':parent_resource_name_lc.lower(),
diff --git a/src/codegen/templates/collectionaddtemplate 
b/src/codegen/templates/collectionaddtemplate
index 6cf32a3..95307f2 100644
--- a/src/codegen/templates/collectionaddtemplate
+++ b/src/codegen/templates/collectionaddtemplate
@@ -1,9 +1,9 @@
     def add(self, %(resource_to_add_lc)s%(headers_method_params_str)s):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         result = self.__getProxy().add(
-           url=url,
+           path=path,
            body=ParseHelper.toXml(%(resource_to_add_lc)s),
            headers=%(headers_map_params_str)s
         )
diff --git a/src/codegen/templates/collectiongetcapabilitiestemplate 
b/src/codegen/templates/collectiongetcapabilitiestemplate
index fa2c456..211bff7 100644
--- a/src/codegen/templates/collectiongetcapabilitiestemplate
+++ b/src/codegen/templates/collectiongetcapabilitiestemplate
@@ -7,12 +7,12 @@
         @return VersionCaps:
         '''
 
-        url = '/api/capabilities'
+        path = '/capabilities'
 
         if id:
             try :
                 return VersionCaps(
-                    self.__getProxy().get(url=UrlHelper.append(url, id)),
+                    self.__getProxy().get(path=UrlHelper.append(path, id)),
                     self.context
                 )
             except RequestError, err:
@@ -20,7 +20,7 @@
                     return None
                 raise err
         elif kwargs:
-            result = self.__getProxy().get(url=url).version
+            result = self.__getProxy().get(path=path).version
 
             return VersionCaps(
                 FilterHelper.getItem(FilterHelper.filter(result, kwargs)),
diff --git a/src/codegen/templates/collectiongetdiskstemplate 
b/src/codegen/templates/collectiongetdiskstemplate
index c5ad640..ed207a8 100644
--- a/src/codegen/templates/collectiongetdiskstemplate
+++ b/src/codegen/templates/collectiongetdiskstemplate
@@ -1,11 +1,11 @@
     def get(self, alias=None, %(headers_method_params_str)sid=None):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         if id:
             try :
                 return %(resource_type)s(
-                    self.__getProxy().get(url=UrlHelper.append(url, id),
+                    self.__getProxy().get(path=UrlHelper.append(path, id),
                     headers=%(headers_map_params_str)s),
                     self.context
                 )
@@ -15,7 +15,7 @@
                 raise err
         elif alias:
             result = self.__getProxy().get(
-                url=SearchHelper.appendQuery(url, 
{'search:query':'alias='+alias}),
+                path=SearchHelper.appendQuery(path, 
{'search:query':'alias='+alias}),
                 headers=%(headers_map_params_str)s
             ).get_%(resource_name_lc)s()
 
diff --git a/src/codegen/templates/collectiongetnotsearchabletemplate 
b/src/codegen/templates/collectiongetnotsearchabletemplate
index 55e8b17..8ef9936 100644
--- a/src/codegen/templates/collectiongetnotsearchabletemplate
+++ b/src/codegen/templates/collectiongetnotsearchabletemplate
@@ -1,12 +1,12 @@
     def get(self, name=None, %(headers_method_params_str)sid=None):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         if id:
             try :
                 return %(resource_type)s(
                     self.__getProxy().get(
-                                url=UrlHelper.append(url, id),
+                                path=UrlHelper.append(path, id),
                                 headers=%(headers_map_params_str)s
                     ),
                     self.context
@@ -17,7 +17,7 @@
                 raise err
         elif name:
             result = self.__getProxy().get(
-                    url=url,
+                    path=path,
                     headers=%(headers_map_params_str)s
             ).get_%(resource_name_lc)s()
 
diff --git a/src/codegen/templates/collectiongetsearchabletemplate 
b/src/codegen/templates/collectiongetsearchabletemplate
index a9bc2a9..d7cf300 100644
--- a/src/codegen/templates/collectiongetsearchabletemplate
+++ b/src/codegen/templates/collectiongetsearchabletemplate
@@ -1,12 +1,12 @@
     def get(self, name=None, %(headers_method_params_str)sid=None):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         if id:
             try :
                 return %(resource_type)s(
                     self.__getProxy().get(
-                        url=UrlHelper.append(url, id),
+                        path=UrlHelper.append(path, id),
                         headers=%(headers_map_params_str)s
                     ),
                     self.context
@@ -17,7 +17,7 @@
                 raise err
         elif name:
             result = self.__getProxy().get(
-                url=SearchHelper.appendQuery(url, 
{'search:query':'name='+name}),
+                path=SearchHelper.appendQuery(path, 
{'search:query':'name='+name}),
                 headers=%(headers_map_params_str)s
             ).get_%(resource_name_lc)s()
 
diff --git a/src/codegen/templates/collectionlistcapabilitiestemplate 
b/src/codegen/templates/collectionlistcapabilitiestemplate
index b64c66e..0763e7e 100644
--- a/src/codegen/templates/collectionlistcapabilitiestemplate
+++ b/src/codegen/templates/collectionlistcapabilitiestemplate
@@ -6,9 +6,9 @@
         @return [VersionCaps]:
         '''
 
-        url='/api/capabilities'
+        path='/capabilities'
 
-        result = self.__getProxy().get(url=url).version
+        result = self.__getProxy().get(path=path).version
 
         return ParseHelper.toCollection(
             VersionCaps,
diff --git a/src/codegen/templates/collectionlistnotsearchabletemplate 
b/src/codegen/templates/collectionlistnotsearchabletemplate
index 5a53abd..a423e61 100644
--- a/src/codegen/templates/collectionlistnotsearchabletemplate
+++ b/src/codegen/templates/collectionlistnotsearchabletemplate
@@ -1,9 +1,9 @@
     def list(self, **kwargs):
 %(docs)s
-        url='%(url)s'
+        path='%(path)s'
 
         result = self.__getProxy().get(
-            url=url
+            path=path
         ).get_%(resource_name_lc)s()
 
         return ParseHelper.toCollection(
diff --git a/src/codegen/templates/collectionlistsearchabletemplate 
b/src/codegen/templates/collectionlistsearchabletemplate
index 803ef3c..098a795 100644
--- a/src/codegen/templates/collectionlistsearchabletemplate
+++ b/src/codegen/templates/collectionlistsearchabletemplate
@@ -1,9 +1,9 @@
     def list(self, %(combined_method_params)s, **kwargs):
 %(docs)s
-        url='%(url)s'
+        path='%(path)s'
 
         result = self.__getProxy().get(
-            url=SearchHelper.appendQuery(url, %(url_params)s),
+            path=SearchHelper.appendQuery(path, %(url_params)s),
             headers=%(headers_map_params_str)s
         ).get_%(resource_name_lc)s()
 
diff --git a/src/codegen/templates/entrypointdyinamicmethodtemplate 
b/src/codegen/templates/entrypointdyinamicmethodtemplate
index d29020b..1ed89cd 100644
--- a/src/codegen/templates/entrypointdyinamicmethodtemplate
+++ b/src/codegen/templates/entrypointdyinamicmethodtemplate
@@ -4,7 +4,7 @@
         if proxy:
             return proxy.request(
                 method='GET',
-                url='/api'
+                path=''
             ).%(attr)s
 
         raise DisconnectedError
diff --git a/src/codegen/templates/entrypointmethodstemplate 
b/src/codegen/templates/entrypointmethodstemplate
index 1629aba..853377e 100644
--- a/src/codegen/templates/entrypointmethodstemplate
+++ b/src/codegen/templates/entrypointmethodstemplate
@@ -24,7 +24,7 @@
                 try:
                     proxy.request(
                         method='GET',
-                        url='/api',
+                        path='',
                         last=True
                     )
                 except Exception:
@@ -43,7 +43,7 @@
             try :
                 proxy.request(
                     method='GET',
-                    url='/api'
+                    path=''
                 )
             except Exception, e:
                 if throw_exception: raise e
diff --git a/src/codegen/templates/entrypointtemplate 
b/src/codegen/templates/entrypointtemplate
index 28675c3..91b7e10 100644
--- a/src/codegen/templates/entrypointtemplate
+++ b/src/codegen/templates/entrypointtemplate
@@ -4,7 +4,7 @@
                  renew_session=False, insecure=False, 
validate_cert_chain=True, filter=False, debug=False):  # @ReservedAssignment
 
         '''
-        @param url: server url (format "http/s://server[:port]/api")
+        @param url: server url (format 
"http/s://server[:port]/ovirt-engine/api")
         @param username: user (format user@domain)
         @param password: password
         [@param key_file: client PEM key_file for ssl enabled connection]
@@ -56,8 +56,13 @@
             debug=debug
         )
 
+        # Extract from the entry point URL the prefix common to paths
+        # of all requests:
+        prefix = urlparse.urlparse(url).path
+
         # Create the proxy:
         proxy = Proxy(
+            prefix,
             pool,
             persistent_auth
         )
@@ -74,7 +79,7 @@
         # Get entry point
         entry_point = proxy.request(
             method='GET',
-            url=urlparse.urlparse(url).path
+            path=""
         )
 
         # If server returns no response for the root resource, this is sign
diff --git a/src/codegen/templates/resourceactiontemplate 
b/src/codegen/templates/resourceactiontemplate
index c43191f..ef72883 100644
--- a/src/codegen/templates/resourceactiontemplate
+++ b/src/codegen/templates/resourceactiontemplate
@@ -1,10 +1,10 @@
     def %(action_name)s(self%(method_params)s, 
%(body_type_lc)s=params.%(body_type)s()%(headers_method_params_str)s):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         result = self.__getProxy().request(
             method='%(method)s',
-            url=UrlHelper.replace(url, {'{%(resource_name_lc)s:id}': 
self.get_id()}),
+            path=UrlHelper.replace(path, {'{%(resource_name_lc)s:id}': 
self.get_id()}),
             body=ParseHelper.toXml(%(body_type_lc)s),
             headers=%(headers_map_params_str)s
         )
diff --git a/src/codegen/templates/resourcedeletetemplate 
b/src/codegen/templates/resourcedeletetemplate
index 94cdfdd..63bb2cd 100644
--- a/src/codegen/templates/resourcedeletetemplate
+++ b/src/codegen/templates/resourcedeletetemplate
@@ -1,10 +1,10 @@
     def delete(self):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         return self.__getProxy().delete(
-            url=UrlHelper.replace(
-                url,
+            path=UrlHelper.replace(
+                path,
                 {'{%(resource_name_lc)s:id}': self.get_id()}
             ),
             headers={'Content-type':None}
diff --git a/src/codegen/templates/resourcedeletewithbodyandparamstemplate 
b/src/codegen/templates/resourcedeletewithbodyandparamstemplate
index 1804c44..bbd10ca 100644
--- a/src/codegen/templates/resourcedeletewithbodyandparamstemplate
+++ b/src/codegen/templates/resourcedeletewithbodyandparamstemplate
@@ -1,10 +1,10 @@
     def delete(self, %(body_type_lc)s%(body_instance_str)s):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         return self.__getProxy().delete(
-            url=UrlHelper.replace(
-                url,
+            path=UrlHelper.replace(
+                path,
                 {'{%(resource_name_lc)s:id}': self.get_id()}
             ),
             body=ParseHelper.toXml(%(body_type_lc)s)
diff --git a/src/codegen/templates/resourcedeletewithbodytemplate 
b/src/codegen/templates/resourcedeletewithbodytemplate
index 114d39d..128e7fe 100644
--- a/src/codegen/templates/resourcedeletewithbodytemplate
+++ b/src/codegen/templates/resourcedeletewithbodytemplate
@@ -1,13 +1,13 @@
     def delete(self, %(body_type_lc)s%(body_instance_str)s, 
%(combined_method_params)s):
 %(docs)s
-        url = UrlHelper.replace(
-            '%(url)s',
+        path = UrlHelper.replace(
+            '%(path)s',
             {'{%(resource_name_lc)s:id}': self.get_id()}
         )
 
         return self.__getProxy().delete(
-            url=SearchHelper.appendQuery(
-                url,
+            path=SearchHelper.appendQuery(
+                path,
                 %(url_params)s
             ),
             body=ParseHelper.toXml(%(body_type_lc)s),
diff --git a/src/codegen/templates/resourcedeletewithparamstemplate 
b/src/codegen/templates/resourcedeletewithparamstemplate
index 2a37850..2bff58b 100644
--- a/src/codegen/templates/resourcedeletewithparamstemplate
+++ b/src/codegen/templates/resourcedeletewithparamstemplate
@@ -1,13 +1,13 @@
     def delete(self, %(combined_method_params)s):
 %(docs)s
-        url = UrlHelper.replace(
-            '%(url)s',
+        path = UrlHelper.replace(
+            '%(path)s',
             {'{%(resource_name_lc)s:id}': self.get_id()}
         )
 
         return self.__getProxy().delete(
-            url=SearchHelper.appendQuery(
-                url,
+            path=SearchHelper.appendQuery(
+                path,
                 %(url_params)s
             ),
             headers=%(headers_map_params_str_with_no_ct)s
diff --git a/src/codegen/templates/resourceupdatetemplate 
b/src/codegen/templates/resourceupdatetemplate
index f48a7c1..aab7bf4 100644
--- a/src/codegen/templates/resourceupdatetemplate
+++ b/src/codegen/templates/resourceupdatetemplate
@@ -1,10 +1,10 @@
     def update(self%(headers_method_params_str)s):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         result = self.__getProxy().update(
-            url=UrlHelper.replace(
-                url,
+            path=UrlHelper.replace(
+                path,
                 {'{%(resource_name_lc)s:id}': self.get_id()}
             ),
             body=ParseHelper.toXml(self.superclass),
diff --git a/src/codegen/templates/subcollectionaddtemplate 
b/src/codegen/templates/subcollectionaddtemplate
index 4da8370..8190602 100644
--- a/src/codegen/templates/subcollectionaddtemplate
+++ b/src/codegen/templates/subcollectionaddtemplate
@@ -1,11 +1,11 @@
     def add(self, %(resource_to_add)s%(headers_method_params_str)s):
 
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         result = self.__getProxy().add(
-            url=UrlHelper.replace(
-                url,
+            path=UrlHelper.replace(
+                path,
                 %(url_params)s
             ),
             body=ParseHelper.toXml(%(resource_to_add)s),
diff --git a/src/codegen/templates/subcollectiongettemplate 
b/src/codegen/templates/subcollectiongettemplate
index 1b1b55b..43c0514 100644
--- a/src/codegen/templates/subcollectiongettemplate
+++ b/src/codegen/templates/subcollectiongettemplate
@@ -1,14 +1,14 @@
     def get(self, name=None, %(headers_method_params_str)sid=None):
 
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         if id:
             try :
                 result = self.__getProxy().get(
-                    url=UrlHelper.append(
+                    path=UrlHelper.append(
                         UrlHelper.replace(
-                            url,
+                            path,
                             %(url_params_id)s
                         ),
                         id
@@ -27,8 +27,8 @@
                 raise err
         elif name:
             result = self.__getProxy().get(
-                url=UrlHelper.replace(
-                    url,
+                path=UrlHelper.replace(
+                    path,
                     %(url_params_name)s
                 ),
                 headers=%(headers_map_params_str)s
diff --git a/src/codegen/templates/subcollectionlisttemplate 
b/src/codegen/templates/subcollectionlisttemplate
index 1723c4e..06f5da8 100644
--- a/src/codegen/templates/subcollectionlisttemplate
+++ b/src/codegen/templates/subcollectionlisttemplate
@@ -1,10 +1,10 @@
     def list(self, **kwargs):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         result = self.__getProxy().get(
-            url=UrlHelper.replace(
-                url,
+            path=UrlHelper.replace(
+                path,
                 %(url_params)s
             )
         ).get_%(actual_resource_name_lc)s()
diff --git a/src/codegen/templates/subcollectionlistwithparamstemplate 
b/src/codegen/templates/subcollectionlistwithparamstemplate
index 1939149..deaf154 100644
--- a/src/codegen/templates/subcollectionlistwithparamstemplate
+++ b/src/codegen/templates/subcollectionlistwithparamstemplate
@@ -1,11 +1,11 @@
     def list(self, %(combined_method_params)s, **kwargs):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         result = self.__getProxy().get(
-            url=SearchHelper.appendQuery(
-                url=UrlHelper.replace(
-                    url=url,
+            path=SearchHelper.appendQuery(
+                path=UrlHelper.replace(
+                    url=path,
                     args=%(url_params)s
                 ),
                 qargs=%(url_query_params)s
diff --git a/src/codegen/templates/subresourceactiontemplate 
b/src/codegen/templates/subresourceactiontemplate
index a6a8f33..a374875 100644
--- a/src/codegen/templates/subresourceactiontemplate
+++ b/src/codegen/templates/subresourceactiontemplate
@@ -1,11 +1,11 @@
     def %(action_name)s(self%(add_method_params)s, 
%(body_type_lc)s=params.%(body_type)s()%(headers_method_params_str)s):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         result = self.__getProxy().request(
             method='%(method)s',
-            url=UrlHelper.replace(
-                url,
+            path=UrlHelper.replace(
+                path,
                 %(url_params)s
             ),
             body=ParseHelper.toXml(%(body_type_lc)s),
diff --git a/src/codegen/templates/subresourcecollectionactiontemplate 
b/src/codegen/templates/subresourcecollectionactiontemplate
index 8f00618..1db5fd0 100644
--- a/src/codegen/templates/subresourcecollectionactiontemplate
+++ b/src/codegen/templates/subresourcecollectionactiontemplate
@@ -1,11 +1,11 @@
     def %(action_name)s(self%(add_method_params)s, 
%(body_type_lc)s=params.%(body_type)s()%(headers_method_params_str)s):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         result = self.__getProxy().request(
             method='%(method)s',
-            url=UrlHelper.replace(
-                url,
+            path=UrlHelper.replace(
+                path,
                 {'{%(parent_resource_name_lc)s:id}' : 
self.parentclass.get_id()}
             ),
             body=ParseHelper.toXml(%(body_type_lc)s),
diff --git a/src/codegen/templates/subresourcedeletetemplate 
b/src/codegen/templates/subresourcedeletetemplate
index d1c5ba0..2f962d8 100644
--- a/src/codegen/templates/subresourcedeletetemplate
+++ b/src/codegen/templates/subresourcedeletetemplate
@@ -1,10 +1,10 @@
     def delete(self):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         return self.__getProxy().delete(
-            url=UrlHelper.replace(
-                url,
+            path=UrlHelper.replace(
+                path,
                 %(url_identifyiers)s
             ),
             headers={'Content-type':None}
diff --git a/src/codegen/templates/subresourcedeletewithbodytemplate 
b/src/codegen/templates/subresourcedeletewithbodytemplate
index e2ab415..610b307 100644
--- a/src/codegen/templates/subresourcedeletewithbodytemplate
+++ b/src/codegen/templates/subresourcedeletewithbodytemplate
@@ -1,9 +1,9 @@
     def delete(self, %(body_type_lc)s%(body_instance_str)s):
 %(docs)s
-        url = '%(url)s'
+        path = '%(path)s'
 
         return self.__getProxy().delete(
-            url=UrlHelper.replace(url,
+            path=UrlHelper.replace(path,
 %(url_identifyiers_with_body)s),
             body=ParseHelper.toXml(%(body_type_lc)s)
         )
diff --git 
a/src/codegen/templates/subresourcedeletewithurlparamsandbodytemplate 
b/src/codegen/templates/subresourcedeletewithurlparamsandbodytemplate
index 0a1553e..69d41c0 100644
--- a/src/codegen/templates/subresourcedeletewithurlparamsandbodytemplate
+++ b/src/codegen/templates/subresourcedeletewithurlparamsandbodytemplate
@@ -1,13 +1,13 @@
     def delete(self, %(body_type_lc)s%(body_instance_str)s, 
%(combined_method_params)s):
 %(docs)s
-        url = UrlHelper.replace(
-            '%(url)s',
+        path = UrlHelper.replace(
+            '%(path)s',
 %(url_identifyiers)s
         )
 
         return self.__getProxy().delete(
-            url=SearchHelper.appendQuery(
-                url,
+            path=SearchHelper.appendQuery(
+                path,
                 %(url_params)s
             ),
             body=ParseHelper.toXml(%(body_type_lc)s),
diff --git a/src/codegen/templates/subresourcedeletewithurlparamstemplate 
b/src/codegen/templates/subresourcedeletewithurlparamstemplate
index 9e36c0c..24e6a5a 100644
--- a/src/codegen/templates/subresourcedeletewithurlparamstemplate
+++ b/src/codegen/templates/subresourcedeletewithurlparamstemplate
@@ -1,13 +1,13 @@
     def delete(self, %(combined_method_params)s):
 %(docs)s
-        url = UrlHelper.replace(
-            '%(url)s',
+        path = UrlHelper.replace(
+            '%(path)s',
 %(url_identifyiers)s
         )
 
         return self.__getProxy().delete(
-            url=SearchHelper.appendQuery(
-                url,
+            path=SearchHelper.appendQuery(
+                path,
                 %(url_params)s
             ),
             headers=%(headers_map_params_str_with_no_ct)s
diff --git a/src/codegen/templates/subresourceupdatetemplate 
b/src/codegen/templates/subresourceupdatetemplate
index bd22a48..aa54037 100644
--- a/src/codegen/templates/subresourceupdatetemplate
+++ b/src/codegen/templates/subresourceupdatetemplate
@@ -1,8 +1,8 @@
     def update(self%(combined_method_params)s):
 %(docs)s
-        url = '%(url)s'
-        url = UrlHelper.replace(
-            url,
+        path = '%(path)s'
+        path = UrlHelper.replace(
+            path,
             %(url_identifiers_replacments)s
         )
 
diff --git a/src/codegen/utils/urlutils.py b/src/codegen/utils/urlutils.py
index c374a1f..83b381d 100644
--- a/src/codegen/utils/urlutils.py
+++ b/src/codegen/utils/urlutils.py
@@ -32,7 +32,6 @@
         url = link.href
         s_url = url.split('/')
         s_url.pop(0)
-        s_url.pop(0)
 
         return UrlUtils.__list_to_dict(s_url)
 
@@ -56,7 +55,6 @@
 
         url = link.href
         s_url = url.split('/')
-        s_url.pop(0)
         s_url.pop(0)
 
         if url.endswith('/' + link.rel):
diff --git a/src/codegen/xsd/abstractxsdcodegen.py 
b/src/codegen/xsd/abstractxsdcodegen.py
index 91f7ac7..81cd590 100644
--- a/src/codegen/xsd/abstractxsdcodegen.py
+++ b/src/codegen/xsd/abstractxsdcodegen.py
@@ -25,7 +25,7 @@
 
     __metaclass__ = abc.ABCMeta
 
-    SCHEMA_URI = '/api?schema'
+    SCHEMA_URI = '?schema'
 
     def __init__(self, path, api):
         '''
diff --git a/src/codegen/xsd/genparams.py b/src/codegen/xsd/genparams.py
index d725b36..f0b47cd 100755
--- a/src/codegen/xsd/genparams.py
+++ b/src/codegen/xsd/genparams.py
@@ -695,7 +695,7 @@
     genParser.handle_command(sys.argv[1:])
     outFile = genParser.getOutFile()
     # will support get the schema from the engine server
-    # contextmanager.get('proxy').request('GET', '/api?schema')
+    # contextmanager.get('proxy').request('GET', '?schema')
     schemaFile = genParser.getSchemaFile()
     logFile = genParser.getLogFile()
     tmpOutFile = outFile + r".in"
diff --git a/src/ovirtsdk/api.py b/src/ovirtsdk/api.py
index 0230377..d6c8158 100644
--- a/src/ovirtsdk/api.py
+++ b/src/ovirtsdk/api.py
@@ -20,7 +20,7 @@
 ############ GENERATED CODE ############
 ########################################
 
-'''Generated at: 2013-12-24 11:16:42.676341'''
+'''Generated at: 2014-01-16 20:13:22.031917'''
 
 import types
 import urlparse
@@ -61,7 +61,7 @@
                  renew_session=False, insecure=False, 
validate_cert_chain=True, filter=False, debug=False):  # @ReservedAssignment
 
         '''
-        @param url: server url (format "http/s://server[:port]/api")
+        @param url: server url (format 
"http/s://server[:port]/ovirt-engine/api")
         @param username: user (format user@domain)
         @param password: password
         [@param key_file: client PEM key_file for ssl enabled connection]
@@ -113,8 +113,13 @@
             debug=debug
         )
 
+        # Extract from the entry point URL the prefix common to paths
+        # of all requests:
+        prefix = urlparse.urlparse(url).path
+
         # Create the proxy:
         proxy = Proxy(
+            prefix,
             pool,
             persistent_auth
         )
@@ -131,7 +136,7 @@
         # Get entry point
         entry_point = proxy.request(
             method='GET',
-            url=urlparse.urlparse(url).path
+            path=""
         )
 
         # If server returns no response for the root resource, this is sign
@@ -207,7 +212,7 @@
                 try:
                     proxy.request(
                         method='GET',
-                        url='/api',
+                        path='',
                         last=True
                     )
                 except Exception:
@@ -226,7 +231,7 @@
             try :
                 proxy.request(
                     method='GET',
-                    url='/api'
+                    path=''
                 )
             except Exception, e:
                 if throw_exception: raise e
@@ -286,7 +291,7 @@
         if proxy:
             return proxy.request(
                 method='GET',
-                url='/api'
+                path=''
             ).summary
 
         raise DisconnectedError
@@ -296,7 +301,7 @@
         if proxy:
             return proxy.request(
                 method='GET',
-                url='/api'
+                path=''
             ).time
 
         raise DisconnectedError
diff --git a/src/ovirtsdk/infrastructure/proxy.py 
b/src/ovirtsdk/infrastructure/proxy.py
index caef125..7087c8b 100644
--- a/src/ovirtsdk/infrastructure/proxy.py
+++ b/src/ovirtsdk/infrastructure/proxy.py
@@ -23,11 +23,13 @@
     The proxy to web connection
     '''
 
-    def __init__(self, connections_pool, persistent_auth=True):
+    def __init__(self, prefix, connections_pool, persistent_auth=True):
         '''
+        @param prefix: the prefix common to all requests, usually 
/ovirt-engine/api
         @param connections_pool: connections pool
         @param persistent_auth: persistent authentication flag (default True)
         '''
+        self._prefix = prefix
         self.__connections_pool = connections_pool
         self._persistent_auth = persistent_auth
 
@@ -35,75 +37,78 @@
         # URL the host name, so that we can accept cookies only from that host:
         self._url = self.__connections_pool.get_url()
 
+    def getPrefix(self):
+        """Returns the prefix common to all requests."""
+        return self._prefix
+
     def getConnectionsPool(self):
         '''
         Returns connections pool
         '''
         return self.__connections_pool
 
-    def get(self, url, headers={}):
+    def get(self, path, headers={}):
         '''
         Performs get request
         
-        @param url: request URI
-        @param body: request body
+        @param path: request path
         @param headers: request headers
         '''
-        return self.request(method='GET', url=url, headers=headers)
+        return self.request('GET', path, headers)
 
-    def delete(self, url, body=None, headers={}):
+    def delete(self, path, body=None, headers={}):
         '''
         Performs delete request
         
-        @param url: request URI
+        @param path: request path
         @param body: request body
         @param headers: request headers
         '''
-        return self.request('DELETE', url, body, headers)
+        return self.request('DELETE', path, body, headers)
 
-    def update(self, url, body=None, headers={}):
+    def update(self, path, body=None, headers={}):
         '''
         Performs update request
         
-        @param url: request URI
+        @param path: request path
         @param body: request body
         @param headers: request headers
         '''
-        return self.request('PUT', url, body, headers)
+        return self.request('PUT', path, body, headers)
 
-    def add(self, url, body=None, headers={}):
+    def add(self, path, body=None, headers={}):
         '''
         Performs add request
         
-        @param url: request URI
+        @param path: request path
         @param body: request body
         @param headers: request headers
         '''
-        return self.request('POST', url, body, headers)
+        return self.request('POST', path, body, headers)
 
-    def action(self, url, body=None, headers={}):
+    def action(self, path, body=None, headers={}):
         '''
         Performs action request
         
-        @param url: request URI
+        @param path: request path
         @param body: request body
         @param headers: request headers
         '''
-        return self.request('POST', url, body, headers)
+        return self.request('POST', path, body, headers)
 
-    def request(self, method, url, body=None, headers={}, last=False, 
noParse=False):
+    def request(self, method, path, body=None, headers={}, last=False, 
noParse=False):
         '''
         Performs HTTP request
         
         @param method: HTTP method
-        @param url: request URI
+        @param path: request path
         @param body: request body
         @param headers: request headers
         @param last: disables persistence authentication
         @param noParse: disables xml2py conversion
         '''
         return self.__doRequest(method, \
-                                url, \
+                                path, \
                                 body=body, \
                                 headers=headers, \
                                 
conn=self.getConnectionsPool().getConnection(), \
@@ -111,12 +116,12 @@
                                 noParse=noParse,
                                 persistent_auth=self._persistent_auth)
 
-    def __doRequest(self, method, url, conn, body=None, headers={}, 
last=False, noParse=False, persistent_auth=True):
+    def __doRequest(self, method, path, conn, body=None, headers={}, 
last=False, noParse=False, persistent_auth=True):
         '''
         Performs HTTP request
         
         @param method: HTTP method
-        @param url: request URI
+        @param path: request path
         @param conn: connection to invoke request on
         @param body: request body
         @param headers: request headers
@@ -127,7 +132,7 @@
 
         response = conn.doRequest(
                    method=method,
-                   url=url,
+                   url=self._prefix + path,
                    body=body,
                    headers=headers,
                    last=last,


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I0e39510541e34349fce5a8ad4a643cf65784bccc
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to