From d192a5aa92da630872a113b8e1459055f859cdf2 Mon Sep 17 00:00:00 2001 From: garciadeblas Date: Thu, 10 May 2018 14:33:34 +0200 Subject: [PATCH] support of PATCH method for sol005 client Change-Id: Ic8c6c4c9250aae0da486d298dc5f796c6b6a2350 Signed-off-by: garciadeblas --- osmclient/sol005/http.py | 16 +++++++++++++--- osmclient/sol005/vim.py | 11 ++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/osmclient/sol005/http.py b/osmclient/sol005/http.py index d76e41e..60f0a49 100644 --- a/osmclient/sol005/http.py +++ b/osmclient/sol005/http.py @@ -56,11 +56,13 @@ class Http(http.Http): def send_cmd(self, endpoint='', postfields_dict=None, formfile=None, filename=None, - put_method=False): + put_method=False, patch_method=False): data = BytesIO() curl_cmd = self._get_curl_cmd(endpoint) if put_method: curl_cmd.setopt(pycurl.PUT, 1) + elif patch_method: + curl_cmd.setopt(pycurl.CUSTOMREQUEST, "PATCH") else: curl_cmd.setopt(pycurl.POST, 1) curl_cmd.setopt(pycurl.WRITEFUNCTION, data.write) @@ -104,7 +106,7 @@ class Http(http.Http): postfields_dict=postfields_dict, formfile=formfile, filename=filename, - put_method=False) + put_method=False, patch_method=False) def put_cmd(self, endpoint='', postfields_dict=None, formfile=None, filename=None): @@ -112,7 +114,15 @@ class Http(http.Http): postfields_dict=postfields_dict, formfile=formfile, filename=filename, - put_method=True) + put_method=True, patch_method=False) + + def patch_cmd(self, endpoint='', postfields_dict=None, + formfile=None, filename=None): + return self.send_cmd(endpoint=endpoint, + postfields_dict=postfields_dict, + formfile=formfile, + filename=filename, + put_method=False, patch_method=True) def get2_cmd(self, endpoint): data = BytesIO() diff --git a/osmclient/sol005/vim.py b/osmclient/sol005/vim.py index 0dcc4ad..d540c63 100644 --- a/osmclient/sol005/vim.py +++ b/osmclient/sol005/vim.py @@ -59,13 +59,14 @@ class Vim(object): def update(self, vim_name, vim_account): vim = self.get(vim_name) - resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']), + #resp = self._http.put_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']), + resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase,vim['_id']), postfields_dict=vim_account) - if not resp or '_id' not in resp: - raise ClientException('failed to update vim: '.format( - resp)) + #print 'RESP: {}'.format(resp) + if not resp or 'id' not in resp: + raise ClientException('failed to update vim: '.format(resp)) else: - print resp['_id'] + print resp['id'] def update_vim_account_dict(self, vim_account, vim_access): vim_account['vim_type'] = vim_access['vim-type'] -- 2.25.1