Reformats code on NSD and VNFD clients and fixes small validation bug on VNFD create...
[osm/osmclient.git] / osmclient / sol005 / project.py
index 39d2453..ed781fa 100644 (file)
@@ -20,8 +20,8 @@ OSM project mgmt API
 """
 
 from osmclient.common import utils
+from osmclient.common.exceptions import ClientException
 from osmclient.common.exceptions import NotFound
-from osmclient.common.exceptions import OsmHttpException
 import json
 import logging
 
@@ -43,14 +43,15 @@ class Project(object):
         self._logger.debug("")
         self._client.get_token()
         http_code, resp = self._http.post_cmd(endpoint=self._apiBase,
-                                              postfields_dict=project)
+                                              postfields_dict=project,
+                                              skip_query_admin=True)
         #print('HTTP CODE: {}'.format(http_code))
         #print('RESP: {}'.format(resp))
         #if http_code in (200, 201, 202, 204):
         if resp:
             resp = json.loads(resp)
         if not resp or 'id' not in resp:
-            raise OsmHttpException('unexpected response from server - {}'.format(
+            raise ClientException('unexpected response from server - {}'.format(
                                   resp))
         print(resp['id'])
         #else:
@@ -69,14 +70,15 @@ class Project(object):
         self._client.get_token()
         proj = self.get(project)
         http_code, resp = self._http.patch_cmd(endpoint='{}/{}'.format(self._apiBase, proj['_id']),
-                                             postfields_dict=project_changes)
+                                             postfields_dict=project_changes,
+                                             skip_query_admin=True)
         # print('HTTP CODE: {}'.format(http_code))
         # print('RESP: {}'.format(resp))
         if http_code in (200, 201, 202):
             if resp:
                 resp = json.loads(resp)
             if not resp or 'id' not in resp:
-                raise OsmHttpException('unexpected response from server - {}'.format(
+                raise ClientException('unexpected response from server - {}'.format(
                                       resp))
             print(resp['id'])
         elif http_code == 204:
@@ -100,7 +102,8 @@ class Project(object):
         if force:
             querystring = '?FORCE=True'
         http_code, resp = self._http.delete_cmd('{}/{}{}'.format(self._apiBase,
-                                                project['_id'], querystring))
+                                                project['_id'], querystring),
+                                                skip_query_admin=True)
         #print('HTTP CODE: {}'.format(http_code))
         #print('RESP: {}'.format(resp))
         if http_code == 202:
@@ -110,13 +113,13 @@ class Project(object):
         elif resp and 'result' in resp:
             print('Deleted')
         else:
-            msg = ""
-            if resp:
-                try:
-                    msg = json.loads(resp)
-                except ValueError:
-                    msg = resp
-            raise OsmHttpException("failed to delete project {} - {}".format(name, msg))
+            msg = resp or ""
+            if resp:
+                try:
+                    msg = json.loads(resp)
+                except ValueError:
+                    msg = resp
+            raise ClientException("failed to delete project {} - {}".format(name, msg))
 
     def list(self, filter=None):
         """Returns the list of OSM projects
@@ -126,7 +129,8 @@ class Project(object):
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
-        _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
+        _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string),
+                                                    skip_query_admin=True)
         #print('RESP: {}'.format(resp))
         if resp:
             return json.loads(resp)