b12f7d038187a004eb66e4684987379cee71d404
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
28 def get_lcm_operations_configuration(vnfd
):
29 return vnfd
.get("df", ())[0].get("lcm-operations-configuration", ())
32 def get_vdu_list(vnfd
):
33 return vnfd
.get("vdu", ())
36 def get_kdu_list(vnfd
):
37 return vnfd
.get("kdu", ())
40 def get_ee_sorted_initial_config_primitive_list(primitive_list
, vca_deployed
, ee_descriptor_id
):
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
51 primitive_list
= primitive_list
or []
53 p
for p
in primitive_list
if p
.get("execution-environment-ref", ee_descriptor_id
) == ee_descriptor_id
56 primitive_list
.sort(key
=lambda val
: int(val
['seq']))
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
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": []})
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": []})
75 def get_ee_sorted_terminate_config_primitive_list(primitive_list
, ee_descriptor_id
):
76 primitive_list
= primitive_list
or []
78 p
for p
in primitive_list
if p
.get("execution-environment-ref", ee_descriptor_id
) == ee_descriptor_id
81 primitive_list
.sort(key
=lambda val
: int(val
['seq']))
85 def 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
)
91 def get_kdu_profile(vnfd
, kdu_profile_id
):
92 return list_utils
.find_in_list(
93 vnfd
.get("df", ())[0]["kdu-profile"],
94 lambda kdu_profile
: kdu_profile
["name"] == kdu_profile_id
)
97 def get_vnf_configuration(vnfd
):
98 if "vnf-configuration-id" not in vnfd
.get("df")[0]:
100 vnf_config_id
= vnfd
.get("df")[0]["vnf-configuration-id"]
101 return list_utils
.find_in_list(
102 vnfd
.get("vnf-configuration", {}),
103 lambda vnf_config
: vnf_config
["id"] == vnf_config_id
)
106 def get_vdu_configuration(vnfd
, vdu_id
):
107 vdu_profile
= get_vdu_profile(vnfd
, vdu_id
)
108 return list_utils
.find_in_list(
109 vnfd
.get("vdu-configuration", ()),
110 lambda vdu_configuration
: vdu_configuration
["id"] == vdu_profile
["vdu-configuration-id"])
113 def get_kdu_configuration(vnfd
, kdu_id
):
114 kdu_profile
= get_kdu_profile(vnfd
, kdu_id
)
115 return list_utils
.find_in_list(
116 vnfd
.get("kdu-configuration", ()),
117 lambda kdu_configuration
: kdu_configuration
["id"] == kdu_profile
["kdu-configuration-id"])
120 def get_virtual_link_profiles(vnfd
):
121 return vnfd
.get("df")[0].get("virtual-link-profile", ())
124 def get_vdu(vnfd
, vdu_id
):
125 return list_utils
.find_in_list(
127 lambda vdu
: vdu
["id"] == vdu_id
)
130 def get_vdu_index(vnfd
, vdu_id
):
131 target_vdu
= list_utils
.find_in_list(
133 lambda vdu
: vdu
["id"] == vdu_id
)
135 return vnfd
.get("vdu", ()).index(target_vdu
)
140 def get_scaling_aspect(vnfd
):
141 return vnfd
.get("df", ())[0].get("scaling-aspect", ())
144 def get_number_of_instances(vnfd
, vdu_id
):
145 return list_utils
.find_in_list(
150 "instantiation-level",
156 lambda a_vdu
: a_vdu
["vdu-id"] == vdu_id
157 )["number-of-instances"]