feat(sol006): LCM migration to SOL006
Change-Id: I48a3ec2fec0b1e0173bb0f3aaa83a774d46b3955
Signed-off-by: bravof <fbravo@whitestack.com>
diff --git a/osm_lcm/data_utils/__init__.py b/osm_lcm/data_utils/__init__.py
new file mode 100644
index 0000000..0e69572
--- /dev/null
+++ b/osm_lcm/data_utils/__init__.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com
+##
diff --git a/osm_lcm/data_utils/database/__init__.py b/osm_lcm/data_utils/database/__init__.py
new file mode 100644
index 0000000..8d05ad8
--- /dev/null
+++ b/osm_lcm/data_utils/database/__init__.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM LCM module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com or agarcia@whitestack.com
+##
diff --git a/osm_lcm/data_utils/database/database.py b/osm_lcm/data_utils/database/database.py
new file mode 100644
index 0000000..eeb44c4
--- /dev/null
+++ b/osm_lcm/data_utils/database/database.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM LCM module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com or agarcia@whitestack.com
+##
+
+import logging
+from osm_common import dbmemory, dbmongo
+from osm_common.dbbase import DbException
+
+
+class Database:
+ class __Database:
+ def __init__(self, config):
+ self.logger = logging.getLogger('lcm')
+ try:
+ # TODO check database version
+ if config["database"]["driver"] == "mongo":
+ self.db = dbmongo.DbMongo()
+ self.db.db_connect(config["database"])
+ elif config["database"]["driver"] == "memory":
+ self.db = dbmemory.DbMemory()
+ self.db.db_connect(config["database"])
+ else:
+ raise Exception("Invalid configuration param '{}' at '[database]':'driver'".format(
+ config["database"]["driver"]))
+ except (DbException) as e:
+ self.logger.critical(str(e), exc_info=True)
+ raise Exception(str(e))
+
+ def __str__(self):
+ return repr(self) + self.db
+
+ instance = None
+
+ def __init__(self, config=None):
+ if not Database.instance:
+ Database.instance = Database.__Database(config)
+
+ def __getattr__(self, name):
+ return getattr(self.instance, name)
diff --git a/osm_lcm/data_utils/database/vim_account.py b/osm_lcm/data_utils/database/vim_account.py
new file mode 100644
index 0000000..5c61073
--- /dev/null
+++ b/osm_lcm/data_utils/database/vim_account.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM LCM module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com or agarcia@whitestack.com
+##
+
+
+from osm_lcm.data_utils.database.database import Database
+
+
+class VimAccountDB:
+ db = None
+
+ def get_vim_account_with_id(vim_account_id):
+ if not VimAccountDB.db:
+ VimAccountDB.initialize_db()
+ return VimAccountDB.db.get_one("vim_accounts", {"_id": vim_account_id}) or {}
+
+ def initialize_db():
+ VimAccountDB.db = Database().instance.db
diff --git a/osm_lcm/data_utils/dict_utils.py b/osm_lcm/data_utils/dict_utils.py
new file mode 100644
index 0000000..79df8c9
--- /dev/null
+++ b/osm_lcm/data_utils/dict_utils.py
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM LCM module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com
+##
+
+import yaml
+
+
+def parse_yaml_strings(params):
+ params = params or {}
+ for key, value in params.items():
+ if str(value).startswith("!!yaml "):
+ params[key] = yaml.safe_load(value[7:])
+ return params
diff --git a/osm_lcm/data_utils/filesystem/__init__.py b/osm_lcm/data_utils/filesystem/__init__.py
new file mode 100644
index 0000000..8d05ad8
--- /dev/null
+++ b/osm_lcm/data_utils/filesystem/__init__.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM LCM module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com or agarcia@whitestack.com
+##
diff --git a/osm_lcm/data_utils/filesystem/filesystem.py b/osm_lcm/data_utils/filesystem/filesystem.py
new file mode 100644
index 0000000..bc26c96
--- /dev/null
+++ b/osm_lcm/data_utils/filesystem/filesystem.py
@@ -0,0 +1,58 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM LCM module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com or agarcia@whitestack.com
+##
+
+import logging
+from osm_common.fsbase import FsException
+from osm_common import fslocal, fsmongo
+
+
+class Filesystem:
+ class __Filesystem:
+ def __init__(self, config):
+ self.logger = logging.getLogger('lcm')
+ try:
+ if config["storage"]["driver"] == "local":
+ self.fs = fslocal.FsLocal()
+ self.fs.fs_connect(config["storage"])
+ elif config["storage"]["driver"] == "mongo":
+ self.fs = fsmongo.FsMongo()
+ self.fs.fs_connect(config["storage"])
+ else:
+ raise Exception("Invalid configuration param '{}' at '[storage]':'driver'".format(
+ config["storage"]["driver"]))
+ except (FsException) as e:
+ self.logger.critical(str(e), exc_info=True)
+ raise Exception(str(e))
+
+ def __str__(self):
+ return repr(self) + self.fs
+
+ instance = None
+
+ def __init__(self, config=None):
+ if not Filesystem.instance:
+ Filesystem.instance = Filesystem.__Filesystem(config)
+
+ def __getattr__(self, name):
+ return getattr(self.instance, name)
diff --git a/osm_lcm/data_utils/list_utils.py b/osm_lcm/data_utils/list_utils.py
new file mode 100644
index 0000000..14c11d3
--- /dev/null
+++ b/osm_lcm/data_utils/list_utils.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com
+##
+
+
+def find_in_list(the_list, condition_lambda):
+ for item in the_list:
+ if condition_lambda(item):
+ return item
+ else:
+ return None
diff --git a/osm_lcm/data_utils/nsd.py b/osm_lcm/data_utils/nsd.py
new file mode 100644
index 0000000..2917c04
--- /dev/null
+++ b/osm_lcm/data_utils/nsd.py
@@ -0,0 +1,38 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com
+##
+import ast
+
+
+def get_vnf_profiles(nsd):
+ return nsd.get("df")[0].get("vnf-profile", ())
+
+
+def get_virtual_link_profiles(nsd):
+ return nsd.get("df")[0].get("virtual-link-profile", ())
+
+
+def replace_vnf_id(nsd, old_vnf_id, new_vnf_id):
+ dict_str = str(nsd)
+ dict_str.replace(old_vnf_id, new_vnf_id)
+ return ast.literal_eval(dict_str)
diff --git a/osm_lcm/data_utils/nsr.py b/osm_lcm/data_utils/nsr.py
new file mode 100644
index 0000000..f62b0b4
--- /dev/null
+++ b/osm_lcm/data_utils/nsr.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com
+##
+
+
+def get_vlds(nsr):
+ return nsr.get("vld", ())
diff --git a/osm_lcm/data_utils/vim.py b/osm_lcm/data_utils/vim.py
new file mode 100644
index 0000000..0e69572
--- /dev/null
+++ b/osm_lcm/data_utils/vim.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com
+##
diff --git a/osm_lcm/data_utils/vnfd.py b/osm_lcm/data_utils/vnfd.py
new file mode 100644
index 0000000..5774060
--- /dev/null
+++ b/osm_lcm/data_utils/vnfd.py
@@ -0,0 +1,137 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com
+##
+
+from osm_lcm.data_utils import list_utils
+
+
+def get_lcm_operations_configuration(vnfd):
+ return vnfd.get("df", ())[0].get("lcm-operations-configuration", ())
+
+
+def get_vdu_list(vnfd):
+ return vnfd.get("vdu", ())
+
+
+def get_kdu_list(vnfd):
+ return vnfd.get("kdu", ())
+
+
+def get_ee_sorted_initial_config_primitive_list(primitive_list, vca_deployed, ee_descriptor_id):
+ """
+ Generates a list of initial-config-primitive based on the list provided by the descriptor. It includes internal
+ primitives as verify-ssh-credentials, or config when needed
+ :param primitive_list: information of the descriptor
+ :param vca_deployed: information of the deployed, needed for known if it is related to an NS, VNF, VDU and if
+ this element contains a ssh public key
+ :param ee_descriptor_id: execution environment descriptor id. It is the value of
+ XXX_configuration.execution-environment-list.INDEX.id; it can be None
+ :return: The modified list. Can ba an empty list, but always a list
+ """
+ primitive_list = primitive_list or []
+ primitive_list = [
+ p for p in primitive_list if p.get("execution-environment-ref", ee_descriptor_id) == ee_descriptor_id
+ ]
+ if primitive_list:
+ primitive_list.sort(key=lambda val: int(val['seq']))
+
+ # look for primitive config, and get the position. None if not present
+ config_position = None
+ for index, primitive in enumerate(primitive_list):
+ if primitive["name"] == "config":
+ config_position = index
+ break
+
+ # for NS, add always a config primitive if not present (bug 874)
+ if not vca_deployed["member-vnf-index"] and config_position is None:
+ primitive_list.insert(0, {"name": "config", "parameter": []})
+ config_position = 0
+ # TODO revise if needed: for VNF/VDU add verify-ssh-credentials after config
+ if vca_deployed["member-vnf-index"] and config_position is not None and vca_deployed.get("ssh-public-key"):
+ primitive_list.insert(config_position + 1, {"name": "verify-ssh-credentials", "parameter": []})
+ return primitive_list
+
+
+def get_ee_sorted_terminate_config_primitive_list(primitive_list, ee_descriptor_id):
+ primitive_list = primitive_list or []
+ primitive_list = [
+ p for p in primitive_list if p.get("execution-environment-ref", ee_descriptor_id) == ee_descriptor_id
+ ]
+ if primitive_list:
+ primitive_list.sort(key=lambda val: int(val['seq']))
+ return primitive_list
+
+
+def get_vdu_profile(vnfd, vdu_profile_id):
+ return list_utils.find_in_list(
+ vnfd.get("df", ())[0]["vdu-profile"],
+ lambda vdu_profile: vdu_profile["id"] == vdu_profile_id)
+
+
+def get_kdu_profile(vnfd, kdu_profile_id):
+ return list_utils.find_in_list(
+ vnfd.get("df", ())[0]["kdu-profile"],
+ lambda kdu_profile: kdu_profile["id"] == kdu_profile_id)
+
+
+def get_vnf_configuration(vnfd):
+ if "vnf-configuration-id" not in vnfd.get("df")[0]:
+ return None
+ vnf_config_id = vnfd.get("df")[0]["vnf-configuration-id"]
+ return list_utils.find_in_list(
+ vnfd.get("vnf-configuration", {}),
+ lambda vnf_config: vnf_config["id"] == vnf_config_id)
+
+
+def get_vdu_configuration(vnfd, vdu_id):
+ vdu_profile = get_vdu_profile(vnfd, vdu_id)
+ return list_utils.find_in_list(
+ vnfd.get("vdu-configuration", ()),
+ lambda vdu_configuration: vdu_configuration["id"] == vdu_profile["vdu-configuration-id"])
+
+
+def get_kdu_configuration(vnfd, kdu_id):
+ kdu_profile = get_kdu_profile(vnfd, kdu_id)
+ return list_utils.find_in_list(
+ vnfd.get("kdu-configuration", ()),
+ lambda kdu_configuration: kdu_configuration["id"] == kdu_profile["kdu-configuration-id"])
+
+
+def get_virtual_link_profiles(vnfd):
+ return vnfd.get("df")[0].get("virtual-link-profile", ())
+
+
+def get_vdu(vnfd, vdu_id):
+ return list_utils.find_in_list(
+ vnfd.get("vdu", ()),
+ lambda vdu: vdu["id"] == vdu_id)
+
+
+def get_vdu_index(vnfd, vdu_id):
+ target_vdu = list_utils.find_in_list(
+ vnfd.get("vdu", ()),
+ lambda vdu: vdu["id"] == vdu_id)
+ if target_vdu:
+ return vnfd.get("vdu", ()).index(target_vdu)
+ else:
+ return -1
diff --git a/osm_lcm/data_utils/vnfr.py b/osm_lcm/data_utils/vnfr.py
new file mode 100644
index 0000000..042788e
--- /dev/null
+++ b/osm_lcm/data_utils/vnfr.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2020 Whitestack, LLC
+# *************************************************************
+#
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: fbravo@whitestack.com
+##
+
+from osm_lcm.data_utils import list_utils
+
+
+def find_VNFR_by_VDU_ID(vnfr, vdu_id):
+ list_utils.find_in_list(vnfr, lambda vnfr: False)
+
+
+def get_osm_params(db_vnfr, vdu_id=None, vdu_count_index=0):
+ osm_params = {
+ x.replace("-", "_"): db_vnfr[x] for x in ("ip-address", "vim-account-id", "vnfd-id", "vnfd-ref")
+ if db_vnfr.get(x) is not None
+ }
+ osm_params["ns_id"] = db_vnfr["nsr-id-ref"]
+ osm_params["vnf_id"] = db_vnfr["_id"]
+ osm_params["member_vnf_index"] = db_vnfr["member-vnf-index-ref"]
+ if db_vnfr.get("vdur"):
+ osm_params["vdu"] = {}
+ for vdur in db_vnfr["vdur"]:
+ vdu = {
+ "count_index": vdur["count-index"],
+ "vdu_id": vdur["vdu-id-ref"],
+ "interfaces": {}
+ }
+ if vdur.get("ip-address"):
+ vdu["ip_address"] = vdur["ip-address"]
+ for iface in vdur["interfaces"]:
+ vdu["interfaces"][iface["name"]] = \
+ {x.replace("-", "_"): iface[x] for x in ("mac-address", "ip-address", "name")
+ if iface.get(x) is not None}
+ vdu_id_index = "{}-{}".format(vdur["vdu-id-ref"], vdur["count-index"])
+ osm_params["vdu"][vdu_id_index] = vdu
+ if vdu_id:
+ osm_params["vdu_id"] = vdu_id
+ osm_params["count_index"] = vdu_count_index
+ return osm_params