fix missing vnfd composer constraint 35/6935/1
authorlombardofr <lombardo@everyup.it>
Tue, 20 Nov 2018 22:47:32 +0000 (23:47 +0100)
committerlombardofr <lombardo@everyup.it>
Tue, 20 Nov 2018 22:47:32 +0000 (23:47 +0100)
Change-Id: I58644c97076cf87fe82017cb10a072db21fecab6
Signed-off-by: lombardofr <lombardo@everyup.it>
descriptorhandler/views.py
lib/osm/osm_rdcl_parser.py
lib/osm/osm_util.py
static/src/descriptorhandler/composer.js

index 1bdb9b4..1cf6906 100644 (file)
@@ -137,6 +137,24 @@ def addElement(request, descriptor_type=None, descriptor_id=None, element_type=N
 
         return __response_handler(request, result_graph, url=None, status=200)
 
+    elif descriptor_type == 'vnfd':
+        descriptor_result = client.vnfd_get(user.get_token(), descriptor_id)
+        element_id = request.POST.get('id', '')
+        util = OsmUtil()
+        descriptor_updated = util.add_base_node('vnfd', descriptor_result, element_type, element_id, request.POST.dict())
+        result = client.vnfd_update(user.get_token(), descriptor_id, descriptor_updated)
+        if result['error'] == True:
+            return __response_handler(request, result['data'], url=None,
+                                      status=result['data']['status'] if 'status' in result['data'] else 500)
+        else:
+            parser = OsmParser()
+            # print nsr_object
+            if descriptor_type == 'vnfd':
+                result_graph = parser.vnfd_to_graph(descriptor_updated)
+
+        return __response_handler(request, result_graph, url=None, status=200)
+
+
 @login_required
 def removeElement(request, descriptor_type=None, descriptor_id=None, element_type=None):
     user = osmutils.get_user(request)
index 84814f2..ab62688 100644 (file)
@@ -267,9 +267,30 @@ class OsmParser(RdclGraph):
             "layer": {
                 "vnfd": {
                     "nodes": {
-                        "vdu": {},
-                        "cp": {},
-                        "int_cp": {},
+                        "vdu": {
+                            "addable": {
+                                "callback": "addNode"
+                            },
+                            "removable": {
+                                "callback": "removeNode"
+                            }
+                        },
+                        "cp": {
+                            "addable": {
+                                "callback": "addNode"
+                            },
+                            "removable": {
+                                "callback": "removeNode"
+                            }
+                        },
+                        "int_cp": {
+                            "addable": {
+                                "callback": "addNode"
+                            },
+                            "removable": {
+                                "callback": "removeNode"
+                            }
+                        },
                         "vnf_vl": {
                             "addable": {
                                 "callback": "addNode"
@@ -287,9 +308,6 @@ class OsmParser(RdclGraph):
                                 },
                                 "int_cp": {
                                     "direct_edge": False,
-                                },
-                                "vnf_vl": {
-                                    "direct_edge": False,
                                 }
                             }
                         },
@@ -312,7 +330,7 @@ class OsmParser(RdclGraph):
                         },
                         "vnf_vl": {
                             "destination": {
-                                "vdu": {
+                                "int_cp": {
                                     "direct_edge": False
                                 }
                             }
index 5d314ce..12e567b 100644 (file)
@@ -29,6 +29,16 @@ class OsmUtil():
                                                             str(item['member-vnf-index-ref']) != str(
                                                                 args['member-vnf-index-ref']) or str(
                                                                 item['vnfd-id-ref']) != str(args['vnfd-id-ref'])]
+        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':
+                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]
 
         return descriptor
 
@@ -92,6 +102,41 @@ class OsmUtil():
                                 "vnfd-id-ref": args['vnfd-id-ref']
                             },
                         )
+
+        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 == 'vdu':
+                vnfd['vdu'].append({
+                    "count": "1",
+                    "description": "",
+                    "monitoring-param": [],
+                    "internal-connection-point": [],
+                    "image": "ubuntu",
+                    "cloud-init-file": "",
+                    "vm-flavor": {},
+                    "interface": [],
+                    "id": element_id,
+                    "name": element_id
+                })
+            if node_type == 'cp':
+                vnfd['connection-point'].append({
+                    "type": "VPORT",
+                    "name": element_id
+                })
+
+            if node_type == 'vnf_vl':
+                vnfd['internal-vld'].append({
+                    "short-name": element_id,
+                    "name": element_id,
+                    "internal-connection-point": [],
+                    "type": "ELAN",
+                    "ip-profile-ref": "",
+                    "id": element_id
+                })
+
         return descriptor
 
     @staticmethod
index d56e22f..4b8bfd5 100644 (file)
@@ -118,7 +118,7 @@ function initDropOnGraph() {
 
         var nodetype = $('#' + elemet_id).attr('type-name');
         var random_name = nodetype + "_" + generateUID();
-
+        console.log(nodetype)
         var node_information = {
             'id': random_name,
             'info': {
@@ -134,21 +134,17 @@ function initDropOnGraph() {
             'x': e.layerX,
             'y': e.layerY
         };
-        if (nodetype === 'ns_vl') {
 
-            graph_editor.addNode(node_information, function () {
-                console.log("OK")
-            }, function (error) {
-                showAlert(error)
-            })
-        } else if (nodetype === 'vnf') {
+        if (nodetype === 'vnf') {
             node_information['id'] = $('#' + elemet_id).attr('desc_id');
-            graph_editor.addNode(node_information, function () {
-                console.log("OK")
-            }, function (error) {
-                showAlert(error)
-            })
         }
+
+        graph_editor.addNode(node_information, function () {
+            console.log("OK")
+        }, function (error) {
+            showAlert(error)
+        })
+
     };
 
     dropZone.ondragover = function (ev) {
@@ -261,7 +257,7 @@ function updatePalette(view) {
             var node = nodes[n];
             if (nodes_properties[node]) {
                 palette_template += '<div id="drag_' + n + '" class="node ui-draggable"' +
-                    'type-name="' + n + '" draggable="true" ondragstart="nodeDragStart(event)">' +
+                    'type-name="' + node + '" draggable="true" ondragstart="nodeDragStart(event)">' +
                     '<div class="icon" style="background-color:' + nodes_properties[node].color + '"></div>' +
                     '<div class="name">' + nodes_properties[node].name + '</div></div>';
             }