blob: 16257db52035007244bddd2746b072248e061856 [file] [log] [blame]
bravof922c4172020-11-24 21:21:43 -03001# -*- coding: utf-8 -*-
2
3# Copyright 2020 Whitestack, LLC
4# *************************************************************
5#
6# This file is part of OSM Monitoring module
7# All Rights Reserved to Whitestack, LLC
8#
9# Licensed under the Apache License, Version 2.0 (the "License"); you may
10# not use this file except in compliance with the License. You may obtain
11# a copy of the License at
12#
13# http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18# License for the specific language governing permissions and limitations
19# under the License.
20#
21# For those usages not covered by the Apache License, Version 2.0 please
22# contact: fbravo@whitestack.com
23##
24
25from osm_lcm.data_utils import list_utils
26
27
28def get_lcm_operations_configuration(vnfd):
29 return vnfd.get("df", ())[0].get("lcm-operations-configuration", ())
30
31
32def get_vdu_list(vnfd):
33 return vnfd.get("vdu", ())
34
35
36def get_kdu_list(vnfd):
37 return vnfd.get("kdu", ())
38
39
40def get_ee_sorted_initial_config_primitive_list(primitive_list, vca_deployed, ee_descriptor_id):
41 """
42 Generates a list of initial-config-primitive based on the list provided by the descriptor. It includes internal
43 primitives as verify-ssh-credentials, or config when needed
44 :param primitive_list: information of the descriptor
45 :param vca_deployed: information of the deployed, needed for known if it is related to an NS, VNF, VDU and if
46 this element contains a ssh public key
47 :param ee_descriptor_id: execution environment descriptor id. It is the value of
48 XXX_configuration.execution-environment-list.INDEX.id; it can be None
49 :return: The modified list. Can ba an empty list, but always a list
50 """
51 primitive_list = primitive_list or []
52 primitive_list = [
53 p for p in primitive_list if p.get("execution-environment-ref", ee_descriptor_id) == ee_descriptor_id
54 ]
55 if primitive_list:
56 primitive_list.sort(key=lambda val: int(val['seq']))
57
58 # look for primitive config, and get the position. None if not present
59 config_position = None
60 for index, primitive in enumerate(primitive_list):
61 if primitive["name"] == "config":
62 config_position = index
63 break
64
65 # for NS, add always a config primitive if not present (bug 874)
66 if not vca_deployed["member-vnf-index"] and config_position is None:
67 primitive_list.insert(0, {"name": "config", "parameter": []})
68 config_position = 0
69 # TODO revise if needed: for VNF/VDU add verify-ssh-credentials after config
70 if vca_deployed["member-vnf-index"] and config_position is not None and vca_deployed.get("ssh-public-key"):
71 primitive_list.insert(config_position + 1, {"name": "verify-ssh-credentials", "parameter": []})
72 return primitive_list
73
74
75def get_ee_sorted_terminate_config_primitive_list(primitive_list, ee_descriptor_id):
76 primitive_list = primitive_list or []
77 primitive_list = [
78 p for p in primitive_list if p.get("execution-environment-ref", ee_descriptor_id) == ee_descriptor_id
79 ]
80 if primitive_list:
81 primitive_list.sort(key=lambda val: int(val['seq']))
82 return primitive_list
83
84
85def get_vdu_profile(vnfd, vdu_profile_id):
86 return list_utils.find_in_list(
87 vnfd.get("df", ())[0]["vdu-profile"],
88 lambda vdu_profile: vdu_profile["id"] == vdu_profile_id)
89
90
garciaalea77ced72021-02-17 19:09:12 -030091def get_configuration(vnfd, entity_id):
92 lcm_ops_config = vnfd.get("df")[0].get("lcm-operations-configuration")
93 if not lcm_ops_config:
bravof922c4172020-11-24 21:21:43 -030094 return None
garciaalea77ced72021-02-17 19:09:12 -030095 ops_vnf = lcm_ops_config.get("operate-vnf-op-config")
96 if not ops_vnf:
97 return None
98 day12ops = ops_vnf.get("day1-2", [])
99 list_utils.find_in_list(
100 day12ops,
101 lambda configuration: configuration["id"] == entity_id)
bravof922c4172020-11-24 21:21:43 -0300102
103
104def get_virtual_link_profiles(vnfd):
105 return vnfd.get("df")[0].get("virtual-link-profile", ())
106
107
108def get_vdu(vnfd, vdu_id):
109 return list_utils.find_in_list(
110 vnfd.get("vdu", ()),
111 lambda vdu: vdu["id"] == vdu_id)
112
113
114def get_vdu_index(vnfd, vdu_id):
115 target_vdu = list_utils.find_in_list(
116 vnfd.get("vdu", ()),
117 lambda vdu: vdu["id"] == vdu_id)
118 if target_vdu:
119 return vnfd.get("vdu", ()).index(target_vdu)
120 else:
121 return -1
bravof832f8992020-12-07 12:57:31 -0300122
123
124def get_scaling_aspect(vnfd):
125 return vnfd.get("df", ())[0].get("scaling-aspect", ())
126
127
128def get_number_of_instances(vnfd, vdu_id):
129 return list_utils.find_in_list(
130 vnfd.get(
131 "df",
132 ()
133 )[0].get(
134 "instantiation-level",
135 ()
136 )[0].get(
137 "vdu-level",
138 ()
139 ),
140 lambda a_vdu: a_vdu["vdu-id"] == vdu_id
141 )["number-of-instances"]