incomplete support to user and project management
[osm/LW-UI.git] / lib / osm / osmclient / client.py
index 7a2d908..74b098f 100644 (file)
@@ -14,7 +14,7 @@ log = logging.getLogger('helper.py')
 
 
 class Client(object):
-    def __init__(self, host=os.getenv('OSM_SERVER', "localhost"), so_port=9999, so_project='admin', ro_host=None, ro_port=9090, **kwargs):
+    def __init__(self, host=os.getenv('OSM_SERVER', "localhost"), so_port=9999, so_project='admin', **kwargs):
 
         self._user = 'admin'
         self._password = 'admin'
@@ -77,6 +77,45 @@ class Client(object):
                                   json=vim_data)
         return None
 
+    def sdn_list(self):
+        token = self.get_token()
+        if token:
+            self._headers['Authorization'] = 'Bearer {}'.format(token)
+            self._headers['accept'] = 'application/json'
+            _url = "{0}/admin/v1/sdns".format(self._base_path)
+            return self._send_get(_url, headers=self._headers)
+
+    def sdn_delete(self, id):
+        token = self.get_token()
+        if token:
+            self._headers['Authorization'] = 'Bearer {}'.format(token)
+            self._headers['accept'] = 'application/json'
+            _url = "{0}/admin/v1/sdns/{1}".format(self._base_path, id)
+            return self._send_delete(_url, headers=self._headers)
+        return None
+
+    def sdn_get(self, id):
+        token = self.get_token()
+        if token:
+            self._headers['Authorization'] = 'Bearer {}'.format(token)
+            self._headers['accept'] = 'application/json'
+            _url = "{0}/admin/v1/sdns/{1}".format(self._base_path, id)
+            return self._send_get(_url, headers=self._headers)
+        return None
+
+    def sdn_create(self, sdn_data):
+        token = self.get_token()
+        headers = {}
+        if token:
+            headers['Authorization'] = 'Bearer {}'.format(token)
+            headers['Content-Type'] = 'application/json'
+            headers['accept'] = 'application/json'
+
+            _url = "{0}/admin/v1/sdns".format(self._base_path)
+            return self._send_post(_url, headers=headers,
+                                  json=sdn_data)
+        return None
+
     def nsd_list(self):
         token = self.get_token()
         if token:
@@ -212,13 +251,16 @@ class Client(object):
             return self._send_get(_url, headers=self._headers)
         return None
 
-    def ns_delete(self, id):
+    def ns_delete(self, id, force=None):
         token = self.get_token()
         if token:
             self._headers['Authorization'] = 'Bearer {}'.format(token)
-            #self._headers['Content-Type'] = 'application/yaml'
             self._headers['accept'] = 'application/json'
-            _url = "{0}/nslcm/v1/ns_instances_content/{1}".format(self._base_path, id)
+            query_path = ''
+            if force:
+                query_path = '?FORCE=true'
+            _url = "{0}/nslcm/v1/ns_instances_content/{1}{2}".format(self._base_path, id, query_path)
+
             return self._send_delete(_url, headers=self._headers)
         return None
 
@@ -259,6 +301,33 @@ class Client(object):
             return self._send_get(_url, headers=headers)
         return None
 
+    def ns_alarm_create(self, id, alarm_payload):
+        token = self.get_token()
+        headers = {}
+        if token:
+            headers['Authorization'] = 'Bearer {}'.format(token)
+            headers['Content-Type'] = 'application/json'
+#            headers['accept'] = 'application/json'
+
+            _url = "{0}/test/message/alarm_request".format(self._base_path)
+            return self._send_post(_url, headers=headers, json=alarm_payload)
+        return None
+
+    def ns_metric_export(self, id, metric_payload):
+
+        token = self.get_token()
+        headers = {}
+        if token:
+            headers['Authorization'] = 'Bearer {}'.format(token)
+            headers['Content-Type'] = 'application/json'
+            #headers['accept'] = 'application/json'
+            print "DIO"
+            _url = "{0}/test/message/metric_request".format(self._base_path)
+            print _url
+            return self._send_post(_url, headers=headers, json=metric_payload)
+        return None
+
+
     def vnfd_list(self):
         token = self.get_token()
         if token:
@@ -373,7 +442,12 @@ class Client(object):
             log.exception(e)
             #print "Exception during send POST"
             return {'error': 'error during connection to agent'}
-        return Util.json_loads_byteified(r.text)
+        if 'accept' in kwargs['headers']:
+            accept = kwargs['headers']['accept']
+            if accept == 'application/json':
+                #print "json"
+                return Util.json_loads_byteified(r.text)
+        return r
 
     def _send_put(self, url, data=None, json=None, **kwargs):
         try: