Backwards compatibility with old descriptors; updated override flags in vnfd/nsd... 45/10045/2 sol006
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 27 Nov 2020 12:48:06 +0000 (12:48 +0000)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Fri, 27 Nov 2020 16:27:53 +0000 (16:27 +0000)
Change-Id: I40a4d033b6d2f07cdbd60e920d402dead35702d5
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
osmclient/common/utils.py
osmclient/scripts/osm.py
osmclient/sol005/vnfd.py

index 6d5ebd8..94bd72f 100644 (file)
@@ -73,6 +73,22 @@ def get_key_val_from_pkg(descriptor_file):
             result['type'] = 'nsd'
         else:
             result['type'] = 'vnfd'
+    if 'type' not in result:
+        for k1, v1 in list(dict.items()):
+            if not k1.endswith('-catalog'):
+                continue
+            for k2, v2 in v1.items():
+                if not k2.endswith('nsd') and not k2.endswith('vnfd'):
+                    continue
+                if 'nsd' in k2:
+                    result['type'] = 'nsd'
+                else:
+                    result['type'] = 'vnfd'
+                for entry in v2:
+                    for k3, v3 in list(entry.items()):
+                        # strip off preceeding chars before :
+                        key_name = k3.split(':').pop()
+                        result[key_name] = v3
 
     tar.close()
     return result
index dc93b7a..7d8695c 100755 (executable)
@@ -427,7 +427,7 @@ def nsd_list(ctx, filter, long):
         else:
             table = PrettyTable(['nsd name', 'id'])
         for nsd in resp:
-            name = nsd.get('name','-')
+            name = nsd.get('id','-')
             if long:
                 onb_state = nsd['_admin'].get('onboardingState','-')
                 op_state = nsd['_admin'].get('operationalState','-')
@@ -474,10 +474,10 @@ def pkg_repo_list(ctx, pkgtype, filter, repo, long):
     else:
         table = PrettyTable(['nfpkg name', 'repository'])
     for vnfd in resp:
-        name = vnfd.get('product-name', '-')
+        name = vnfd.get('id', vnfd.get('name','-'))
         repository = vnfd.get('repository')
         if long:
-            vendor = vnfd.get('provider')
+            vendor = vnfd.get('provider', vnfd.get('vendor'))
             version = vnfd.get('version')
             description = vnfd.get('description')
             latest = vnfd.get('latest')
@@ -514,27 +514,28 @@ def vnfd_list(ctx, nf_type, filter, long):
     fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__
     if fullclassname == 'osmclient.sol005.client.Client':
         if long:
