Michael Pasternak has uploaded a new change for review. Change subject: sdk: Cannot fetch the disk using /alias #865407 ......................................................................
sdk: Cannot fetch the disk using /alias #865407 https://bugzilla.redhat.com/show_bug.cgi?id=865407 Change-Id: I2de5c7fcd8be7d2800a07b56b6171434bfa9be97 Signed-off-by: Michael Pasternak <[email protected]> --- M src/codegen/collection/collection.py A src/codegen/collection/collectionexceptions.py M src/ovirtsdk/infrastructure/brokers.py 3 files changed, 97 insertions(+), 31 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/51/8551/1 diff --git a/src/codegen/collection/collection.py b/src/codegen/collection/collection.py index 37fcc55..7db9f07 100644 --- a/src/codegen/collection/collection.py +++ b/src/codegen/collection/collection.py @@ -23,6 +23,7 @@ from codegen.doc.documentation import Documentation from codegen.utils.paramutils import ParamUtils from codegen.utils.headerutils import HeaderUtils +from codegen.collection.collectionexceptions import CollectionExceptions class Collection(object): @@ -54,31 +55,16 @@ #fully comply with RESTful collection pattern, but preserved #in sake of backward compatibility if url == '/api/capabilities': - return \ -""" - def get(self, id=None, **kwargs): - ''' - [@param id: string (the id of the entity)] - [@param **kwargs: dict (property based filtering)] + return CollectionExceptions.get(url, link, prms_str, method_params, url_params, + headers_method_params_str, headers_map_params_str, + collection_get_template_values) - @return VersionCaps: - ''' - - url = '/api/capabilities' - - if id: - try : - return VersionCaps(self._getProxy().get(url=UrlHelper.append(url, id))) - except RequestError, err: - if err.status and err.status == 404: - return None - raise err - elif kwargs: - result = self._getProxy().get(url=url).version - return VersionCaps(FilterHelper.getItem(FilterHelper.filter(result, kwargs))) - else: - raise MissingParametersError(['id', 'kwargs']) -""" + # /api/disks search-by-name paradigm was broken by the engine + #should be fixed later on + if url == '/api/disks': + return CollectionExceptions.get(url, link, prms_str, method_params, url_params, + headers_method_params_str, headers_map_params_str, + collection_get_template_values) if 'search:query' in url_params: return \ diff --git a/src/codegen/collection/collectionexceptions.py b/src/codegen/collection/collectionexceptions.py new file mode 100644 index 0000000..6d69f0f --- /dev/null +++ b/src/codegen/collection/collectionexceptions.py @@ -0,0 +1,80 @@ +# +# Copyright (c) 2010 Red Hat, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +#============================================================ +#=======================COLLECTION RESOURCE================== +#============================================================ + +from codegen.doc.documentation import Documentation + +class CollectionExceptions(object): + + @staticmethod + def get(url, 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': + return \ +""" + def get(self, id=None, **kwargs): + ''' + [@param id: string (the id of the entity)] + [@param **kwargs: dict (property based filtering)] + + @return VersionCaps: + ''' + + url = '/api/capabilities' + + if id: + try : + return VersionCaps(self._getProxy().get(url=UrlHelper.append(url, id))) + except RequestError, err: + if err.status and err.status == 404: + return None + raise err + elif kwargs: + result = self._getProxy().get(url=url).version + return VersionCaps(FilterHelper.getItem(FilterHelper.filter(result, kwargs))) + else: + raise MissingParametersError(['id', 'kwargs']) +""" + + if url == '/api/disks': + return \ + (" def get(self, alias=None, " + headers_method_params_str + "id=None):\n" + \ + Documentation.document(link, {'alias: string (the alias of the entity)': False, + 'id : string (the id of the entity)' : False}) + + " url = '%(url)s'\n\n" + \ + + " if id:\n" + + " try :\n" + \ + " return %(resource_type)s(self._getProxy().get(url=UrlHelper.append(url, id),\n" + " headers=" + headers_map_params_str + "))\n" + + " except RequestError, err:\n" + \ + " if err.status and err.status == 404:\n" + \ + " return None\n" + \ + " raise err\n" + \ + " elif alias:\n" + + " result = self._getProxy().get(url=SearchHelper.appendQuery(url, {'search:query':'alias='+alias,'max:matrix':-1}),\n" + " headers=" + headers_map_params_str + ").get_%(resource_name_lc)s()\n" + \ + " return %(resource_type)s(FilterHelper.getItem(result))\n" + \ + " else:\n" + \ + " raise MissingParametersError(['id', 'alias'])\n\n") % collection_get_template_values \ No newline at end of file diff --git a/src/ovirtsdk/infrastructure/brokers.py b/src/ovirtsdk/infrastructure/brokers.py index 6f84c89..2781404 100644 --- a/src/ovirtsdk/infrastructure/brokers.py +++ b/src/ovirtsdk/infrastructure/brokers.py @@ -19,7 +19,7 @@ ############ GENERATED CODE ############ ######################################## -'''Generated at: 2012-10-15 09:39:53.954481''' +'''Generated at: 2012-10-15 12:52:57.174268''' from ovirtsdk.xml import params from ovirtsdk.utils.urlhelper import UrlHelper @@ -1365,10 +1365,10 @@ headers={"Expect":expect, "Correlation-Id":correlation_id}) return Disk(result) - def get(self, name=None, id=None): + def get(self, alias=None, id=None): ''' - [@param id : string (the id of the entity)] - [@param name: string (the name of the entity)] + [@param id : string (the id of the entity)] + [@param alias: string (the alias of the entity)] @return Disks: ''' @@ -1383,12 +1383,12 @@ if err.status and err.status == 404: return None raise err - elif name: - result = self._getProxy().get(url=SearchHelper.appendQuery(url, {'search:query':'name='+name,'max:matrix':-1}), + elif alias: + result = self._getProxy().get(url=SearchHelper.appendQuery(url, {'search:query':'alias='+alias,'max:matrix':-1}), headers={}).get_disk() return Disk(FilterHelper.getItem(result)) else: - raise MissingParametersError(['id', 'name']) + raise MissingParametersError(['id', 'alias']) def list(self, query=None, case_sensitive=True, max=None, **kwargs): ''' -- To view, visit http://gerrit.ovirt.org/8551 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2de5c7fcd8be7d2800a07b56b6171434bfa9be97 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-sdk Gerrit-Branch: master Gerrit-Owner: Michael Pasternak <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
