vnfd composer fix missing node update
[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 elif descriptor_type == 'vnfd':
76 if 'vnfd-catalog' in descriptor:
77 vnfd = descriptor['vnfd-catalog']['vnfd'][0]
78 elif 'vnfd:vnfd-catalog' in descriptor:
79 vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0]
80
81 if node_type == 'vnf_vl':
82 for k, v in enumerate(vnfd['internal-vld']):
83 if v['id'] == old['id']:
84 vnfd['internal-vld'][k].update(updated)
85 if node_type == 'cp':
86 for k, v in enumerate(vnfd['connection-point']):
87 if v['name'] == old['name']:
88 vnfd['connection-point'][k].update(updated)
89 if node_type == 'vdu':
90 for k, v in enumerate(vnfd['vdu']):
91 if v['name'] == old['name']:
92 vnfd['vdu'][k].update(updated)
93
94 return descriptor
95
96 @staticmethod
97 def add_base_node(descriptor_type, descriptor, node_type, element_id, args):
98 if descriptor_type == 'nsd':
99 if 'nsd-catalog' in descriptor:
100 nsd = descriptor['nsd-catalog']['nsd'][0]
101 elif 'nsd:nsd-catalog' in descriptor:
102 nsd = descriptor['nsd:nsd-catalog']['nsd'][0]
103 if node_type == 'ns_vl':
104 nsd['vld'].append({
105 "vim-network-name": "PUBLIC",
106 "name": element_id,
107 "vnfd-connection-point-ref": [],
108 "mgmt-network": "true",
109 "type": "ELAN",
110 "id": element_id
111 })
112 if node_type == 'vnf':
113 indexes = []
114 for cvnfd in nsd['constituent-vnfd']:
115 indexes.append(int(cvnfd["member-vnf-index"]))
116 memberindex = max(indexes) + 1
117 nsd['constituent-vnfd'].append({
118 "member-vnf-index": memberindex,
119 "vnfd-id-ref": element_id
120 })
121 if node_type == 'cp':
122 for vld in nsd['vld']:
123 if vld['id'] == args['vld_id']:
124 if 'vnfd-connection-point-ref' not in vld:
125 vld['vnfd-connection-point-ref'] = []
126 vld['vnfd-connection-point-ref'].append(
127 {
128 "vnfd-connection-point-ref": args['vnfd-connection-point-ref'],
129 "member-vnf-index-ref": args['member-vnf-index-ref'],
130 "vnfd-id-ref": args['vnfd-id-ref']
131 },
132 )
133
134 elif descriptor_type == 'vnfd':
135 if 'vnfd-catalog' in descriptor:
136 vnfd = descriptor['vnfd-catalog']['vnfd'][0]
137 elif 'vnfd:vnfd-catalog' in descriptor:
138 vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0]
139 if node_type == 'vdu':
140 vnfd['vdu'].append({
141 "count": "1",
142 "description": "",
143 "monitoring-param": [],
144 "internal-connection-point": [],
145 "image": "ubuntu",
146 "cloud-init-file": "",
147 "vm-flavor": {},
148 "interface": [],
149 "id": element_id,
150 "name": element_id
151 })
152 if node_type == 'cp':
153 vnfd['connection-point'].append({
154 "type": "VPORT",
155 "name": element_id
156 })
157
158 if node_type == 'vnf_vl':
159 vnfd['internal-vld'].append({
160 "short-name": element_id,
161 "name": element_id,
162 "internal-connection-point": [],
163 "type": "ELAN",
164 "ip-profile-ref": "",
165 "id": element_id
166 })
167 if node_type == 'interface':
168 for vdu in vnfd['vdu']:
169 if vdu['id'] == args['vdu_id']:
170 vdu['interface'].append({
171 "virtual-interface": {
172 "type": "VIRTIO"
173 },
174 "name": element_id,
175 "mgmt-interface": True,
176 "type": "EXTERNAL",
177 "external-connection-point-ref": args["external-connection-point-ref"]
178 })
179 if node_type == 'int_cp':
180 for vdu in vnfd['vdu']:
181 if vdu['id'] == args['vdu_id']:
182 if 'internal-connection-point' not in vdu:
183 vdu['internal-connection-point'] = []
184 vdu['internal-connection-point'].append({
185 "short-name": element_id,
186 "type": "VPORT",
187 "id": element_id,
188 "name": element_id
189 })
190 if 'interface' not in vdu:
191 vdu['interface'] = []
192 vdu['interface'].append({
193 "virtual-interface": {
194 "type": "VIRTIO"
195 },
196 "name": "int_"+element_id,
197 "type": "INTERNAL",
198 "internal-connection-point-ref": element_id
199 })
200 for int_vld in vnfd['internal-vld']:
201 if int_vld['id'] == args['vld_id']:
202 if 'internal-connection-point' not in int_vld:
203 int_vld['internal-connection-point'] = []
204 int_vld['internal-connection-point'].append({
205 'id-ref': element_id
206 })
207 return descriptor
208
209 @staticmethod
210 def update_graph_params(descriptor_type, descriptor, updated):
211 if descriptor_type == 'nsd':
212 if 'nsd-catalog' in descriptor:
213 nsd = descriptor['nsd-catalog']['nsd'][0]
214 elif 'nsd:nsd-catalog' in descriptor:
215 nsd = descriptor['nsd:nsd-catalog']['nsd'][0]
216 nsd.update(updated)
217 elif descriptor_type == 'vnfd':
218 if 'vnfd-catalog' in descriptor:
219 vnfd = descriptor['vnfd-catalog']['vnfd'][0]
220 elif 'vnfd:vnfd-catalog' in descriptor:
221 vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0]
222 vnfd.update(updated)
223
224 return descriptor