Update dependencies to use latest version of requests
[osm/osmclient.git] / osmclient / cli_commands / vim.py
index c6424ca..2f7bbfc 100755 (executable)
@@ -14,6 +14,7 @@
 #    under the License.
 
 import click
+from osmclient.common import print_output
 from osmclient.cli_commands import utils
 from prettytable import PrettyTable
 import yaml
@@ -75,6 +76,16 @@ def _check_ca_cert(vim_config: dict) -> None:
 @click.option(
     "--creds", default=None, help="credentials file (only applicable for GCP VIM type)"
 )
+@click.option(
+    "--prometheus_url",
+    default=None,
+    help="PrometheusTSBD URL to get VIM data",
+)
+@click.option(
+    "--prometheus_map",
+    default=None,
+    help="PrometheusTSBD metrics mapping for VIM data",
+)
 @click.option(
     "--prometheus_config_file",
     default=None,
@@ -97,6 +108,8 @@ def vim_create(
     wait,
     vca,
     creds,
+    prometheus_url,
+    prometheus_map,
     prometheus_config_file,
 ):
     """creates a new VIM account"""
@@ -106,11 +119,17 @@ def vim_create(
     if sdn_port_mapping:
         utils.check_client_version(ctx.obj, "--sdn_port_mapping")
     vim = {}
+    prometheus_config = {}
+    if prometheus_url:
+        prometheus_config["prometheus-url"] = prometheus_url
+    if prometheus_map:
+        prometheus_config["prometheus-map"] = prometheus_map
     if prometheus_config_file:
         with open(prometheus_config_file) as prometheus_file:
             prometheus_config_dict = json.load(prometheus_file)
-        vim["prometheus-config"] = prometheus_config_dict
-
+        prometheus_config.update(prometheus_config_dict)
+    if prometheus_config:
+        vim["prometheus-config"] = prometheus_config
     vim["vim-username"] = user
     vim["vim-password"] = password
     vim["vim-url"] = auth_url
@@ -166,6 +185,16 @@ def vim_create(
 @click.option(
     "--creds", default=None, help="credentials file (only applicable for GCP VIM type)"
 )
+@click.option(
+    "--prometheus_url",
+    default=None,
+    help="PrometheusTSBD URL to get VIM data",
+)
+@click.option(
+    "--prometheus_map",
+    default=None,
+    help="PrometheusTSBD metrics mapping for VIM data",
+)
 @click.option(
     "--prometheus_config_file",
     default=None,
@@ -188,6 +217,8 @@ def vim_update(
     sdn_port_mapping,
     wait,
     creds,
+    prometheus_url,
+    prometheus_map,
     prometheus_config_file,
 ):
     """updates a VIM account
@@ -218,11 +249,17 @@ def vim_update(
     if creds:
         with open(creds, "r") as cf:
             vim_config["credentials"] = yaml.safe_load(cf.read())
+    prometheus_config = {}
+    if prometheus_url:
+        prometheus_config["prometheus-url"] = prometheus_url
+    if prometheus_map:
+        prometheus_config["prometheus-map"] = prometheus_map
     if prometheus_config_file:
         with open(prometheus_config_file) as prometheus_file:
             prometheus_config_dict = json.load(prometheus_file)
-        vim["prometheus-config"] = prometheus_config_dict
-    logger.info(f"VIM: {vim}, VIM config: {vim_config}")
+        prometheus_config.update(prometheus_config_dict)
+    if prometheus_config:
+        vim["prometheus-config"] = prometheus_config
     ctx.obj.vim.update(
         name, vim, vim_config, sdn_controller, sdn_port_mapping, wait=wait
     )
@@ -267,16 +304,15 @@ def vim_delete(ctx, name, force, wait):
     is_flag=True,
     help="get more details of the NS (project, vim, deployment status, configuration status.",
 )
+@print_output.output_option
 @click.pass_context
-def vim_list(ctx, filter, long):
+def vim_list(ctx, filter, long, output):
     """list all VIM accounts"""
     logger.debug("")
     if filter:
         filter = "&".join(filter)
         utils.check_client_version(ctx.obj, "--filter")
-    fullclassname = ctx.obj.__module__ + "." + ctx.obj.__class__.__name__
-    if fullclassname == "osmclient.sol005.client.Client":
-        resp = ctx.obj.vim.list(filter)
+    resp = ctx.obj.vim.list(filter)
     if long:
         table = PrettyTable(
             ["vim name", "uuid", "project", "operational state", "error details"]
@@ -311,8 +347,7 @@ def vim_list(ctx, filter, long):
             table.add_row(
                 [vim["name"], vim["uuid"], vim["_admin"].get("operationalState", "-")]
             )
-    table.align = "l"
-    print(table)
+    print_output.print_output(output, table.field_names, table._rows)
 
 
 @click.command(name="vim-show", short_help="shows the details of a VIM account")
@@ -323,8 +358,9 @@ def vim_list(ctx, filter, long):
     help="restricts the information to the fields in the filter",
 )
 @click.option("--literal", is_flag=True, help="print literally, no pretty table")
+@print_output.output_option
 @click.pass_context
-def vim_show(ctx, name, filter, literal):
+def vim_show(ctx, name, filter, literal, output):
     """shows the details of a VIM account
 
     NAME: name or ID of the VIM account
@@ -343,5 +379,4 @@ def vim_show(ctx, name, filter, literal):
     for k, v in list(resp.items()):
         if not filter or k in filter:
             table.add_row([k, utils.wrap_text(text=json.dumps(v, indent=2), width=100)])
-    table.align = "l"
-    print(table)
+    print_output.print_output(output, table.field_names, table._rows)