X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_lcm%2Fvim_sdn.py;h=47015c0e2ead4839bbee1749b6c305f099bc8fd8;hb=7f2a2a9f354b83e7dbe4072c6ab1074138091090;hp=41a16e5229bc2844d31add77151fd0f04c1d1cdd;hpb=8e53c6d0046a3015bf015b745aa3cf9a30a8fbe6;p=osm%2FLCM.git diff --git a/osm_lcm/vim_sdn.py b/osm_lcm/vim_sdn.py index 41a16e5..47015c0 100644 --- a/osm_lcm/vim_sdn.py +++ b/osm_lcm/vim_sdn.py @@ -46,7 +46,7 @@ class VimLcm(LcmBase): ), } - def __init__(self, msg, lcm_tasks, config, loop): + def __init__(self, msg, lcm_tasks, config): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', @@ -54,14 +54,12 @@ class VimLcm(LcmBase): """ self.logger = logging.getLogger("lcm.vim") - self.loop = loop self.lcm_tasks = lcm_tasks self.ro_config = config["RO"] super().__init__(msg, self.logger) async def create(self, vim_content, order_id): - # HA tasks and backward compatibility: # If 'vim_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing. @@ -112,7 +110,7 @@ class VimLcm(LcmBase): db_vim_update["_admin.deployed.RO"] = None db_vim_update["_admin.detailed-status"] = step self.update_db_2("vim_accounts", vim_id, db_vim_update) - RO = ROclient.ROClient(self.loop, **self.ro_config) + RO = ROclient.ROClient(**self.ro_config) vim_RO = deepcopy(vim_content) vim_RO.pop("_id", None) vim_RO.pop("_admin", None) @@ -214,7 +212,6 @@ class VimLcm(LcmBase): self.lcm_tasks.remove("vim_account", vim_id, order_id) async def edit(self, vim_content, order_id): - # HA tasks and backward compatibility: # If 'vim_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, and the HA check always returns True @@ -272,7 +269,7 @@ class VimLcm(LcmBase): RO_vim_id = db_vim["_admin"]["deployed"]["RO"] step = "Editing vim at RO" - RO = ROclient.ROClient(self.loop, **self.ro_config) + RO = ROclient.ROClient(**self.ro_config) vim_RO = deepcopy(vim_content) vim_RO.pop("_id", None) vim_RO.pop("_admin", None) @@ -370,7 +367,6 @@ class VimLcm(LcmBase): self.lcm_tasks.remove("vim_account", vim_id, order_id) async def delete(self, vim_content, order_id): - # HA tasks and backward compatibility: # If 'vim_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, and the HA check always returns True @@ -397,7 +393,7 @@ class VimLcm(LcmBase): and db_vim["_admin"]["deployed"].get("RO") ): RO_vim_id = db_vim["_admin"]["deployed"]["RO"] - RO = ROclient.ROClient(self.loop, **self.ro_config) + RO = ROclient.ROClient(**self.ro_config) step = "Detaching vim from RO tenant" try: await RO.detach("vim_account", RO_vim_id) @@ -468,7 +464,7 @@ class WimLcm(LcmBase): # values that are encrypted at wim config because they are passwords wim_config_encrypted = () - def __init__(self, msg, lcm_tasks, config, loop): + def __init__(self, msg, lcm_tasks, config): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', @@ -476,14 +472,12 @@ class WimLcm(LcmBase): """ self.logger = logging.getLogger("lcm.vim") - self.loop = loop self.lcm_tasks = lcm_tasks self.ro_config = config["RO"] super().__init__(msg, self.logger) async def create(self, wim_content, order_id): - # HA tasks and backward compatibility: # If 'wim_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing. @@ -506,7 +500,7 @@ class WimLcm(LcmBase): step = "Creating wim at RO" db_wim_update["_admin.detailed-status"] = step self.update_db_2("wim_accounts", wim_id, db_wim_update) - RO = ROclient.ROClient(self.loop, **self.ro_config) + RO = ROclient.ROClient(**self.ro_config) wim_RO = deepcopy(wim_content) wim_RO.pop("_id", None) wim_RO.pop("_admin", None) @@ -600,7 +594,6 @@ class WimLcm(LcmBase): self.lcm_tasks.remove("wim_account", wim_id, order_id) async def edit(self, wim_content, order_id): - # HA tasks and backward compatibility: # If 'wim_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, and the HA check always returns True @@ -628,10 +621,9 @@ class WimLcm(LcmBase): and db_wim["_admin"].get("deployed") and db_wim["_admin"]["deployed"].get("RO") ): - RO_wim_id = db_wim["_admin"]["deployed"]["RO"] step = "Editing wim at RO" - RO = ROclient.ROClient(self.loop, **self.ro_config) + RO = ROclient.ROClient(**self.ro_config) wim_RO = deepcopy(wim_content) wim_RO.pop("_id", None) wim_RO.pop("_admin", None) @@ -721,7 +713,6 @@ class WimLcm(LcmBase): self.lcm_tasks.remove("wim_account", wim_id, order_id) async def delete(self, wim_content, order_id): - # HA tasks and backward compatibility: # If 'vim_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, and the HA check always returns True @@ -748,7 +739,7 @@ class WimLcm(LcmBase): and db_wim["_admin"]["deployed"].get("RO") ): RO_wim_id = db_wim["_admin"]["deployed"]["RO"] - RO = ROclient.ROClient(self.loop, **self.ro_config) + RO = ROclient.ROClient(**self.ro_config) step = "Detaching wim from RO tenant" try: await RO.detach("wim_account", RO_wim_id) @@ -816,7 +807,7 @@ class WimLcm(LcmBase): class SdnLcm(LcmBase): - def __init__(self, msg, lcm_tasks, config, loop): + def __init__(self, msg, lcm_tasks, config): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', @@ -824,14 +815,12 @@ class SdnLcm(LcmBase): """ self.logger = logging.getLogger("lcm.sdn") - self.loop = loop self.lcm_tasks = lcm_tasks self.ro_config = config["RO"] super().__init__(msg, self.logger) async def create(self, sdn_content, order_id): - # HA tasks and backward compatibility: # If 'sdn_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing. @@ -856,7 +845,7 @@ class SdnLcm(LcmBase): db_sdn_update["_admin.detailed-status"] = step self.update_db_2("sdns", sdn_id, db_sdn_update) - RO = ROclient.ROClient(self.loop, **self.ro_config) + RO = ROclient.ROClient(**self.ro_config) sdn_RO = deepcopy(sdn_content) sdn_RO.pop("_id", None) sdn_RO.pop("_admin", None) @@ -912,7 +901,6 @@ class SdnLcm(LcmBase): self.lcm_tasks.remove("sdn", sdn_id, order_id) async def edit(self, sdn_content, order_id): - # HA tasks and backward compatibility: # If 'sdn_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, and the HA check always returns True @@ -940,7 +928,7 @@ class SdnLcm(LcmBase): and db_sdn["_admin"]["deployed"].get("RO") ): RO_sdn_id = db_sdn["_admin"]["deployed"]["RO"] - RO = ROclient.ROClient(self.loop, **self.ro_config) + RO = ROclient.ROClient(**self.ro_config) step = "Editing sdn at RO" sdn_RO = deepcopy(sdn_content) sdn_RO.pop("_id", None) @@ -994,7 +982,6 @@ class SdnLcm(LcmBase): self.lcm_tasks.remove("sdn", sdn_id, order_id) async def delete(self, sdn_content, order_id): - # HA tasks and backward compatibility: # If 'vim_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, and the HA check always returns True @@ -1021,7 +1008,7 @@ class SdnLcm(LcmBase): and db_sdn["_admin"]["deployed"].get("RO") ): RO_sdn_id = db_sdn["_admin"]["deployed"]["RO"] - RO = ROclient.ROClient(self.loop, **self.ro_config) + RO = ROclient.ROClient(**self.ro_config) step = "Deleting sdn from RO" try: await RO.delete("sdn", RO_sdn_id) @@ -1078,7 +1065,7 @@ class SdnLcm(LcmBase): class K8sClusterLcm(LcmBase): timeout_create = 300 - def __init__(self, msg, lcm_tasks, config, loop): + def __init__(self, msg, lcm_tasks, config): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', @@ -1086,7 +1073,6 @@ class K8sClusterLcm(LcmBase): """ self.logger = logging.getLogger("lcm.k8scluster") - self.loop = loop self.lcm_tasks = lcm_tasks self.vca_config = config["VCA"] @@ -1114,7 +1100,6 @@ class K8sClusterLcm(LcmBase): kubectl_command=self.vca_config.get("kubectlpath"), juju_command=self.vca_config.get("jujupath"), log=self.logger, - loop=self.loop, on_update_db=None, db=self.db, fs=self.fs, @@ -1127,7 +1112,6 @@ class K8sClusterLcm(LcmBase): } async def create(self, k8scluster_content, order_id): - op_id = k8scluster_content.pop("op_id", None) if not self.lcm_tasks.lock_HA("k8scluster", "create", op_id): return @@ -1299,8 +1283,33 @@ class K8sClusterLcm(LcmBase): self.logger.error(logging_text + "Cannot update database: {}".format(e)) self.lcm_tasks.remove("k8scluster", k8scluster_id, order_id) - async def delete(self, k8scluster_content, order_id): + async def edit(self, k8scluster_content, order_id): + op_id = k8scluster_content.pop("op_id", None) + if not self.lcm_tasks.lock_HA("k8scluster", "edit", op_id): + return + k8scluster_id = k8scluster_content["_id"] + + logging_text = "Task k8scluster_edit={} ".format(k8scluster_id) + self.logger.debug(logging_text + "Enter") + + # TODO the implementation is pending and will be part of a new feature + # It will support rotation of certificates, update of credentials and K8S API endpoint + # At the moment the operation is set as completed + + operation_state = "COMPLETED" + operation_details = "Not implemented" + + self.lcm_tasks.unlock_HA( + "k8scluster", + "edit", + op_id, + operationState=operation_state, + detailed_status=operation_details, + ) + self.lcm_tasks.remove("k8scluster", k8scluster_id, order_id) + + async def delete(self, k8scluster_content, order_id): # HA tasks and backward compatibility: # If 'vim_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing. @@ -1352,7 +1361,7 @@ class K8sClusterLcm(LcmBase): db_k8scluster_update["_admin.helm-chart.operationalState"] = "DISABLED" if k8s_h3c_id: - step = "Removing helm-chart-v3 '{}'".format(k8s_hc_id) + step = "Removing helm-chart-v3 '{}'".format(k8s_h3c_id) uninstall_sw = ( deep_get(db_k8scluster, ("_admin", "helm-chart-v3", "created")) or False @@ -1437,7 +1446,7 @@ class K8sClusterLcm(LcmBase): class VcaLcm(LcmBase): timeout_create = 30 - def __init__(self, msg, lcm_tasks, config, loop): + def __init__(self, msg, lcm_tasks, config): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', @@ -1445,15 +1454,12 @@ class VcaLcm(LcmBase): """ self.logger = logging.getLogger("lcm.vca") - self.loop = loop self.lcm_tasks = lcm_tasks super().__init__(msg, self.logger) # create N2VC connector - self.n2vc = N2VCJujuConnector( - log=self.logger, loop=self.loop, fs=self.fs, db=self.db - ) + self.n2vc = N2VCJujuConnector(log=self.logger, fs=self.fs, db=self.db) def _get_vca_by_id(self, vca_id: str) -> dict: db_vca = self.db.get_one("vca", {"_id": vca_id}) @@ -1619,7 +1625,6 @@ class VcaLcm(LcmBase): self.lcm_tasks.remove("vca", vca_id, order_id) async def delete(self, vca_content, order_id): - # HA tasks and backward compatibility: # If "vim_content" does not include "op_id", we a running a legacy NBI version. # In such a case, HA is not supported by NBI, "op_id" is None, and lock_HA() will do nothing. @@ -1674,7 +1679,7 @@ class VcaLcm(LcmBase): class K8sRepoLcm(LcmBase): - def __init__(self, msg, lcm_tasks, config, loop): + def __init__(self, msg, lcm_tasks, config): """ Init, Connect to database, filesystem storage, and messaging :param config: two level dictionary with configuration. Top level should contain 'database', 'storage', @@ -1682,7 +1687,6 @@ class K8sRepoLcm(LcmBase): """ self.logger = logging.getLogger("lcm.k8srepo") - self.loop = loop self.lcm_tasks = lcm_tasks self.vca_config = config["VCA"] @@ -1698,7 +1702,6 @@ class K8sRepoLcm(LcmBase): ) async def create(self, k8srepo_content, order_id): - # HA tasks and backward compatibility: # If 'vim_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing. @@ -1763,7 +1766,6 @@ class K8sRepoLcm(LcmBase): self.lcm_tasks.remove("k8srepo", k8srepo_id, order_id) async def delete(self, k8srepo_content, order_id): - # HA tasks and backward compatibility: # If 'vim_content' does not include 'op_id', we a running a legacy NBI version. # In such a case, HA is not supported by NBI, 'op_id' is None, and lock_HA() will do nothing.