X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=lib%2Fosm%2Fosm_util.py;h=acc4726f568c7cabb85f869a57996ab6b487aefa;hb=70f9629aef040ce2bd6fba9c082f15d33ac00ef1;hp=5d314cea0e970e359694798467a0e66d0b9b9f33;hpb=e428af7f429a3e42379c42c633ded0651ea2f0cf;p=osm%2FLW-UI.git diff --git a/lib/osm/osm_util.py b/lib/osm/osm_util.py index 5d314ce..acc4726 100644 --- a/lib/osm/osm_util.py +++ b/lib/osm/osm_util.py @@ -22,14 +22,42 @@ class OsmUtil(): str(item['member-vnf-index-ref']) != str( args['member-vnf-index']) or str( item['vnfd-id-ref']) != str(args['vnfd-id-ref'])] - elif node_type == 'cp': + elif node_type == 'ns_cp': for vld in nsd['vld']: if vld['id'] == args['vld_id']: vld['vnfd-connection-point-ref'] = [item for item in vld['vnfd-connection-point-ref'] if 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'] != args['name']] + if vnfd['mgmt-interface']['cp'] == args['name']: + del vnfd['mgmt-interface']['cp'] + 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 @@ -44,14 +72,34 @@ 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) + for vdu in vnfd['vdu']: + if 'interface' in vdu: + for intf in vdu['interface']: + if 'external-connection-point-ref' in intf and intf['external-connection-point-ref'] == old['name']: + intf['external-connection-point-ref'] = updated['name'] + if node_type == 'vdu': + for k, v in enumerate(vnfd['vdu']): + if v['name'] == old['name']: + vnfd['vdu'][k].update(updated) return descriptor @@ -75,7 +123,7 @@ class OsmUtil(): indexes = [] for cvnfd in nsd['constituent-vnfd']: indexes.append(int(cvnfd["member-vnf-index"])) - memberindex = max(indexes) + 1 + memberindex = max(indexes) + 1 if len(indexes) > 0 else 1 nsd['constituent-vnfd'].append({ "member-vnf-index": memberindex, "vnfd-id-ref": element_id @@ -83,7 +131,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( { @@ -92,6 +140,86 @@ 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': + if 'vdu' not in vnfd: + vnfd['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': + 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, + "internal-connection-point": [], + "type": "ELAN", + "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": args["name"], + "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 @@ -102,5 +230,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