support of PATCH method for sol005 client 18/6118/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 10 May 2018 12:33:34 +0000 (14:33 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 10 May 2018 12:33:34 +0000 (14:33 +0200)
Change-Id: Ic8c6c4c9250aae0da486d298dc5f796c6b6a2350
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/sol005/http.py
osmclient/sol005/vim.py

index d76e41e..60f0a49 100644 (file)
@@ -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()
index 0dcc4ad..d540c63 100644 (file)
@@ -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']