X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FN2VC.git;a=blobdiff_plain;f=n2vc%2Fk8s_conn.py;h=e49e49731868509b80b44f1d3cbcd26ab1284cd8;hp=d951c2c16200373ce72819ce74ecd84b11f2efc2;hb=2f2832cc214c058d3fce343cdd459ccddd770dad;hpb=3957ba32d3a898b7ccbb7ec1bd0c7df8fd88f367 diff --git a/n2vc/k8s_conn.py b/n2vc/k8s_conn.py index d951c2c..e49e497 100644 --- a/n2vc/k8s_conn.py +++ b/n2vc/k8s_conn.py @@ -50,20 +50,20 @@ class K8sConnector(abc.ABC, Loggable): # parent class Loggable.__init__(self, log=log, log_to_console=True, prefix='\nK8S') - self.info('Initializing generic K8S connector') + self.log.info('Initializing generic K8S connector') # the database and update callback self.db = db self.on_update_db = on_update_db - self.info('K8S generic connector initialized') + self.log.info('K8S generic connector initialized') @abc.abstractmethod async def init_env( self, k8s_creds: str, namespace: str = 'kube-system', - reuse_cluster_uuid = None + reuse_cluster_uuid=None ) -> (str, bool): """ It prepares a given K8s cluster environment to run Charts or juju Bundles on both sides: @@ -71,7 +71,8 @@ class K8sConnector(abc.ABC, Loggable): server (Tiller/Charm) :param k8s_creds: credentials to access a given K8s cluster, i.e. a valid '.kube/config' - :param namespace: optional namespace for helm tiller. By default, 'kube-system' will be used + :param namespace: optional namespace to be used for the K8s engine (helm tiller, juju). + By default, 'kube-system' will be used :param reuse_cluster_uuid: existing cluster uuid for reuse :return: uuid of the K8s cluster and True if connector has installed some software in the cluster (on error, an exception will be raised) @@ -121,6 +122,20 @@ class K8sConnector(abc.ABC, Loggable): :return: True if successful """ + @abc.abstractmethod + async def synchronize_repos( + self, + cluster_uuid: str, + name: str + ): + """ + Synchronizes the list of repositories created in the cluster with + the repositories added by the NBI + + :param cluster_uuid: the cluster + :return: List of repositories deleted from the cluster and dictionary with repos added + """ + @abc.abstractmethod async def reset( self, @@ -146,7 +161,8 @@ class K8sConnector(abc.ABC, Loggable): atomic: bool = True, timeout: float = 300, params: dict = None, - db_dict: dict = None + db_dict: dict = None, + kdu_name: str = None ): """ Deploys of a new KDU instance. It would implicitly rely on the `install` call to deploy the Chart/Bundle @@ -166,6 +182,7 @@ class K8sConnector(abc.ABC, Loggable): :param dict db_dict: where to write into database when the status changes. It contains a dict with {collection: , filter: {}, path: }, e.g. {collection: "nsrs", filter: {_id: , path: "_admin.deployed.K8S.3"} + :param kdu_name: Name of the KDU instance to be installed :return: True if successful """ @@ -237,30 +254,33 @@ class K8sConnector(abc.ABC, Loggable): @abc.abstractmethod async def inspect_kdu( self, - kdu_model: str + kdu_model: str, + repo_url: str = None ) -> str: """ - These calls will retrieve from the Charm/Bundle: + These calls will retrieve from the Chart/Bundle: - The list of configurable values and their defaults (e.g. in Charts, it would retrieve the contents of `values.yaml`). - If available, any embedded help file (e.g. `readme.md`) embedded in the Chart/Bundle. - :param cluster_uuid: the cluster to get the information :param kdu_model: chart/bundle reference - :return: If successful, it will return a dictionary containing the list of available parameters - and their default values + :param repo_url: optional, reposotory URL (None if tar.gz, URl in other cases, even stable URL) + :return: + + If successful, it will return the available parameters and their default values as provided by the backend. """ @abc.abstractmethod async def help_kdu( self, - kdu_model: str + kdu_model: str, + repo_url: str = None ) -> str: """ - :param cluster_uuid: the cluster to get the information :param kdu_model: chart/bundle reference + :param repo_url: optional, reposotory URL (None if tar.gz, URl in other cases, even stable URL) :return: If successful, it will return the contents of the 'readme.md' """ @@ -313,7 +333,7 @@ class K8sConnector(abc.ABC, Loggable): self.warning('No db_dict => No database write') return False - self.debug('status={}'.format(status)) + self.log.debug('status={}'.format(status)) try: @@ -346,5 +366,5 @@ class K8sConnector(abc.ABC, Loggable): return True except Exception as e: - self.info('Exception writing status to database: {}'.format(e)) + self.log.info('Exception writing status to database: {}'.format(e)) return False