-            table = PrettyTable(['nfpkg name', 'id', 'vendor', 'version', 'onboarding state', 'operational state',
+            table = PrettyTable(['nfpkg name', 'id', 'desc type', 'vendor', 'version', 'onboarding state', 'operational state',
                                   'usage state', 'date', 'last update'])
         else:
-            table = PrettyTable(['nfpkg name', 'id'])
+            table = PrettyTable(['nfpkg name', 'id', 'desc type'])
         for vnfd in resp:
-            name = vnfd['product-name'] if 'product-name' in vnfd else '-'
+            name = vnfd.get('id', vnfd.get('name','-'))
+            descriptor_type = 'sol005' if 'product-name' in vnfd else 'rel8'
             if long:
                 onb_state = vnfd['_admin'].get('onboardingState','-')
                 op_state = vnfd['_admin'].get('operationalState','-')
-                vendor = vnfd.get('provider')
+                vendor = vnfd.get('provider', vnfd.get('vendor'))
                 version = vnfd.get('version')
                 usage_state = vnfd['_admin'].get('usageState','-')
                 date = datetime.fromtimestamp(vnfd['_admin']['created']).strftime("%Y-%m-%dT%H:%M:%S")
                 last_update = datetime.fromtimestamp(vnfd['_admin']['modified']).strftime("%Y-%m-%dT%H:%M:%S")
-                table.add_row([name, vnfd['_id'], vendor, version, onb_state, op_state, usage_state, date, last_update])
+                table.add_row([name, vnfd['_id'], descriptor_type, vendor, version, onb_state, op_state, usage_state, date, last_update])
             else:
-                table.add_row([name, vnfd['_id']])
+                table.add_row([name, vnfd['_id'], descriptor_type])
     else:
         table = PrettyTable(['nfpkg name', 'id'])
         for vnfd in resp:
-            table.add_row([vnfd['product-name'], vnfd['id']])
+            table.add_row([vnfd['name'], vnfd['id']])
     table.align = 'l'
     print(table)
 
index 9eb18ca..f80c000 100644 (file)
@@ -67,6 +67,8 @@ class Vnfd(object):
             for vnfd in self.list():
                 if 'product-name' in vnfd and name == vnfd['product-name']:
                     return vnfd
+                elif 'name' in vnfd and name == vnfd['name']:
+                    return vnfd
         raise NotFound("vnfd {} not found".format(name))
 
     def get_individual(self, name):
@@ -194,40 +196,38 @@ class Vnfd(object):
 
                 for vcd_number, vcd in enumerate(vcd_list):
                     if override_epa:
-                        virtual_memory = {
-                            "mempage-size": "LARGE",
-                            "numa-node-policy": {
-                                "node-cnt": 1,
-                                "mem-policy": "STRICT"
-                            }
+                        virtual_memory = vcd["virtual-memory"]
+                        virtual_memory["mempage-size"] = "LARGE"
+                        virtual_memory["numa-enabled"] = True
+                        virtual_memory["numa-node-policy"] = {
+                            "node-cnt": 1,
+                            "mem-policy": "STRICT"
                         }
-                        virtual_cpu = {
-                            "pinning": {
-                                "policy": "static",
-                                "thread-policy": "PREFER"
-                            }
+                        virtual_cpu = vcd["virtual-cpu"]
+                        virtual_cpu["pinning"] = {
+                            "policy": "static",
+                            "thread-policy": "PREFER"
                         }
 
-                        memory_override_string = "virtual-compute-desc.{}.virtual-cpu={};"\
+                        cpu_override_string = "virtual-compute-desc.{}.virtual-cpu={};"\
                                                  .format(vcd_number, quote(yaml.safe_dump(virtual_cpu)))
-                        cpu_override_string = "virtual-compute-desc.{}.virtual-memory={};"\
+                        memory_override_string = "virtual-compute-desc.{}.virtual-memory={};"\
                                               .format(vcd_number, quote(yaml.safe_dump(virtual_memory)))
                         special_override_string = "{}{}{}".format(special_override_string,
                                                                   cpu_override_string, memory_override_string)
 
-                        headers['Query-String-Format'] = 'yaml'
+                    headers['Query-String-Format'] = 'yaml'
                     if override_nonepa:
-                        virtual_memory = {
-                            "mempage-size": "",
-                            "numa-node-policy": {}
-                        }
-                        virtual_cpu = {
-                            "pinning": {}
-                        }
+                        virtual_memory = vcd["virtual-memory"]
+                        virtual_memory["mempage-size"] = ""
+                        virtual_memory["numa-enabled"] = ""
+                        virtual_memory["numa-node-policy"] = {}
+                        virtual_cpu = vcd["virtual-cpu"]
+                        virtual_cpu["pinning"] = {}
 
-                        memory_override_string = "virtual-compute-desc.{}.virtual-cpu={};"\
+                        cpu_override_string = "virtual-compute-desc.{}.virtual-cpu={};"\
                                                  .format(vcd_number, quote(yaml.safe_dump(virtual_cpu)))
-                        cpu_override_string = "virtual-compute-desc.{}.virtual-memory={};"\
+                        memory_override_string = "virtual-compute-desc.{}.virtual-memory={};"\
                                               .format(vcd_number, quote(yaml.safe_dump(virtual_memory)))
                         special_override_string = "{}{}{}".format(special_override_string,
                                                                   cpu_override_string, memory_override_string)