From 353d932020025be4f4a8cfa909a7709564205ad3 Mon Sep 17 00:00:00 2001 From: zhangbailin Date: Tue, 10 Mar 2020 19:22:26 +0800 Subject: [PATCH] Optimize device profiles APIs Make ""DeviceProfileCollection" inherit ""DeviceProfile"" and delete the @classmethod decorator of the current method, the decorator does not work here. nit: Rename two functions, change get_api_obj() to get_device_profile(), change get_api_objs() to get_device_profiles(). Change-Id: Id0b0d00799ba16bf9b86747908ce3f373b65bb5b --- cyborg/api/controllers/v2/device_profiles.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/cyborg/api/controllers/v2/device_profiles.py b/cyborg/api/controllers/v2/device_profiles.py index 2fac34cd..2ba39b87 100644 --- a/cyborg/api/controllers/v2/device_profiles.py +++ b/cyborg/api/controllers/v2/device_profiles.py @@ -59,8 +59,7 @@ class DeviceProfile(base.APIBase): a device profile. See module notes above. """ - @classmethod - def get_api_obj(cls, obj_devprof): + def get_device_profile(self, obj_devprof): api_obj = {} for field in ['name', 'description', 'uuid', 'groups']: api_obj[field] = obj_devprof[field] @@ -72,18 +71,18 @@ class DeviceProfile(base.APIBase): return api_obj -class DeviceProfileCollection(object): +class DeviceProfileCollection(DeviceProfile): """API representation of a collection of device profiles.""" - @classmethod - def get_api_objs(cls, obj_devprofs): + def get_device_profiles(self, obj_devprofs): api_obj_devprofs = [ - DeviceProfile.get_api_obj(obj_devprof) + self.get_device_profile(obj_devprof) for obj_devprof in obj_devprofs] return api_obj_devprofs -class DeviceProfilesController(base.CyborgController): +class DeviceProfilesController(base.CyborgController, + DeviceProfileCollection): """REST controller for Device Profiles.""" @policy.authorize_wsgi("cyborg:device_profile", "create", False) @@ -116,7 +115,7 @@ class DeviceProfilesController(base.CyborgController): new_devprof = pecan.request.conductor_api.device_profile_create( context, obj_devprof) - ret = DeviceProfile.get_api_obj(new_devprof) + ret = self.get_device_profile(new_devprof) return wsme.api.Response(ret, status_code=http_client.CREATED, return_type=wsme.types.DictType) @@ -162,7 +161,7 @@ class DeviceProfilesController(base.CyborgController): if devprof['uuid'] == uuid] obj_devprofs = new_obj_devprofs - api_obj_devprofs = DeviceProfileCollection.get_api_objs(obj_devprofs) + api_obj_devprofs = self.get_device_profiles(obj_devprofs) return api_obj_devprofs