fix bug 768
[osm/LW-UI.git] / lib / osm / osmclient / clientv2.py
index 191385e..30cc1f4 100644 (file)
@@ -22,6 +22,7 @@ import StringIO
 from lib.util import Util
 import hashlib
 import os
+import re
 from requests.packages.urllib3.exceptions import InsecureRequestWarning
 
 requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
@@ -49,7 +50,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
 
         result['data'] = Util.json_loads_byteified(r.text)
@@ -66,13 +67,103 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
 
         result['data'] = Util.json_loads_byteified(r.text)
 
         return result
 
+    def role_list(self, token):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/json", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+
+        _url = "{0}/admin/v1/roles".format(self._base_path)
+        try:
+            r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        result['data'] = Util.json_loads_byteified(r.text)
+
+        return result
+
+    def role_create(self, token, role_data):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/json", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        _url = "{0}/admin/v1/roles".format(self._base_path)
+
+        try:
+            r = requests.post(_url, json=role_data, verify=False, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        result['data'] = Util.json_loads_byteified(r.text)
+        return result
+
+    def role_update(self, token, role_id, role_data):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/json", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        _url = "{0}/admin/v1/roles/{1}".format(self._base_path, role_id)
+        
+        try:
+            r = requests.put(_url, json=role_data, verify=False, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        else:
+            result['data'] = Util.json_loads_byteified(r.text)
+        return result
+    
+    def role_delete(self, token, id, force=None):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/json", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        query_path = ''
+        if force:
+            query_path = '?FORCE=true'
+        _url = "{0}/admin/v1/roles/{1}{2}".format(self._base_path, id, query_path)
+        try:
+            r = requests.delete(_url, params=None, verify=False, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        else:
+            result['data'] = Util.json_loads_byteified(r.text)
+        return result
+
+    def role_get(self, token, id):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/json", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        
+        _url = "{0}/admin/v1/roles/{1}".format(self._base_path, id)
+        try:
+            r = requests.get(_url, params=None, verify=False, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        result['data'] = Util.json_loads_byteified(r.text)
+        return result
+
     def user_list(self, token):
         result = {'error': True, 'data': ''}
         headers = {"Content-Type": "application/json", "accept": "application/json",
@@ -85,7 +176,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
@@ -104,7 +195,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -121,7 +212,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.no_content:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         else:
             result['data'] = Util.json_loads_byteified(r.text)
@@ -139,7 +230,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.no_content:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         else:
             result['data'] = Util.json_loads_byteified(r.text)
@@ -156,7 +247,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -173,7 +264,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
@@ -190,7 +281,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -209,7 +300,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -228,9 +319,8 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.no_content:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
-        result['data'] = Util.json_loads_byteified(r.text)
         return result
 
     def project_delete(self, token, id):
@@ -245,7 +335,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.no_content:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         else:
             result['data'] = Util.json_loads_byteified(r.text)
@@ -262,7 +352,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
@@ -279,7 +369,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data']  = Util.json2yaml(yaml.load(str(r.text)))
 
@@ -297,7 +387,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
@@ -317,7 +407,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
@@ -337,12 +427,29 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
         return result
 
+    def nsi_list(self, token):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/yaml", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        _url = "{0}/nsilcm/v1/netslice_instances".format(self._base_path)
+        try:
+            r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        result['data'] = Util.json_loads_byteified(r.text)
+
+        return result
+    
     def ns_list(self, token):
         result = {'error': True, 'data': ''}
         headers = {"Content-Type": "application/yaml", "accept": "application/json",
@@ -354,7 +461,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
@@ -371,7 +478,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
@@ -388,7 +495,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
@@ -406,7 +513,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.no_content:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         
         return result
@@ -423,9 +530,10 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r:
             result['error'] = False
-        result['data'] = Util.json_loads_byteified(r.text)
+        if r.status_code != requests.codes.no_content:
+            result['data'] = Util.json_loads_byteified(r.text)
         return result
 
     def vnfd_delete(self, token, id):
@@ -462,7 +570,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -482,7 +590,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -502,7 +610,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -522,7 +630,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['data'] = r.json()
             result['error'] = False
         if r.status_code == requests.codes.conflict:
@@ -543,7 +651,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['data'] = r.json()
             result['error'] = False
         if r.status_code == requests.codes.conflict:
@@ -570,7 +678,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         if r.status_code == requests.codes.conflict:
             result['data'] = "Invalid ID."
@@ -598,7 +706,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         if r.status_code == requests.codes.conflict:
             result['data'] = "Invalid ID."
@@ -616,7 +724,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.no_content:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         return result
 
@@ -641,7 +749,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.no_content:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         else:
             try:
@@ -672,7 +780,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.no_content:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         else:
             try:
@@ -694,7 +802,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
             tarf = StringIO.StringIO(r.content)
             return tarf
@@ -711,7 +819,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
             tarf = StringIO.StringIO(r.content)
             return tarf
@@ -719,10 +827,10 @@ class Client(object):
 
     def _descriptor_update(self, tarf, data):
         # extract the package on a tmp directory
-        tarf.extractall('/tmp')
-
+        tarf.extractall('/tmp') 
+        regex = re.compile(r"^[^/]+(/[^/]+\.(yaml|yml))$", re.U)
         for name in tarf.getnames():
-            if name.endswith(".yaml") or name.endswith(".yml"):
+            if regex.match(name):
                 with open('/tmp/' + name, 'w') as outfile:
                     yaml.safe_dump(data, outfile, default_flow_style=False)
                 break
@@ -833,7 +941,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
             return yaml.load(r.text)
         else:
@@ -854,7 +962,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
             return yaml.load(r.text)
         else:
@@ -875,7 +983,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
             result['data'] = r.text
         else:
@@ -897,7 +1005,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
             result['data'] = r.text
         else:
@@ -908,6 +1016,24 @@ class Client(object):
 
         return result
 
+    def nsi_create(self, token, nsi_data):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/yaml", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+
+        _url = "{0}/nsilcm/v1/netslice_instances_content".format(self._base_path)
+
+        try:
+            r = requests.post(_url, json=nsi_data, verify=False, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        result['data'] = Util.json_loads_byteified(r.text)
+        return result
+
     def ns_create(self, token, ns_data):
         result = {'error': True, 'data': ''}
         headers = {"Content-Type": "application/yaml", "accept": "application/json",
@@ -921,7 +1047,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -939,7 +1065,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -956,7 +1082,25 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        result['data'] = Util.json_loads_byteified(r.text)
+
+        return result
+
+    def nsi_op_list(self, token, id):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/json", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        _url = "{0}/nsilcm/v1/nsi_lcm_op_occs/?netsliceInstanceId={1}".format(self._base_path, id)
+
+        try:
+            r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
@@ -974,7 +1118,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
@@ -993,11 +1137,31 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
 
+    def nsi_delete(self, token, id, force=None):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/yaml", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        query_path = ''
+        if force:
+            query_path = '?FORCE=true'
+        _url = "{0}/nsilcm/v1/netslice_instances_content/{1}{2}".format(self._base_path, id, query_path)
+        try:
+            r = requests.delete(_url, params=None, verify=False, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r:
+            result['error'] = False
+        if r.status_code != requests.codes.no_content:
+            result['data'] = Util.json_loads_byteified(r.text)
+        return result
+
     def ns_delete(self, token, id, force=None):
         result = {'error': True, 'data': ''}
         headers = {"Content-Type": "application/yaml", "accept": "application/json",
@@ -1035,6 +1199,23 @@ class Client(object):
             result['data'] = Util.json_loads_byteified(r.text)
         return result
 
+    def nsi_get(self, token, id):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/json", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        _url = "{0}/nsilcm/v1/netslice_instances/{1}".format(self._base_path, id)
+
+        try:
+            r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        result['data'] = Util.json_loads_byteified(r.text)
+        return result
+
     def ns_get(self, token, id):
         result = {'error': True, 'data': ''}
         headers = {"Content-Type": "application/json", "accept": "application/json",
@@ -1047,7 +1228,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -1064,7 +1245,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -1081,7 +1262,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -1097,7 +1278,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         # result['data'] = Util.json_loads_byteified(r.text)
         result['data'] = r.text
@@ -1114,12 +1295,29 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         # result['data'] = Util.json_loads_byteified(r.text)
         result['data'] = r.text
         return result
 
+    def wim_list(self, token):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/yaml", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        _url = "{0}/admin/v1/wim_accounts".format(self._base_path)
+        try:
+            r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        result['data'] = Util.json_loads_byteified(r.text)
+
+        return result
+
     def vim_list(self, token):
         result = {'error': True, 'data': ''}
         headers = {"Content-Type": "application/yaml", "accept": "application/json",
@@ -1131,12 +1329,29 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
 
         return result
 
+    def wim_delete(self, token, id):
+        result = {'error': True, 'data': ''}
+        headers = {"accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        _url = "{0}/admin/v1/wim_accounts/{1}".format(self._base_path, id)
+        try:
+            r = requests.delete(_url, params=None, verify=False, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        else:
+            result['data'] = r.text
+        return result
+
     def vim_delete(self, token, id):
         result = {'error': True, 'data': ''}
         headers = {"accept": "application/json",
@@ -1148,12 +1363,30 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.accepted:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         else:
             result['data'] = r.text
         return result
 
+    def wim_get(self, token, id):
+
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/json", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+        _url = "{0}/admin/v1/wim_accounts/{1}".format(self._base_path, id)
+
+        try:
+            r = requests.get(_url, params=None, verify=False, stream=True, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        result['data'] = Util.json_loads_byteified(r.text)
+        return result
+
     def vim_get(self, token, id):
 
         result = {'error': True, 'data': ''}
@@ -1167,7 +1400,25 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
+            result['error'] = False
+        result['data'] = Util.json_loads_byteified(r.text)
+        return result
+
+    def wim_create(self, token, wim_data):
+        result = {'error': True, 'data': ''}
+        headers = {"Content-Type": "application/json", "accept": "application/json",
+                   'Authorization': 'Bearer {}'.format(token['id'])}
+
+        _url = "{0}/admin/v1/wim_accounts".format(self._base_path)
+
+        try:
+            r = requests.post(_url, json=wim_data, verify=False, headers=headers)
+        except Exception as e:
+            log.exception(e)
+            result['data'] = str(e)
+            return result
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -1186,7 +1437,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -1202,7 +1453,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -1218,7 +1469,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.accepted:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         else:
             result['data'] = r.text
@@ -1236,7 +1487,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.ok:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result
@@ -1254,7 +1505,7 @@ class Client(object):
             log.exception(e)
             result['data'] = str(e)
             return result
-        if r.status_code == requests.codes.created:
+        if r.status_code in (200, 201, 202, 204):
             result['error'] = False
         result['data'] = Util.json_loads_byteified(r.text)
         return result