X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Fk8s_juju_conn.py;h=5b158d7b7e0869716f42a6f54078c05a936b7c3f;hp=3d58385ede494b7e0378c0e3605a1bad2bb4808d;hb=refs%2Fchanges%2F40%2F10540%2F1;hpb=f6e9b00b6f7cd35e45ace4c84b53fe8d12b2438c diff --git a/n2vc/k8s_juju_conn.py b/n2vc/k8s_juju_conn.py index 3d58385..5b158d7 100644 --- a/n2vc/k8s_juju_conn.py +++ b/n2vc/k8s_juju_conn.py @@ -20,6 +20,7 @@ import tempfile import binascii import base64 +from n2vc.config import ModelConfig from n2vc.exceptions import K8sException, N2VCBadArgumentsException from n2vc.k8s_conn import K8sConnector from n2vc.kubectl import Kubectl, CORE_CLIENT, RBAC_CLIENT @@ -102,8 +103,7 @@ class K8sJujuConnector(K8sConnector): ) port = vca_config["port"] if "port" in vca_config else 17070 url = "{}:{}".format(vca_config["host"], port) - enable_os_upgrade = vca_config.get("enable_os_upgrade", True) - apt_mirror = vca_config.get("apt_mirror", None) + model_config = ModelConfig(vca_config) username = vca_config["user"] secret = vca_config["secret"] ca_cert = base64_to_cacert(vca_config["ca_cert"]) @@ -111,8 +111,7 @@ class K8sJujuConnector(K8sConnector): self.libjuju = Libjuju( endpoint=url, api_proxy=None, # Not needed for k8s charms - enable_os_upgrade=enable_os_upgrade, - apt_mirror=apt_mirror, + model_config=model_config, username=username, password=secret, cacert=ca_cert, @@ -456,6 +455,7 @@ class K8sJujuConnector(K8sConnector): self, cluster_uuid: str, kdu_model: str, + kdu_instance: str, atomic: bool = True, timeout: float = 1800, params: dict = None, @@ -467,6 +467,7 @@ class K8sJujuConnector(K8sConnector): :param cluster_uuid str: The UUID of the cluster to install to :param kdu_model str: The name or path of a bundle to install + :param kdu_instance: Kdu instance name :param atomic bool: If set, waits until the model is active and resets the cluster on failure. :param timeout int: The time, in seconds, to wait for the install @@ -500,11 +501,6 @@ class K8sJujuConnector(K8sConnector): os.chdir(new_workdir) bundle = "local:{}".format(kdu_model) - if kdu_name: - kdu_instance = "{}-{}".format(kdu_name, db_dict["filter"]["_id"]) - else: - kdu_instance = db_dict["filter"]["_id"] - self.log.debug("Checking for model named {}".format(kdu_instance)) # Create the new model @@ -571,8 +567,7 @@ class K8sJujuConnector(K8sConnector): # await model.disconnect() # await controller.disconnect() os.chdir(previous_workdir) - - return kdu_instance + return True async def instances_list(self, cluster_uuid: str) -> list: """ @@ -1477,3 +1472,13 @@ class K8sJujuConnector(K8sConnector): base64.b64decode(token).decode("utf-8"), base64.b64decode(client_certificate_data).decode("utf-8"), ) + + @staticmethod + def generate_kdu_instance_name(**kwargs): + db_dict = kwargs.get("db_dict") + kdu_name = kwargs.get("kdu_name", None) + if kdu_name: + kdu_instance = "{}-{}".format(kdu_name, db_dict["filter"]["_id"]) + else: + kdu_instance = db_dict["filter"]["_id"] + return kdu_instance