fix missing vnfd composer constraint
[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
43 return descriptor
44
45 @staticmethod
46 def update_node(descriptor_type, descriptor, node_type, old, updated):
47 if descriptor_type == 'nsd':
48 if 'nsd-catalog' in descriptor:
49 nsd = descriptor['nsd-catalog']['nsd'][0]
50 elif 'nsd:nsd-catalog' in descriptor:
51 nsd = descriptor['nsd:nsd-catalog']['nsd'][0]
52
53 if node_type == 'ns_vl':
54 for k, v in enumerate(nsd['vld']):
55 if v['id'] == old['id']:
56 nsd['vld'][k].update(updated)
57 print 'update here'
58 print old
59 elif node_type == 'vnf':
60 for k, v in enumerate(nsd['constituent-vnfd']):
61 if str(v['member-vnf-index']) == str(old['member-vnf-index']) and str(v['vnfd-id-ref']) == str(
62 old['vnfd-id-ref']):
63 print 'update here'
64 print old
65
66 return descriptor
67
68 @staticmethod
69 def add_base_node(descriptor_type, descriptor, node_type, element_id, args):
70 if descriptor_type == 'nsd':
71 if 'nsd-catalog' in descriptor:
72 nsd = descriptor['nsd-catalog']['nsd'][0]
73 elif 'nsd:nsd-catalog' in descriptor:
74 nsd = descriptor['nsd:nsd-catalog']['nsd'][0]
75 if node_type == 'ns_vl':
76 nsd['vld'].append({
77 "vim-network-name": "PUBLIC",
78 "name": element_id,
79 "vnfd-connection-point-ref": [],
80 "mgmt-network": "true",
81 "type": "ELAN",
82 "id": element_id
83 })
84 if node_type == 'vnf':
85 indexes = []
86 for cvnfd in nsd['constituent-vnfd']:
87 indexes.append(int(cvnfd["member-vnf-index"]))
88 memberindex = max(indexes) + 1
89 nsd['constituent-vnfd'].append({
90 "member-vnf-index": memberindex,
91 "vnfd-id-ref": element_id
92 })
93 if node_type == 'cp':
94 for vld in nsd['vld']:
95 if vld['id'] == args['vld_id']:
96 if'vnfd-connection-point-ref' not in vld:
97 vld['vnfd-connection-point-ref'] = []
98 vld['vnfd-connection-point-ref'].append(
99 {
100 "vnfd-connection-point-ref": args['vnfd-connection-point-ref'],
101 "member-vnf-index-ref": args['member-vnf-index-ref'],
102 "vnfd-id-ref": args['vnfd-id-ref']
103 },
104 )
105
106 elif descriptor_type == 'vnfd':
107 if 'vnfd-catalog' in descriptor:
108 vnfd = descriptor['vnfd-catalog']['vnfd'][0]
109 elif 'vnfd:vnfd-catalog' in descriptor:
110 vnfd = descriptor['vnfd:vnfd-catalog']['vnfd'][0]
111 if node_type == 'vdu':
112 vnfd['vdu'].append({
113 "count": "1",
114 "description": "",
115 "monitoring-param": [],
116 "internal-connection-point": [],
117 "image": "ubuntu",
118 "cloud-init-file": "",
119 "vm-flavor": {},
120 "interface": [],
121 "id": element_id,
122 "name": element_id
123 })
124 if node_type == 'cp':
125 vnfd['connection-point'].append({
126 "type": "VPORT",
127 "name": element_id
128 })
129
130 if node_type == 'vnf_vl':
131 vnfd['internal-vld'].append({
132 "short-name": element_id,
133 "name": element_id,
134 "internal-connection-point": [],
135 "type": "ELAN",
136 "ip-profile-ref": "",
137 "id": element_id
138 })
139
140 return descriptor
141
142 @staticmethod
143 def update_graph_params(descriptor_type, descriptor, updated):
144 if descriptor_type == 'nsd':
145 if 'nsd-catalog' in descriptor:
146 nsd = descriptor['nsd-catalog']['nsd'][0]
147 elif 'nsd:nsd-catalog' in descriptor:
148 nsd = descriptor['nsd:nsd-catalog']['nsd'][0]
149 nsd.update(updated)
150
151 return descriptor