1 # -*- coding: utf-8 -*-
3 # Copyright 2020 Whitestack, LLC
4 # *************************************************************
6 # This file is part of OSM Monitoring module
7 # All Rights Reserved to Whitestack, LLC
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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
21 # For those usages not covered by the Apache License, Version 2.0 please
22 # contact: fbravo@whitestack.com
25 from osm_lcm
.data_utils
import list_utils
26 from osm_lcm
.lcm_utils
import get_iterable
29 def get_lcm_operations_configuration(vnfd
):
30 return vnfd
.get("df", ())[0].get("lcm-operations-configuration", ())
33 def get_vdu_list(vnfd
):
34 return vnfd
.get("vdu", ())
37 def get_kdu_list(vnfd
):
38 return vnfd
.get("kdu", ())
41 def get_ee_sorted_initial_config_primitive_list(primitive_list
, vca_deployed
, ee_descriptor_id
):
43 Generates a list of initial-config-primitive based on the list provided by the descriptor. It includes internal
44 primitives as verify-ssh-credentials, or config when needed
45 :param primitive_list: information of the descriptor
46 :param vca_deployed: information of the deployed, needed for known if it is related to an NS, VNF, VDU and if
47 this element contains a ssh public key
48 :param ee_descriptor_id: execution environment descriptor id. It is the value of
49 XXX_configuration.execution-environment-list.INDEX.id; it can be None
50 :return: The modified list. Can ba an empty list, but always a list
52 primitive_list
= primitive_list
or []
54 p
for p
in primitive_list
if p
.get("execution-environment-ref", ee_descriptor_id
) == ee_descriptor_id
57 primitive_list
.sort(key
=lambda val
: int(val
['seq']))
59 # look for primitive config, and get the position. None if not present
60 config_position
= None
61 for index
, primitive
in enumerate(primitive_list
):
62 if primitive
["name"] == "config":
63 config_position
= index
66 # for NS, add always a config primitive if not present (bug 874)
67 if not vca_deployed
["member-vnf-index"] and config_position
is None:
68 primitive_list
.insert(0, {"name": "config", "parameter": []})
70 # TODO revise if needed: for VNF/VDU add verify-ssh-credentials after config
71 if vca_deployed
["member-vnf-index"] and config_position
is not None and vca_deployed
.get("ssh-public-key"):
72 primitive_list
.insert(config_position
+ 1, {"name": "verify-ssh-credentials", "parameter": []})
76 def get_ee_sorted_terminate_config_primitive_list(primitive_list
, ee_descriptor_id
):
77 primitive_list
= primitive_list
or []
79 p
for p
in primitive_list
if p
.get("execution-environment-ref", ee_descriptor_id
) == ee_descriptor_id
82 primitive_list
.sort(key
=lambda val
: int(val
['seq']))
86 def get_vdu_profile(vnfd
, vdu_profile_id
):
87 return list_utils
.find_in_list(
88 vnfd
.get("df", ())[0]["vdu-profile"],
89 lambda vdu_profile
: vdu_profile
["id"] == vdu_profile_id
)
92 def get_vnf_configuration(vnfd
):
93 if "vnf-configuration-id" not in vnfd
.get("df")[0]:
95 vnf_config_id
= vnfd
.get("df")[0]["vnf-configuration-id"]
96 return list_utils
.find_in_list(
97 vnfd
.get("vnf-configuration", {}),
98 lambda vnf_config
: vnf_config
["id"] == vnf_config_id
)
101 def get_vdu_configuration(vnfd
, vdu_id
):
102 vdu_profile
= get_vdu_profile(vnfd
, vdu_id
)
103 return list_utils
.find_in_list(
104 vnfd
.get("vdu-configuration", ()),
105 lambda vdu_configuration
: vdu_configuration
["id"] == vdu_profile
["vdu-configuration-id"])
108 def get_kdu_configuration(vnfd
, kdu_name
):
109 for kdu
in get_iterable(vnfd
, "kdu"):
110 if kdu_name
== kdu
["name"]:
111 return kdu
.get("kdu-configuration")
114 def get_virtual_link_profiles(vnfd
):
115 return vnfd
.get("df")[0].get("virtual-link-profile", ())
118 def get_vdu(vnfd
, vdu_id
):
119 return list_utils
.find_in_list(
121 lambda vdu
: vdu
["id"] == vdu_id
)
124 def get_vdu_index(vnfd
, vdu_id
):
125 target_vdu
= list_utils
.find_in_list(
127 lambda vdu
: vdu
["id"] == vdu_id
)
129 return vnfd
.get("vdu", ()).index(target_vdu
)
134 def get_scaling_aspect(vnfd
):
135 return vnfd
.get("df", ())[0].get("scaling-aspect", ())
138 def get_number_of_instances(vnfd
, vdu_id
):
139 return list_utils
.find_in_list(
144 "instantiation-level",
150 lambda a_vdu
: a_vdu
["vdu-id"] == vdu_id
151 )["number-of-instances"]