From: garciadeblas Date: Thu, 10 May 2018 12:33:34 +0000 (+0200) Subject: support of PATCH method for sol005 client X-Git-Tag: v4.0.0~13 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fosmclient.git;a=commitdiff_plain;h=0a7f1259519c504ddb2b47b9c47b6c0543144145 support of PATCH method for sol005 client Change-Id: Ic8c6c4c9250aae0da486d298dc5f796c6b6a2350 Signed-off-by: garciadeblas --- 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']