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_configuration(vnfd
, entity_id
):
92 lcm_ops_config
= vnfd
.get("df")[0].get("lcm-operations-configuration")
93 if not lcm_ops_config
:
95 ops_vnf
= lcm_ops_config
.get("operate-vnf-op-config")
98 day12ops
= ops_vnf
.get("day1-2", [])
99 return list_utils
.find_in_list(
101 lambda configuration
: configuration
["id"] == entity_id
)
104 def get_virtual_link_profiles(vnfd
):
105 return vnfd
.get("df")[0].get("virtual-link-profile", ())
108 def get_vdu(vnfd
, vdu_id
):
109 return list_utils
.find_in_list(
111 lambda vdu
: vdu
["id"] == vdu_id
)
114 def get_vdu_index(vnfd
, vdu_id
):
115 target_vdu
= list_utils
.find_in_list(
117 lambda vdu
: vdu
["id"] == vdu_id
)
119 return vnfd
.get("vdu", ()).index(target_vdu
)
124 def get_scaling_aspect(vnfd
):
125 return vnfd
.get("df", ())[0].get("scaling-aspect", ())
128 def get_number_of_instances(vnfd
, vdu_id
):
129 return list_utils
.find_in_list(
134 "instantiation-level",
140 lambda a_vdu
: a_vdu
["vdu-id"] == vdu_id
141 ).get("number-of-instances", 1)
144 def get_juju_ee_ref(vnfd
, entity_id
):
145 return list_utils
.find_in_list(
146 get_configuration(vnfd
, entity_id
).get(
147 "execution-environment-list",
150 lambda ee
: "juju" in ee