Get VIM certificates from DB
[osm/osmclient.git] / osmclient / scripts / osm.py
index 02870e4..ab56a07 100755 (executable)
@@ -3082,6 +3082,20 @@ def pdu_delete(ctx, name, force):
 #################
 
 
+def _check_ca_cert(vim_config: dict) -> None:
+    """
+    Checks if the VIM has a CA certificate.
+    In that case, reads the content and add it to the config
+    : param vim_config: configuration provided with the VIM creation
+    : return: None
+    """
+
+    if vim_config.get("ca_cert"):
+        with open(vim_config["ca_cert"], "r") as cert_f:
+            vim_config["ca_cert_content"] = str(cert_f.read())
+            del vim_config["ca_cert"]
+
+
 @cli_osm.command(name="vim-create", short_help="creates a new VIM account")
 @click.option("--name", required=True, help="Name to create datacenter")
 @click.option("--user", default=None, help="VIM username")
@@ -3166,6 +3180,7 @@ def vim_create(
     if vca:
         vim["vca"] = vca
     vim_config = create_config(config_file, config)
+    _check_ca_cert(vim_config)
     if creds:
         with open(creds, "r") as cf:
             vim_config["credentials"] = yaml.safe_load(cf.read())
@@ -3263,6 +3278,7 @@ def vim_update(
     vim_config = None
     if config or config_file:
         vim_config = create_config(config_file, config)
+        _check_ca_cert(vim_config)
     if creds:
         with open(creds, "r") as cf:
             vim_config["credentials"] = yaml.safe_load(cf.read())