Fix Bug 934. OSM CLI crashes for listing operations with insufficient permissions
[osm/osmclient.git] / osmclient / sol005 / vnf.py
index 6da13f5..d0c87b8 100644 (file)
@@ -20,13 +20,15 @@ OSM vnf API handling
 
 from osmclient.common import utils
 from osmclient.common.exceptions import NotFound
-
+import logging
+import json
 
 class Vnf(object):
 
     def __init__(self, http=None, client=None):
         self._http = http
         self._client = client
+        self._logger = logging.getLogger('osmclient')
         self._apiName = '/nslcm'
         self._apiVersion = '/v1'
         self._apiResource = '/vnfrs'
@@ -36,6 +38,8 @@ class Vnf(object):
     def list(self, ns=None, filter=None):
         """Returns a list of VNF instances
         """
+        self._logger.debug("")
+        self._client.get_token()
         filter_string = ''
         if filter:
             filter_string = '?{}'.format(filter)
@@ -45,15 +49,17 @@ class Vnf(object):
                 filter_string += ',nsr-id-ref={}'.format(ns_instance['_id'])
             else:
                 filter_string = '?nsr-id-ref={}'.format(ns_instance['_id'])
-        resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+        _, resp = self._http.get2_cmd('{}{}'.format(self._apiBase,filter_string))
         #print('RESP: {}'.format(resp))
         if resp:
-            return resp
+            return json.loads(resp)
         return list()
 
     def get(self, name):
         """Returns a VNF instance based on name or id
         """
+        self._logger.debug("")
+        self._client.get_token()
         if utils.validate_uuid4(name):
             for vnf in self.list():
                 if name == vnf['_id']:
@@ -65,15 +71,17 @@ class Vnf(object):
         raise NotFound("vnf {} not found".format(name))
 
     def get_individual(self, name):
+        self._logger.debug("")
+        self._client.get_token()
         vnf_id = name
         if not utils.validate_uuid4(name):
             for vnf in self.list():
                 if name == vnf['name']:
                     vnf_id = vnf['_id']
                     break
-        resp = self._http.get_cmd('{}/{}'.format(self._apiBase, vnf_id))
+        _, resp = self._http.get2_cmd('{}/{}'.format(self._apiBase, vnf_id))
         #print('RESP: {}'.format(resp))
         if resp:
-            return resp
+            return json.loads(resp)
         raise NotFound("vnf {} not found".format(name))