bug fix vnfd composer; minor ui fix
[osm/LW-UI.git] / lib / osm / osm_util.py
index 12e567b..8cf6a4e 100644 (file)
@@ -38,8 +38,24 @@ class OsmUtil():
             if node_type == 'vnf_vl':
                 vnfd['internal-vld'] = [item for item in vnfd['internal-vld'] if item['id'] != element_id]
             if node_type == 'cp':
-                vnfd['connection-point'] = [item for item in vnfd['connection-point'] if item['name'] != element_id]
-
+                vnfd['connection-point'] = [item for item in vnfd['connection-point'] if item['name'] != args['name']]
+                for vdu in vnfd['vdu']:
+                    if 'interface' in vdu:
+                        vdu['interface'] = [item for item in vdu['interface'] if 'external-connection-point-ref' not in item
+                        or ('external-connection-point-ref'in item and item['external-connection-point-ref'] != args['name'])]
+            if node_type == 'vdu':
+                vdus = []
+                for vdu in vnfd['vdu']:
+                    if vdu['name'] != element_id:
+                        vdus.append(vdu)
+                    else:
+                        for intcp in vdu['internal-connection-point']:
+                            for intVld in vnfd['internal-vld']:
+                                intVld['internal-connection-point'] = [item for item in intVld['internal-connection-point']
+                                                                    if item['id-ref'] != intcp['id']]
+                vnfd['vdu'] = vdus
+            if node_type == 'int_cp':
+                OsmUtil.remove_int_cp(element_id, vnfd)
         return descriptor
 
     @staticmethod
@@ -54,14 +70,29 @@ class OsmUtil():
                 for k, v in enumerate(nsd['vld']):
                     if v['id'] == old['id']:
                         nsd['vld'][k].update(updated)
-                        print 'update here'
-                        print old
             elif node_type == 'vnf':
                 for k, v in enumerate(nsd['constituent-vnfd']):
                     if str(v['member-vnf-index']) == str(old['member-vnf-index']) and str(v['vnfd-id-ref']) == str(
                             old['vnfd-id-ref']):
                         print 'update here'
-                        print old
+        elif descriptor_type == 'vnfd':
+            if 'vnfd-catalog' in descriptor:
+                vnfd = descriptor['vnfd-catalog']['vnfd'][0]
+            elif 'vnfd:vnfd-catalog' in descriptor:
+                vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0]
+
+            if node_type == 'vnf_vl':
+                for k, v in enumerate(vnfd['internal-vld']):
+                    if v['id'] == old['id']:
+                        vnfd['internal-vld'][k].update(updated)
+            if node_type == 'cp':
+                for k, v in enumerate(vnfd['connection-point']):
+                    if v['name'] == old['name']:
+                        vnfd['connection-point'][k].update(updated)
+            if node_type == 'vdu':
+                for k, v in enumerate(vnfd['vdu']):
+                    if v['name'] == old['name']:
+                        vnfd['vdu'][k].update(updated)
 
         return descriptor
 
@@ -93,7 +124,7 @@ class OsmUtil():
             if node_type == 'cp':
                 for vld in nsd['vld']:
                     if vld['id'] == args['vld_id']:
-                        if'vnfd-connection-point-ref' not in vld:
+                        if 'vnfd-connection-point-ref' not in vld:
                             vld['vnfd-connection-point-ref'] = []
                         vld['vnfd-connection-point-ref'].append(
                             {
@@ -109,6 +140,8 @@ class OsmUtil():
             elif 'vnfd:vnfd-catalog' in descriptor:
                 vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0]
             if node_type == 'vdu':
+                if 'vdu' not in vnfd:
+                    vnfd['vdu'] = []
                 vnfd['vdu'].append({
                     "count": "1",
                     "description": "",
@@ -122,12 +155,16 @@ class OsmUtil():
                     "name": element_id
                 })
             if node_type == 'cp':
+                if 'connection-point' not in vnfd:
+                    vnfd['connection-point'] = []
                 vnfd['connection-point'].append({
                     "type": "VPORT",
                     "name": element_id
                 })
 
             if node_type == 'vnf_vl':
+                if 'internal-vld' not in vnfd:
+                    vnfd['internal-vld'] = []
                 vnfd['internal-vld'].append({
                     "short-name": element_id,
                     "name": element_id,
@@ -136,7 +173,46 @@ class OsmUtil():
                     "ip-profile-ref": "",
                     "id": element_id
                 })
-
+            if node_type == 'interface':
+                for vdu in vnfd['vdu']:
+                    if vdu['id'] == args['vdu_id']:
+                        vdu['interface'].append({
+                            "virtual-interface": {
+                                "type": "VIRTIO"
+                            },
+                            "name": element_id,
+                            "mgmt-interface": True,
+                            "type": "EXTERNAL",
+                            "external-connection-point-ref": args["external-connection-point-ref"]
+                        })
+            if node_type == 'int_cp':
+                for vdu in vnfd['vdu']:
+                    if vdu['id'] == args['vdu_id']:
+                        if 'internal-connection-point' not in vdu:
+                            vdu['internal-connection-point'] = []
+                        vdu['internal-connection-point'].append({
+                            "short-name": element_id,
+                            "type": "VPORT",
+                            "id": element_id,
+                            "name": element_id
+                        })
+                        if 'interface' not in vdu:
+                            vdu['interface'] = []
+                        vdu['interface'].append({
+                            "virtual-interface": {
+                                "type": "VIRTIO"
+                            },
+                            "name": "int_"+element_id,
+                            "type": "INTERNAL",
+                            "internal-connection-point-ref": element_id
+                        })
+                for int_vld in vnfd['internal-vld']:
+                    if int_vld['id'] == args['vld_id']:
+                        if 'internal-connection-point' not in int_vld:
+                            int_vld['internal-connection-point'] = []
+                        int_vld['internal-connection-point'].append({
+                            'id-ref': element_id
+                        })
         return descriptor
 
     @staticmethod
@@ -147,5 +223,27 @@ class OsmUtil():
             elif 'nsd:nsd-catalog' in descriptor:
                 nsd = descriptor['nsd:nsd-catalog']['nsd'][0]
             nsd.update(updated)
+        elif descriptor_type == 'vnfd':
+            if 'vnfd-catalog' in descriptor:
+                vnfd = descriptor['vnfd-catalog']['vnfd'][0]
+            elif 'vnfd:vnfd-catalog' in descriptor:
+                vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0]
+            vnfd.update(updated)
+
+        return descriptor
+
+    @staticmethod
+    def remove_int_cp(element_id, vnfd):
+        for vdu in vnfd['vdu']:
+            if 'interface' in vdu:
+                vdu['interface'] = [item for item in vdu['interface'] if 'internal-connection-point-ref' not in item
+                                    or ('internal-connection-point-ref' in item and item[
+                    'internal-connection-point-ref'] != element_id)]
+            if 'internal-connection-point' in vdu:
+                vdu['internal-connection-point'] = [item for item in vdu['internal-connection-point'] if
+                                                    item['id'] != element_id]
+        for intVld in vnfd['internal-vld']:
+            intVld['internal-connection-point'] = [item for item in intVld['internal-connection-point'] if
+                                                   item['id-ref'] != element_id]
 
-        return descriptor
\ No newline at end of file
+        return vnfd