composer vnfd fix on delete intCp node
[osm/LW-UI.git] / lib / osm / osm_util.py
1 class OsmUtil():
2
3 @staticmethod
4 def remove_node(descriptor_type, descriptor, node_type, element_id, args):
5 if descriptor_type == 'nsd':
6 if 'nsd-catalog' in descriptor:
7 nsd = descriptor['nsd-catalog']['nsd'][0]
8 elif 'nsd:nsd-catalog' in descriptor:
9 nsd = descriptor['nsd:nsd-catalog']['nsd'][0]
10
11 if node_type == 'ns_vl':
12 for k, v in enumerate(nsd['vld']):
13 if v['id'] == args['id']:
14 nsd['vld'].pop(k)
15 elif node_type == 'vnf':
16 for k, v in enumerate(nsd['constituent-vnfd']):
17 if str(v['member-vnf-index']) == str(args['member-vnf-index']) and str(v['vnfd-id-ref']) == str(
18 args['vnfd-id-ref']):
19 nsd['constituent-vnfd'].pop(k)
20 for j, vld in enumerate(nsd['vld']):
21 vld['vnfd-connection-point-ref'] = [item for item in vld['vnfd-connection-point-ref'] if
22 str(item['member-vnf-index-ref']) != str(
23 args['member-vnf-index']) or str(
24 item['vnfd-id-ref']) != str(args['vnfd-id-ref'])]
25 elif node_type == 'cp':
26 for vld in nsd['vld']:
27 if vld['id'] == args['vld_id']:
28 vld['vnfd-connection-point-ref'] = [item for item in vld['vnfd-connection-point-ref'] if
29 str(item['member-vnf-index-ref']) != str(
30 args['member-vnf-index-ref']) or str(
31 item['vnfd-id-ref']) != str(args['vnfd-id-ref'])]
32 elif descriptor_type == 'vnfd':
33 if 'vnfd-catalog' in descriptor:
34 vnfd = descriptor['vnfd-catalog']['vnfd'][0]
35 elif 'vnfd:vnfd-catalog' in descriptor:
36 vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0]
37
38 if node_type == 'vnf_vl':
39 vnfd['internal-vld'] = [item for item in vnfd['internal-vld'] if item['id'] != element_id]
40 if node_type == 'cp':
41 vnfd['connection-point'] = [item for item in vnfd['connection-point'] if item['name'] != element_id]
42 if node_type == 'vdu':
43 # check
44 vnfd['vdu'] = [item for item in vnfd['vdu'] if item['name'] != element_id]
45 if node_type == 'int_cp':
46
47 for vdu in vnfd['vdu']:
48 if 'interface' in vdu:
49 vdu['interface'] = [item for item in vdu['interface'] if 'internal-connection-point-ref' not in item
50 or ('internal-connection-point-ref'in item and item['internal-connection-point-ref'] != element_id)]
51 if 'internal-connection-point' in vdu:
52 vdu['internal-connection-point'] = [item for item in vdu['internal-connection-point'] if item['id'] != element_id]
53
54
55
56 return descriptor
57
58 @staticmethod
59 def update_node(descriptor_type, descriptor, node_type, old, updated):
60 if descriptor_type == 'nsd':
61 if 'nsd-catalog' in descriptor:
62 nsd = descriptor['nsd-catalog']['nsd'][0]
63 elif 'nsd:nsd-catalog' in descriptor:
64 nsd = descriptor['nsd:nsd-catalog']['nsd'][0]
65
66 if node_type == 'ns_vl':
67 for k, v in enumerate(nsd['vld']):
68 if v['id'] == old['id']:
69 nsd['vld'][k].update(updated)
70 elif node_type == 'vnf':
71 for k, v in enumerate(nsd['constituent-vnfd']):
72 if str(v['member-vnf-index']) == str(old['member-vnf-index']) and str(v['vnfd-id-ref']) == str(
73 old['vnfd-id-ref']):
74 print 'update here'
75
76 return descriptor
77
78 @staticmethod
79 def add_base_node(descriptor_type, descriptor, node_type, element_id, args):
80 if descriptor_type == 'nsd':
81 if 'nsd-catalog' in descriptor:
82 nsd = descriptor['nsd-catalog']['nsd'][0]
83 elif 'nsd:nsd-catalog' in descriptor:
84 nsd = descriptor['nsd:nsd-catalog']['nsd'][0]
85 if node_type == 'ns_vl':
86 nsd['vld'].append({
87 "vim-network-name": "PUBLIC",
88 "name": element_id,
89 "vnfd-connection-point-ref": [],
90 "mgmt-network": "true",
91 "type": "ELAN",
92 "id": element_id
93 })
94 if node_type == 'vnf':
95 indexes = []
96 for cvnfd in nsd['constituent-vnfd']:
97 indexes.append(int(cvnfd["member-vnf-index"]))
98 memberindex = max(indexes) + 1
99 nsd['constituent-vnfd'].append({
100 "member-vnf-index": memberindex,
101 "vnfd-id-ref": element_id
102 })
103 if node_type == 'cp':
104 for vld in nsd['vld']:
105 if vld['id'] == args['vld_id']:
106 if 'vnfd-connection-point-ref' not in vld:
107 vld['vnfd-connection-point-ref'] = []
108 vld['vnfd-connection-point-ref'].append(
109 {
110 "vnfd-connection-point-ref": args['vnfd-connection-point-ref'],
111 "member-vnf-index-ref": args['member-vnf-index-ref'],
112 "vnfd-id-ref": args['vnfd-id-ref']
113 },
114 )
115
116 elif descriptor_type == 'vnfd':
117 if 'vnfd-catalog' in descriptor:
118 vnfd = descriptor['vnfd-catalog']['vnfd'][0]
119 elif 'vnfd:vnfd-catalog' in descriptor:
120 vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0]
121 if node_type == 'vdu':
122 vnfd['vdu'].append({
123 "count": "1",
124 "description": "",
125 "monitoring-param": [],
126 "internal-connection-point": [],
127 "image": "ubuntu",
128 "cloud-init-file": "",
129 "vm-flavor": {},
130 "interface": [],
131 "id": element_id,
132 "name": element_id
133 })
134 if node_type == 'cp':
135 vnfd['connection-point'].append({
136 "type": "VPORT",
137 "name": element_id
138 })
139
140 if node_type == 'vnf_vl':
141 vnfd['internal-vld'].append({
142 "short-name": element_id,
143 "name": element_id,
144 "internal-connection-point": [],
145 "type": "ELAN",
146 "ip-profile-ref": "",
147 "id": element_id
148 })
149 if node_type == 'interface':
150 for vdu in vnfd['vdu']:
151 if vdu['id'] == args['vdu_id']:
152 vdu['interface'].append({
153 "virtual-interface": {
154 "type": "VIRTIO"
155 },
156 "name": element_id,
157 "mgmt-interface": True,
158 "type": "EXTERNAL",
159 "external-connection-point-ref": args["external-connection-point-ref"]
160 })
161 if node_type == 'int_cp':
162 for vdu in vnfd['vdu']:
163 if vdu['id'] == args['vdu_id']:
164 if 'internal-connection-point' not in vdu:
165 vdu['internal-connection-point'] = []
166 vdu['internal-connection-point'].append({
167 "short-name": element_id,
168 "type": "VPORT",
169 "id": element_id,
170 "name": element_id
171 })
172 if 'interface' not in vdu:
173 vdu['interface'] = []
174 vdu['interface'].append({
175 "virtual-interface": {
176 "type": "VIRTIO"
177 },
178 "name": "int_"+element_id,
179 "type": "INTERNAL",
180 "internal-connection-point-ref": element_id
181 })
182 for int_vld in vnfd['internal-vld']:
183 if int_vld['id'] == args['vld_id']:
184 if 'internal-connection-point' not in int_vld:
185 int_vld['internal-connection-point'] = []
186 int_vld['internal-connection-point'].append({
187 'id-ref': element_id
188 })
189 return descriptor
190
191 @staticmethod
192 def update_graph_params(descriptor_type, descriptor, updated):
193 if descriptor_type == 'nsd':
194 if 'nsd-catalog' in descriptor:
195 nsd = descriptor['nsd-catalog']['nsd'][0]
196 elif 'nsd:nsd-catalog' in descriptor:
197 nsd = descriptor['nsd:nsd-catalog']['nsd'][0]
198 nsd.update(updated)
199
200 return descriptor