fix bugs in vnf-list and vnf-show for sol005 client 78/6178/2
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 18 May 2018 13:33:29 +0000 (15:33 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Sat, 19 May 2018 23:05:15 +0000 (01:05 +0200)
Change-Id: Ia6368e2fbf358d4cfc4d46ed7856305f8bd80563
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/scripts/osm.py
osmclient/sol005/vnf.py

index fd92477..66d1f32 100755 (executable)
@@ -230,20 +230,39 @@ def vnf_list(ctx, ns):
     except ClientException as inst:
         print(inst.message)
         exit(1)
-    table = PrettyTable(
-        ['vnf name',
-         'id',
-         'operational status',
-         'config status'])
-    for vnfr in resp:
-        if 'mgmt-interface' not in vnfr:
-            vnfr['mgmt-interface'] = {}
-            vnfr['mgmt-interface']['ip-address'] = None
-        table.add_row(
-            [vnfr['name'],
-             vnfr['id'],
-             vnfr['operational-status'],
-             vnfr['config-status']])
+    fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__
+    if fullclassname == 'osmclient.sol005.client.Client':
+        table = PrettyTable(
+            ['vnf id',
+             'name',
+             'ns id',
+             'vnf member index',
+             'vnfd name',
+             'ip address'])
+        for vnfr in resp:
+            name = vnfr['name'] if 'name' in vnfr else '-'
+            table.add_row(
+                [vnfr['_id'],
+                 name,
+                 vnfr['nsr-id-ref'],
+                 vnfr['member-vnf-index-ref'],
+                 vnfr['vnfd-ref'],
+                 vnfr['ip-address']])
+    else:
+        table = PrettyTable(
+            ['vnf name',
+             'id',
+             'operational status',
+             'config status'])
+        for vnfr in resp:
+            if 'mgmt-interface' not in vnfr:
+                vnfr['mgmt-interface'] = {}
+                vnfr['mgmt-interface']['ip-address'] = None
+            table.add_row(
+                [vnfr['name'],
+                 vnfr['id'],
+                 vnfr['operational-status'],
+                 vnfr['config-status']])
     table.align = 'l'
     print(table)
 
index 0a1e44a..11d2057 100644 (file)
@@ -41,6 +41,7 @@ class Vnf(object):
             ns_instance = self._client.ns.get(ns)
             filter_string = '?nsr-id-ref={}'.format(ns_instance['_id'])
         resp = self._http.get_cmd('{}{}'.format(self._apiBase,filter_string))
+        #print 'RESP: {}'.format(resp)
         if resp:
             return resp
         return list()
@@ -50,7 +51,7 @@ class Vnf(object):
         """
         if utils.validate_uuid4(name):
             for vnf in self.list():
-                if vnf == vnf['_id']:
+                if name == vnf['_id']:
                     return vnf
         else:
             for vnf in self.list():
@@ -66,6 +67,7 @@ class Vnf(object):
                     vnf_id = vnf['_id']
                     break
         resp = self._http.get_cmd('{}/{}'.format(self._apiBase, vnf_id))
+        #print 'RESP: {}'.format(resp)
         if resp:
             return resp
         raise NotFound("vnf {} not found".format(name))