From 16bdd7cccf1966996c327ca14d1ce417ad1e7926 Mon Sep 17 00:00:00 2001 From: wangzh21 Date: Fri, 27 Jul 2018 17:48:41 +0800 Subject: [PATCH] Fix url_path 1. Replace /v1/deployables with /v1/accelerators/deployables. 2. Replace base_url with api_name. 3. Fix update body. Change-Id: I82bab30d4d880580755e176f751fd5a075975232 --- cyborgclient/v1/accelerators.py | 1 + cyborgclient/v1/basemodels.py | 11 ++++++----- cyborgclient/v1/deployables.py | 11 ++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cyborgclient/v1/accelerators.py b/cyborgclient/v1/accelerators.py index 9ef3146..f501025 100644 --- a/cyborgclient/v1/accelerators.py +++ b/cyborgclient/v1/accelerators.py @@ -24,4 +24,5 @@ class Accelerator(basemodels.BaseModel): class AcceleratorManager(basemodels.BaseModelManager): api_name = "accelerators" + base_url = "accelerators" resource_class = Accelerator diff --git a/cyborgclient/v1/basemodels.py b/cyborgclient/v1/basemodels.py index 19166d5..10e799c 100644 --- a/cyborgclient/v1/basemodels.py +++ b/cyborgclient/v1/basemodels.py @@ -33,15 +33,16 @@ class BaseModel(base.Resource): class BaseModelManager(base.Manager): - # api_name needs to be overridden by any derived class. - # api_name should be pluralized and lowercase, e.g. "clustertemplates", as - # it shows up in the URL path: "/v1/{api_name}" + # base_url needs to be overridden by any derived class. + # base_url should be pluralized and lowercase, e.g. "clustertemplates", as + # it shows up in the URL path: "/v1/{base_url}" api_name = '' + base_url = '' @classmethod def _path(cls, id=None): - return '/v1/' + cls.api_name + \ - '/%s' % id if id else '/v1/' + cls.api_name + return '/v1/' + cls.base_url + \ + '/%s' % id if id else '/v1/' + cls.base_url def list(self, limit=None, marker=None, sort_key=None, sort_dir=None, detail=False): diff --git a/cyborgclient/v1/deployables.py b/cyborgclient/v1/deployables.py index 0343153..40999e1 100644 --- a/cyborgclient/v1/deployables.py +++ b/cyborgclient/v1/deployables.py @@ -24,6 +24,7 @@ class Deployable(basemodels.BaseModel): class DeployableManager(basemodels.BaseModelManager): api_name = "deployables" + base_url = "accelerators/deployables" resource_class = Deployable def deallocation(self, deployable_uuid): @@ -32,12 +33,12 @@ class DeployableManager(basemodels.BaseModelManager): :param deployable_uuid: deployable_uuid which is attached to the instance. """ - body = {"op": "replace", "path": "/instance_uuid", "value": None} - resp = self._update("/deployables/%s" % deployable_uuid, body) + body = [{"op": "replace", "path": "/instance_uuid", "value": None}] + resp = self.update(deployable_uuid, body) return resp def allocation(self, deployable_uuid, instance_uuid): - body = {"op": "replace", "path": "/instance_uuid", - "value": instance_uuid} - resp = self._update("/deployables/%s" % deployable_uuid, body) + body = [{"op": "replace", "path": "/instance_uuid", + "value": instance_uuid}] + resp = self.update(deployable_uuid, body) return resp