Add decorator for all click commands requiring a hostname
Change-Id: I02d72d42d9fd1cd9dba8b4ed418b800e444742d7
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/osmclient/cli_commands/alarms.py b/osmclient/cli_commands/alarms.py
index bc6d52e..5428e86 100755
--- a/osmclient/cli_commands/alarms.py
+++ b/osmclient/cli_commands/alarms.py
@@ -25,6 +25,7 @@
@click.command(name="ns-alarm-create")
+@utils.require_hostname
@click.argument("name")
@click.option("--ns", prompt=True, help="NS instance id or name")
@click.option(
@@ -86,6 +87,7 @@
@click.command(name="alarm-show", short_help="show alarm details")
+@utils.require_hostname
@click.argument("uuid")
@click.pass_context
def alarm_show(ctx, uuid):
@@ -137,6 +139,7 @@
# List alarm
@click.command(name="alarm-list", short_help="list all alarms")
+@utils.require_hostname
@click.option(
"--ns_id", default=None, required=False, help="List out alarm for given ns id"
)
@@ -172,6 +175,7 @@
# Update alarm
@click.command(name="alarm-update", short_help="Update a alarm")
+@utils.require_hostname
@click.argument("uuid")
@click.option("--threshold", default=None, help="Alarm threshold")
@click.option("--is_enable", default=None, type=bool, help="enable or disable alarm")
diff --git a/osmclient/cli_commands/app_profile.py b/osmclient/cli_commands/app_profile.py
index af5647f..75f364a 100755
--- a/osmclient/cli_commands/app_profile.py
+++ b/osmclient/cli_commands/app_profile.py
@@ -16,7 +16,7 @@
#######################################################################################
import click
-from osmclient.cli_commands import common
+from osmclient.cli_commands import common, utils
from osmclient.common import print_output
import logging
@@ -24,6 +24,7 @@
@click.command(name="app-profile-create", short_help="creates an App Profile")
+@utils.require_hostname
@click.argument("name")
@click.option("--description", default="", help="human readable description")
@click.pass_context
@@ -42,6 +43,7 @@
@click.command(name="app-profile-delete", short_help="deletes an App Profile")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion from the DB (not recommended)"
@@ -57,6 +59,7 @@
@click.command(name="app-profile-list")
+@utils.require_hostname
@click.option(
"--filter",
help="restricts the list to the items matching the filter",
@@ -73,6 +76,7 @@
name="app-profile-show",
short_help="shows the details of an App Profile",
)
+@utils.require_hostname
@click.argument("name")
@print_output.output_option
@click.pass_context
@@ -86,6 +90,7 @@
@click.command(name="app-profile-update", short_help="updates an App Profile")
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the App Profile")
@click.option("--description", help="human readable description")
diff --git a/osmclient/cli_commands/cluster.py b/osmclient/cli_commands/cluster.py
index 6f4b56f..2acbed2 100755
--- a/osmclient/cli_commands/cluster.py
+++ b/osmclient/cli_commands/cluster.py
@@ -14,7 +14,7 @@
# under the License.
import click
-from osmclient.cli_commands import common
+from osmclient.cli_commands import common, utils
from osmclient.common import print_output
import logging
import yaml
@@ -23,6 +23,7 @@
@click.command(name="cluster-create", short_help="creates a K8s cluster")
+@utils.require_hostname
@click.argument("name")
@click.option("--node-count", "-n", prompt=True, type=int, help="number of nodes")
@click.option("--node-size", prompt=True, help="size of the worker nodes")
@@ -86,6 +87,7 @@
@click.command(name="cluster-delete", short_help="deletes a K8s cluster")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion from the DB (not recommended)"
@@ -101,6 +103,7 @@
@click.command(name="cluster-list")
+@utils.require_hostname
@click.option(
"--filter",
help="restricts the list to the items matching the filter",
@@ -144,6 +147,7 @@
name="cluster-show",
short_help="shows the details of a K8s cluster",
)
+@utils.require_hostname
@click.argument("name")
@print_output.output_option
@click.pass_context
@@ -159,6 +163,7 @@
@click.command(
name="cluster-edit", short_help="updates name or description of a K8s cluster"
)
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the K8s cluster")
@click.option("--description", help="human readable description")
@@ -176,6 +181,7 @@
@click.command(
name="cluster-upgrade", short_help="changes the version of a K8s cluster"
)
+@utils.require_hostname
@click.argument("name")
@click.option("--version", prompt=True, help="Kubernetes version")
@click.pass_context
@@ -192,6 +198,7 @@
@click.command(name="cluster-scale", short_help="scales a K8s cluster")
+@utils.require_hostname
@click.argument("name")
@click.option("--node-count", "-n", prompt=True, type=int, help="number of nodes")
@click.pass_context
@@ -208,6 +215,7 @@
@click.command(name="cluster-update", short_help="updates a K8s cluster")
+@utils.require_hostname
@click.argument("name")
@click.option("--version", help="Kubernetes version")
@click.option("--node-count", "-n", type=int, help="number of nodes")
@@ -232,6 +240,7 @@
@click.command(
name="cluster-get-credentials", short_help="gets kubeconfig of a K8s cluster"
)
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def cluster_get_credentials(ctx, name, **kwargs):
@@ -247,6 +256,7 @@
@click.command(
name="cluster-get-kubeconfig", short_help="gets kubeconfig of a K8s cluster"
)
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def cluster_get_kubeconfig(ctx, name, **kwargs):
@@ -255,6 +265,7 @@
@click.command(name="cluster-register", short_help="registers a K8s cluster to OSM")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--vim-account",
@@ -298,6 +309,7 @@
@click.command(name="cluster-deregister", short_help="deregisters a K8s cluster")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion from the DB (not recommended)"
diff --git a/osmclient/cli_commands/infra_config_profile.py b/osmclient/cli_commands/infra_config_profile.py
index e9f592d..7a86c93 100755
--- a/osmclient/cli_commands/infra_config_profile.py
+++ b/osmclient/cli_commands/infra_config_profile.py
@@ -16,7 +16,7 @@
#######################################################################################
import click
-from osmclient.cli_commands import common
+from osmclient.cli_commands import common, utils
from osmclient.common import print_output
import logging
@@ -26,6 +26,7 @@
@click.command(
name="infra-config-profile-create", short_help="creates an Infra Config Profile"
)
+@utils.require_hostname
@click.argument("name")
@click.option("--description", default="", help="human readable description")
@click.pass_context
@@ -46,6 +47,7 @@
@click.command(
name="infra-config-profile-delete", short_help="deletes an Infra Config Profile"
)
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion from the DB (not recommended)"
@@ -61,6 +63,7 @@
@click.command(name="infra-config-profile-list")
+@utils.require_hostname
@click.option(
"--filter",
help="restricts the list to the items matching the filter",
@@ -79,6 +82,7 @@
name="infra-config-profile-show",
short_help="shows the details of an Infra Config Profile",
)
+@utils.require_hostname
@click.argument("name")
@print_output.output_option
@click.pass_context
@@ -96,6 +100,7 @@
@click.command(
name="infra-config-profile-update", short_help="updates an Infra Config Profile"
)
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the Infra Config Profile")
@click.option("--description", help="human readable description")
diff --git a/osmclient/cli_commands/infra_controller_profile.py b/osmclient/cli_commands/infra_controller_profile.py
index c764bae..213c158 100755
--- a/osmclient/cli_commands/infra_controller_profile.py
+++ b/osmclient/cli_commands/infra_controller_profile.py
@@ -16,7 +16,7 @@
#######################################################################################
import click
-from osmclient.cli_commands import common
+from osmclient.cli_commands import common, utils
from osmclient.common import print_output
import logging
@@ -27,6 +27,7 @@
name="infra-controller-profile-create",
short_help="creates an Infra Controller Profile",
)
+@utils.require_hostname
@click.argument("name")
@click.option("--description", default="", help="human readable description")
@click.pass_context
@@ -48,6 +49,7 @@
name="infra-controller-profile-delete",
short_help="deletes an Infra Controller Profile",
)
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion from the DB (not recommended)"
@@ -63,6 +65,7 @@
@click.command(name="infra-controller-profile-list")
+@utils.require_hostname
@click.option(
"--filter",
help="restricts the list to the items matching the filter",
@@ -81,6 +84,7 @@
name="infra-controller-profile-show",
short_help="shows the details of an Infra Controller Profile",
)
+@utils.require_hostname
@click.argument("name")
@click.pass_context
@print_output.output_option
@@ -99,6 +103,7 @@
name="infra-controller-profile-update",
short_help="updates an Infra Controller Profile",
)
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the Infra Controller Profile")
@click.option("--description", help="human readable description")
diff --git a/osmclient/cli_commands/k8scluster.py b/osmclient/cli_commands/k8scluster.py
index 380d311..a61978f 100755
--- a/osmclient/cli_commands/k8scluster.py
+++ b/osmclient/cli_commands/k8scluster.py
@@ -24,6 +24,7 @@
@click.command(name="k8scluster-add", short_help="adds a K8s cluster to OSM")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--creds", prompt=True, help="credentials file, i.e. a valid `.kube/config` file"
@@ -114,6 +115,7 @@
@click.command(name="k8scluster-update", short_help="updates a K8s cluster")
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the K8s cluster")
@click.option("--creds", help="credentials file, i.e. a valid `.kube/config` file")
@@ -171,6 +173,7 @@
@click.command(name="k8scluster-delete", short_help="deletes a K8s cluster")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion from the DB (not recommended)"
@@ -194,6 +197,7 @@
@click.command(name="k8scluster-list")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -281,6 +285,7 @@
@click.command(name="k8scluster-show", short_help="shows the details of a K8s cluster")
+@utils.require_hostname
@click.argument("name")
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.pass_context
diff --git a/osmclient/cli_commands/ksu.py b/osmclient/cli_commands/ksu.py
index 8fddacb..63ff78c 100755
--- a/osmclient/cli_commands/ksu.py
+++ b/osmclient/cli_commands/ksu.py
@@ -16,7 +16,7 @@
#######################################################################################
import click
-from osmclient.cli_commands import common
+from osmclient.cli_commands import common, utils
from osmclient.common.exceptions import ClientException
from osmclient.common import print_output
import logging
@@ -223,6 +223,7 @@
ignore_unknown_options=True,
),
)
+@utils.require_hostname
@click.argument(
"args",
nargs=-1,
@@ -264,6 +265,7 @@
@click.command(name="ksu-delete", short_help="deletes one or several KSU")
+@utils.require_hostname
@click.argument("ksus", type=str, nargs=-1, metavar="<KSU> [<KSU>...]")
@click.option(
"--force", is_flag=True, help="forces the deletion from the DB (not recommended)"
@@ -279,6 +281,7 @@
@click.command(name="ksu-list")
+@utils.require_hostname
@click.option(
"--filter",
help="restricts the list to the items matching the filter",
@@ -292,6 +295,7 @@
@click.command(name="ksu-show", short_help="shows the details of a KSU")
+@utils.require_hostname
@click.argument("name")
@print_output.output_option
@click.pass_context
@@ -311,6 +315,7 @@
ignore_unknown_options=True,
),
)
+@utils.require_hostname
@click.argument(
"args",
nargs=-1,
diff --git a/osmclient/cli_commands/metrics.py b/osmclient/cli_commands/metrics.py
index fc62595..327a598 100755
--- a/osmclient/cli_commands/metrics.py
+++ b/osmclient/cli_commands/metrics.py
@@ -25,6 +25,7 @@
name="ns-metric-export",
short_help="exports a metric to the internal OSM bus, which can be read by other apps",
)
+@utils.require_hostname
@click.option("--ns", prompt=True, help="NS instance id or name")
@click.option(
"--vnf", prompt=True, help="VNF name (VNF member index as declared in the NSD)"
diff --git a/osmclient/cli_commands/netslice_instance.py b/osmclient/cli_commands/netslice_instance.py
index 3799f47..1b7015d 100755
--- a/osmclient/cli_commands/netslice_instance.py
+++ b/osmclient/cli_commands/netslice_instance.py
@@ -58,6 +58,7 @@
@click.command(name="nsi-list", short_help="list all Network Slice Instances (NSI)")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -74,6 +75,7 @@
@click.command(
name="netslice-instance-list", short_help="list all Network Slice Instances (NSI)"
)
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -109,6 +111,7 @@
@click.command(
name="nsi-show", short_help="shows the content of a Network Slice Instance (NSI)"
)
+@utils.require_hostname
@click.argument("name")
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.option(
@@ -130,6 +133,7 @@
name="netslice-instance-show",
short_help="shows the content of a Network Slice Instance (NSI)",
)
+@utils.require_hostname
@click.argument("name")
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.option(
@@ -171,6 +175,7 @@
@click.command(name="nsi-create", short_help="creates a new Network Slice Instance")
+@utils.require_hostname
@click.option("--nsi_name", prompt=True, help="name of the Network Slice Instance")
@click.option("--nst_name", prompt=True, help="name of the Network Slice Template")
@click.option(
@@ -219,6 +224,7 @@
@click.command(
name="netslice-instance-create", short_help="creates a new Network Slice Instance"
)
+@utils.require_hostname
@click.option("--nsi_name", prompt=True, help="name of the Network Slice Instance")
@click.option("--nst_name", prompt=True, help="name of the Network Slice Template")
@click.option(
@@ -269,6 +275,7 @@
@click.command(name="nsi-delete", short_help="deletes a Network Slice Instance (NSI)")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
@@ -294,6 +301,7 @@
@click.command(
name="netslice-instance-delete", short_help="deletes a Network Slice Instance (NSI)"
)
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
diff --git a/osmclient/cli_commands/netslice_ops.py b/osmclient/cli_commands/netslice_ops.py
index d891f45..0345c79 100755
--- a/osmclient/cli_commands/netslice_ops.py
+++ b/osmclient/cli_commands/netslice_ops.py
@@ -37,6 +37,7 @@
name="nsi-op-list",
short_help="shows the history of operations over a Network Slice Instance (NSI)",
)
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def nsi_op_list1(ctx, name):
@@ -52,6 +53,7 @@
name="netslice-instance-op-list",
short_help="shows the history of operations over a Network Slice Instance (NSI)",
)
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def nsi_op_list2(ctx, name):
@@ -80,6 +82,7 @@
name="nsi-op-show",
short_help="shows the info of an operation over a Network Slice Instance(NSI)",
)
+@utils.require_hostname
@click.argument("id")
@click.option(
"--filter",
@@ -100,6 +103,7 @@
name="netslice-instance-op-show",
short_help="shows the info of an operation over a Network Slice Instance(NSI)",
)
+@utils.require_hostname
@click.argument("id")
@click.option(
"--filter",
diff --git a/osmclient/cli_commands/netslice_template.py b/osmclient/cli_commands/netslice_template.py
index 8ae780c..d04a4e0 100755
--- a/osmclient/cli_commands/netslice_template.py
+++ b/osmclient/cli_commands/netslice_template.py
@@ -38,6 +38,7 @@
@click.command(name="nst-list", short_help="list all Network Slice Templates (NST)")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -54,6 +55,7 @@
@click.command(
name="netslice-template-list", short_help="list all Network Slice Templates (NST)"
)
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -87,6 +89,7 @@
@click.command(
name="nst-show", short_help="shows the content of a Network Slice Template (NST)"
)
+@utils.require_hostname
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.argument("name")
@click.pass_context
@@ -103,6 +106,7 @@
name="netslice-template-show",
short_help="shows the content of a Network Slice Template (NST)",
)
+@utils.require_hostname
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.argument("name")
@click.pass_context
@@ -124,6 +128,7 @@
@click.command(
name="nst-create", short_help="creates a new Network Slice Template (NST)"
)
+@utils.require_hostname
@click.argument("filename")
@click.option(
"--overwrite",
@@ -152,6 +157,7 @@
name="netslice-template-create",
short_help="creates a new Network Slice Template (NST)",
)
+@utils.require_hostname
@click.argument("filename")
@click.option(
"--overwrite",
@@ -183,6 +189,7 @@
@click.command(name="nst-update", short_help="updates a Network Slice Template (NST)")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--content",
@@ -202,6 +209,7 @@
@click.command(
name="netslice-template-update", short_help="updates a Network Slice Template (NST)"
)
+@utils.require_hostname
@click.argument("name")
@click.option(
"--content",
@@ -225,6 +233,7 @@
@click.command(name="nst-delete", short_help="deletes a Network Slice Template (NST)")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
@@ -242,6 +251,7 @@
@click.command(
name="netslice-template-delete", short_help="deletes a Network Slice Template (NST)"
)
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
diff --git a/osmclient/cli_commands/nfpkg.py b/osmclient/cli_commands/nfpkg.py
index 8d3f01b..c8691bb 100755
--- a/osmclient/cli_commands/nfpkg.py
+++ b/osmclient/cli_commands/nfpkg.py
@@ -106,6 +106,7 @@
@click.command(name="vnfd-list", short_help="list all xNF packages (VNF, HNF, PNF)")
+@utils.require_hostname
@click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
@click.option(
"--filter",
@@ -122,6 +123,7 @@
@click.command(name="vnfpkg-list", short_help="list all xNF packages (VNF, HNF, PNF)")
+@utils.require_hostname
@click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
@click.option(
"--filter",
@@ -138,6 +140,7 @@
@click.command(name="nfpkg-list", short_help="list all xNF packages (VNF, HNF, PNF)")
+@utils.require_hostname
@click.option("--nf_type", help="type of NF (vnf, pnf, hnf)")
@click.option(
"--filter",
@@ -171,6 +174,7 @@
@click.command(name="vnfd-show", short_help="shows the details of a NF package")
+@utils.require_hostname
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.argument("name")
@click.pass_context
@@ -184,6 +188,7 @@
@click.command(name="vnfpkg-show", short_help="shows the details of a NF package")
+@utils.require_hostname
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.argument("name")
@click.pass_context
@@ -197,6 +202,7 @@
@click.command(name="nfpkg-show", short_help="shows the details of a NF package")
+@utils.require_hostname
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.argument("name")
@click.pass_context
@@ -236,6 +242,7 @@
@click.command(name="vnfd-create", short_help="creates a new VNFD/VNFpkg")
+@utils.require_hostname
@click.argument("filename")
@click.option(
"--overwrite", "overwrite", default=None, help="overwrite deprecated, use override"
@@ -316,6 +323,7 @@
@click.command(name="vnfpkg-create", short_help="creates a new VNFD/VNFpkg")
+@utils.require_hostname
@click.argument("filename")
@click.option(
"--overwrite",
@@ -399,6 +407,7 @@
@click.command(name="nfpkg-create", short_help="creates a new NFpkg")
+@utils.require_hostname
@click.argument("filename")
@click.option(
"--overwrite",
@@ -489,6 +498,7 @@
@click.command(name="vnfd-update", short_help="updates a new VNFD/VNFpkg")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--content",
@@ -506,6 +516,7 @@
@click.command(name="vnfpkg-update", short_help="updates a VNFD/VNFpkg")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--content",
@@ -523,6 +534,7 @@
@click.command(name="nfpkg-update", short_help="updates a NFpkg")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--content", default=None, help="filename with the NFpkg replacing the current one"
@@ -547,6 +559,7 @@
@click.command(name="vnfd-delete", short_help="deletes a VNFD/VNFpkg")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
@@ -562,6 +575,7 @@
@click.command(name="vnfpkg-delete", short_help="deletes a VNFD/VNFpkg")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
@@ -577,6 +591,7 @@
@click.command(name="nfpkg-delete", short_help="deletes a NFpkg")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
diff --git a/osmclient/cli_commands/ns.py b/osmclient/cli_commands/ns.py
index 972bfa3..d7687b9 100755
--- a/osmclient/cli_commands/ns.py
+++ b/osmclient/cli_commands/ns.py
@@ -27,6 +27,7 @@
@click.command(name="ns-list", short_help="list all NS instances")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -280,6 +281,7 @@
@click.command(name="ns-show", short_help="shows the info of a NS instance")
+@utils.require_hostname
@click.argument("name")
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.option(
@@ -311,6 +313,7 @@
@click.command(name="ns-create", short_help="creates a new Network Service instance")
+@utils.require_hostname
@click.option("--ns_name", prompt=True, help="name of the NS instance")
@click.option("--nsd_name", prompt=True, help="name of the NS descriptor")
@click.option(
@@ -385,6 +388,7 @@
@click.command(name="ns-delete", short_help="deletes NS instances")
+@utils.require_hostname
@click.argument(
"names", nargs=-1, type=click.UNPROCESSED, callback=process_ns_multi_delete_params
)
diff --git a/osmclient/cli_commands/nslcm.py b/osmclient/cli_commands/nslcm.py
index d206db2..9e58844 100755
--- a/osmclient/cli_commands/nslcm.py
+++ b/osmclient/cli_commands/nslcm.py
@@ -26,6 +26,7 @@
@click.command(
name="ns-action", short_help="executes an action/primitive over a NS instance"
)
+@utils.require_hostname
@click.argument("ns_name")
@click.option(
"--vnf_name",
@@ -95,6 +96,7 @@
@click.command(
name="vnf-scale", short_help="executes a VNF scale (adding/removing VDUs)"
)
+@utils.require_hostname
@click.argument("ns_name")
@click.argument("vnf_name")
@click.option(
@@ -271,6 +273,7 @@
ignore_unknown_options=True,
),
)
+@utils.require_hostname
@click.argument("ns_name")
@click.argument(
"args",
@@ -362,6 +365,7 @@
ignore_unknown_options=True,
),
)
+@utils.require_hostname
@click.argument("vnf_name")
@click.argument(
"args",
diff --git a/osmclient/cli_commands/nslcm_ops.py b/osmclient/cli_commands/nslcm_ops.py
index 9528d08..f9b3c0f 100755
--- a/osmclient/cli_commands/nslcm_ops.py
+++ b/osmclient/cli_commands/nslcm_ops.py
@@ -27,6 +27,7 @@
@click.command(
name="ns-op-list", short_help="shows the history of operations over a NS instance"
)
+@utils.require_hostname
@click.argument("name")
@click.option(
"--long", is_flag=True, help="get more details of the NS operation (date, )."
@@ -122,6 +123,7 @@
@click.command(name="ns-op-show", short_help="shows the info of a NS operation")
+@utils.require_hostname
@click.argument("id")
@click.option(
"--filter",
@@ -152,6 +154,7 @@
@click.command(name="ns-op-cancel", short_help="cancels an ongoing NS operation")
+@utils.require_hostname
@click.argument("id")
@click.option(
"--cancel_mode",
diff --git a/osmclient/cli_commands/nspkg.py b/osmclient/cli_commands/nspkg.py
index 5195d81..ab920cf 100755
--- a/osmclient/cli_commands/nspkg.py
+++ b/osmclient/cli_commands/nspkg.py
@@ -78,6 +78,7 @@
@click.command(name="nsd-list", short_help="list all NS packages")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -93,6 +94,7 @@
@click.command(name="nspkg-list", short_help="list all NS packages")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -124,6 +126,7 @@
@click.command(name="nsd-show", short_help="shows the details of a NS package")
+@utils.require_hostname
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.argument("name")
@click.pass_context
@@ -137,6 +140,7 @@
@click.command(name="nspkg-show", short_help="shows the details of a NS package")
+@utils.require_hostname
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.argument("name")
@click.pass_context
@@ -158,6 +162,7 @@
@click.command(name="nsd-create", short_help="creates a new NSD/NSpkg")
+@utils.require_hostname
@click.argument("filename")
@click.option(
"--overwrite",
@@ -207,6 +212,7 @@
@click.command(name="nspkg-create", short_help="creates a new NSD/NSpkg")
+@utils.require_hostname
@click.argument("filename")
@click.option(
"--overwrite",
@@ -261,6 +267,7 @@
@click.command(name="nsd-update", short_help="updates a NSD/NSpkg")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--content",
@@ -278,6 +285,7 @@
@click.command(name="nspkg-update", short_help="updates a NSD/NSpkg")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--content",
@@ -304,6 +312,7 @@
@click.command(name="nsd-delete", short_help="deletes a NSD/NSpkg")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
@@ -319,6 +328,7 @@
@click.command(name="nspkg-delete", short_help="deletes a NSD/NSpkg")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
@@ -334,6 +344,7 @@
@click.command(name="nsconfig-list", short_help="list all NS Config Templates")
+@utils.require_hostname
@click.option(
"--nsd",
default=None,
@@ -407,6 +418,7 @@
@click.command(
name="nsconfig-show", short_help="shows the details of a Ns config template"
)
+@utils.require_hostname
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.argument("name")
@click.pass_context
@@ -430,6 +442,7 @@
@click.command(name="nsconfig-delete", short_help="deletes a Ns config template")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
@@ -449,6 +462,7 @@
@click.command(name="nsconfig-create", short_help="creates a Ns config template")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--config_file",
@@ -474,6 +488,7 @@
@click.command(
name="nsconfig-update", short_help="update content of Ns config template"
)
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the Ns config template")
@click.option(
diff --git a/osmclient/cli_commands/oka.py b/osmclient/cli_commands/oka.py
index a6457d9..55b1d3c 100755
--- a/osmclient/cli_commands/oka.py
+++ b/osmclient/cli_commands/oka.py
@@ -16,7 +16,7 @@
#######################################################################################
import click
-from osmclient.cli_commands import common
+from osmclient.cli_commands import common, utils
from osmclient.common import print_output
import logging
@@ -99,6 +99,7 @@
@click.command(name="oka-add", short_help="adds an OSM Kubernetes Application (OKA)")
+@utils.require_hostname
@click.argument("name")
@click.argument("path")
@click.option(
@@ -141,6 +142,7 @@
@click.command(
name="oka-delete", short_help="deletes an OSM Kubernetes Application (OKA)"
)
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion from the DB (not recommended)"
@@ -156,6 +158,7 @@
@click.command(name="oka-list")
+@utils.require_hostname
@click.option(
"--filter",
help="restricts the list to the items matching the filter",
@@ -172,6 +175,7 @@
name="oka-show",
short_help="shows the details of an OKA",
)
+@utils.require_hostname
@click.argument("name")
@print_output.output_option
@click.pass_context
@@ -187,6 +191,7 @@
@click.command(
name="oka-update", short_help="updates an OSM Kubernetes Application (OKA)"
)
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the OSM Kubernetes Application (OKA)")
@click.option("--description", help="human readable description")
@@ -205,6 +210,7 @@
name="oka-update-content",
short_help="updates the content of an OKA",
)
+@utils.require_hostname
@click.argument("name")
@click.argument("path")
@click.pass_context
diff --git a/osmclient/cli_commands/other.py b/osmclient/cli_commands/other.py
index d2ce70f..28b46be 100755
--- a/osmclient/cli_commands/other.py
+++ b/osmclient/cli_commands/other.py
@@ -22,6 +22,7 @@
@click.command(name="version", short_help="shows client and server versions")
+@utils.require_hostname
@click.pass_context
def get_version(ctx):
"""shows client and server versions"""
diff --git a/osmclient/cli_commands/packages.py b/osmclient/cli_commands/packages.py
index 3853a30..7426981 100755
--- a/osmclient/cli_commands/packages.py
+++ b/osmclient/cli_commands/packages.py
@@ -282,6 +282,7 @@
# TODO: check if this command should be here. It is more related to nspkg and nfpkg
@click.command(name="upload-package", short_help="uploads a VNF package or NS package")
+@utils.require_hostname
@click.argument("filename")
@click.option(
"--skip-charm-build",
diff --git a/osmclient/cli_commands/pdus.py b/osmclient/cli_commands/pdus.py
index b1fc768..0d6d23c 100755
--- a/osmclient/cli_commands/pdus.py
+++ b/osmclient/cli_commands/pdus.py
@@ -25,6 +25,7 @@
@click.command(name="pdu-list", short_help="list all Physical Deployment Units (PDU)")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -57,6 +58,7 @@
@click.command(
name="pdu-show", short_help="shows the content of a Physical Deployment Unit (PDU)"
)
+@utils.require_hostname
@click.argument("name")
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.option(
@@ -91,6 +93,7 @@
@click.command(
name="pdu-create", short_help="adds a new Physical Deployment Unit to the catalog"
)
+@utils.require_hostname
@click.option("--name", help="name of the Physical Deployment Unit")
@click.option("--pdu_type", help="type of PDU (e.g. router, firewall, FW001)")
@click.option(
@@ -130,6 +133,7 @@
@click.command(
name="pdu-update", short_help="updates a Physical Deployment Unit to the catalog"
)
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the Physical Deployment Unit")
@click.option("--pdu_type", help="type of PDU (e.g. router, firewall, FW001)")
@@ -218,6 +222,7 @@
@click.command(name="pdu-delete", short_help="deletes a Physical Deployment Unit (PDU)")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
diff --git a/osmclient/cli_commands/profiles.py b/osmclient/cli_commands/profiles.py
index cfc7faf..821fca3 100755
--- a/osmclient/cli_commands/profiles.py
+++ b/osmclient/cli_commands/profiles.py
@@ -18,11 +18,13 @@
import click
import logging
from osmclient.common import print_output
+from osmclient.cli_commands import utils
logger = logging.getLogger("osmclient")
@click.command(name="profile-list")
+@utils.require_hostname
@click.option(
"--filter",
help="restricts the list to the items matching the filter",
@@ -82,6 +84,7 @@
@click.command(name="attach-profile")
+@utils.require_hostname
@click.argument("profile")
@click.argument("cluster")
@click.option(
@@ -114,6 +117,7 @@
@click.command(name="detach-profile")
+@utils.require_hostname
@click.argument("profile")
@click.argument("cluster")
@click.option(
diff --git a/osmclient/cli_commands/rbac.py b/osmclient/cli_commands/rbac.py
index c51e229..2bab34a 100755
--- a/osmclient/cli_commands/rbac.py
+++ b/osmclient/cli_commands/rbac.py
@@ -30,6 +30,7 @@
@click.command(name="role-create", short_help="creates a new role")
+@utils.require_hostname
@click.argument("name")
@click.option("--permissions", default=None, help="role permissions using a dictionary")
@click.pass_context
@@ -47,6 +48,7 @@
@click.command(name="role-update", short_help="updates a role")
+@utils.require_hostname
@click.argument("name")
@click.option("--set-name", default=None, help="change name of rle")
@click.option(
@@ -72,6 +74,7 @@
@click.command(name="role-delete", short_help="deletes a role")
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def role_delete(ctx, name):
@@ -87,6 +90,7 @@
@click.command(name="role-list", short_help="list all roles")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -111,6 +115,7 @@
@click.command(name="role-show", short_help="show specific role")
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def role_show(ctx, name):
@@ -137,6 +142,7 @@
@click.command(name="project-create", short_help="creates a new project")
+@utils.require_hostname
@click.argument("name")
# @click.option('--description',
# default='no description',
@@ -187,6 +193,7 @@
@click.command(name="project-delete", short_help="deletes a project")
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def project_delete(ctx, name):
@@ -200,6 +207,7 @@
@click.command(name="project-list", short_help="list all projects")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -222,6 +230,7 @@
@click.command(name="project-show", short_help="shows the details of a project")
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def project_show(ctx, name):
@@ -243,6 +252,7 @@
@click.command(
name="project-update", short_help="updates a project (only the name can be updated)"
)
+@utils.require_hostname
@click.argument("project")
@click.option("--name", default=None, help="new name for the project")
@click.option(
@@ -282,6 +292,7 @@
@click.command(name="user-create", short_help="creates a new user")
+@utils.require_hostname
@click.argument("username")
@click.option(
"--password",
@@ -338,6 +349,7 @@
@click.command(name="user-update", short_help="updates user information")
+@utils.require_hostname
@click.argument("username")
@click.option("--set-username", "set_username", default=None, help="change username")
@click.option("--email", "email", default=None, help="Change User's email address")
@@ -441,6 +453,7 @@
@click.command(name="user-delete", short_help="deletes a user")
+@utils.require_hostname
@click.argument("name")
# @click.option('--force', is_flag=True, help='forces the deletion bypassing pre-conditions')
@click.pass_context
@@ -456,6 +469,7 @@
@click.command(name="user-list", short_help="list all users")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -499,6 +513,7 @@
@click.command(name="user-show", short_help="shows the details of a user")
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def user_show(ctx, name):
@@ -520,6 +535,7 @@
@click.command(name="user-reset-password", short_help="Resetting a user's password")
+@utils.require_hostname
@click.option("--email", "email", help="Email of the user")
@click.pass_context
def user_reset_password(ctx, email):
diff --git a/osmclient/cli_commands/repo.py b/osmclient/cli_commands/repo.py
index b2ecd9a..3a80735 100755
--- a/osmclient/cli_commands/repo.py
+++ b/osmclient/cli_commands/repo.py
@@ -25,6 +25,7 @@
@click.command(name="repo-add", short_help="adds a repo to OSM")
+@utils.require_hostname
@click.argument("name")
@click.argument("uri")
@click.option(
@@ -84,6 +85,7 @@
@click.command(name="repo-update", short_help="updates a repo in OSM")
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the repo")
@click.option("--uri", help="URI of the repo")
@@ -155,6 +157,7 @@
@click.command(name="repo-list")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -191,6 +194,7 @@
@click.command(name="repo-show", short_help="shows the details of a repo")
+@utils.require_hostname
@click.argument("name")
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.pass_context
diff --git a/osmclient/cli_commands/resource_profile.py b/osmclient/cli_commands/resource_profile.py
index d084afe..e1ff670 100755
--- a/osmclient/cli_commands/resource_profile.py
+++ b/osmclient/cli_commands/resource_profile.py
@@ -16,7 +16,7 @@
#######################################################################################
import click
-from osmclient.cli_commands import common
+from osmclient.cli_commands import common, utils
from osmclient.common import print_output
import logging
@@ -26,6 +26,7 @@
@click.command(
name="resource-profile-create", short_help="creates an Resource Profile to OSM"
)
+@utils.require_hostname
@click.argument("name")
@click.option("--description", default=None, help="human readable description")
@click.pass_context
@@ -44,6 +45,7 @@
@click.command(name="resource-profile-delete", short_help="deletes an Resource Profile")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion from the DB (not recommended)"
@@ -59,6 +61,7 @@
@click.command(name="resource-profile-list")
+@utils.require_hostname
@click.option(
"--filter",
help="restricts the list to the items matching the filter",
@@ -77,6 +80,7 @@
name="resource-profile-show",
short_help="shows the details of an Resource Profile",
)
+@utils.require_hostname
@click.argument("name")
@print_output.output_option
@click.pass_context
@@ -90,6 +94,7 @@
@click.command(name="resource-profile-update", short_help="updates an Resource Profile")
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the Resource Profile")
@click.option("--description", help="human readable description")
diff --git a/osmclient/cli_commands/sdnc.py b/osmclient/cli_commands/sdnc.py
index 2bcd770..1ad18fc 100755
--- a/osmclient/cli_commands/sdnc.py
+++ b/osmclient/cli_commands/sdnc.py
@@ -23,6 +23,7 @@
@click.command(name="sdnc-create", short_help="creates a new SDN controller")
+@utils.require_hostname
@click.option("--name", prompt=True, help="Name to create sdn controller")
@click.option("--type", prompt=True, help="SDN controller type")
@click.option(
@@ -85,6 +86,7 @@
@click.command(name="sdnc-update", short_help="updates an SDN controller")
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the SDN controller")
@click.option("--description", default=None, help="human readable description")
@@ -150,6 +152,7 @@
@click.command(name="sdnc-delete", short_help="deletes an SDN controller")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
@@ -173,6 +176,7 @@
@click.command(name="sdnc-list", short_help="list all SDN controllers")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -195,6 +199,7 @@
@click.command(name="sdnc-show", short_help="shows the details of an SDN controller")
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def sdnc_show(ctx, name):
diff --git a/osmclient/cli_commands/subscriptions.py b/osmclient/cli_commands/subscriptions.py
index 3dc3c38..31506ad 100755
--- a/osmclient/cli_commands/subscriptions.py
+++ b/osmclient/cli_commands/subscriptions.py
@@ -27,6 +27,7 @@
name="subscription-create",
short_help="creates a new subscription to a specific event",
)
+@utils.require_hostname
@click.option(
"--event_type",
# type=click.Choice(['ns', 'nspkg', 'vnfpkg'], case_sensitive=False))
@@ -53,6 +54,7 @@
@click.command(name="subscription-delete", short_help="deletes a subscription")
+@utils.require_hostname
@click.option(
"--event_type",
# type=click.Choice(['ns', 'nspkg', 'vnfpkg'], case_sensitive=False))
@@ -75,6 +77,7 @@
@click.command(name="subscription-list", short_help="list all subscriptions")
+@utils.require_hostname
@click.option(
"--event_type",
# type=click.Choice(['ns', 'nspkg', 'vnfpkg'], case_sensitive=False))
@@ -111,6 +114,7 @@
@click.command(
name="subscription-show", short_help="shows the details of a subscription"
)
+@utils.require_hostname
@click.argument("subscription_id")
@click.option(
"--event_type",
diff --git a/osmclient/cli_commands/utils.py b/osmclient/cli_commands/utils.py
index e34926a..4ef7ad4 100755
--- a/osmclient/cli_commands/utils.py
+++ b/osmclient/cli_commands/utils.py
@@ -13,10 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
+import functools
import textwrap
import logging
import shutil
import yaml
+import click
from osmclient.common.exceptions import ClientException
logger = logging.getLogger("osmclient")
@@ -102,3 +104,18 @@
for k, v in cdict.items():
config[k] = v
return config
+
+
+def require_hostname(command):
+ @functools.wraps(command)
+ @click.pass_context
+ def wrapper(ctx, *args, **kwargs):
+ logger.debug("")
+ hostname = ctx.parent.params.get("hostname") if ctx.parent else None
+ if not hostname:
+ raise click.UsageError(
+ "This command requires --hostname or OSM_HOSTNAME to be set."
+ )
+ return ctx.invoke(command, *args, **kwargs)
+
+ return wrapper
diff --git a/osmclient/cli_commands/vca.py b/osmclient/cli_commands/vca.py
index fc33962..7cec847 100755
--- a/osmclient/cli_commands/vca.py
+++ b/osmclient/cli_commands/vca.py
@@ -27,6 +27,7 @@
@click.command(name="vca-add", short_help="adds a VCA (Juju controller) to OSM")
+# @utils.require_hostname
@click.argument("name")
@click.option(
"--endpoints",
@@ -129,6 +130,7 @@
@click.command(name="vca-update", short_help="updates a VCA")
+# @utils.require_hostname
@click.argument("name")
@click.option(
"--endpoints", help="Comma-separated list of IP or hostnames of the Juju controller"
@@ -208,6 +210,7 @@
@click.command(name="vca-delete", short_help="deletes a VCA")
+# @utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion from the DB (not recommended)"
@@ -224,6 +227,7 @@
@click.command(name="vca-list")
+# @utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -277,6 +281,7 @@
@click.command(name="vca-show", short_help="shows the details of a VCA")
+# @utils.require_hostname
@click.argument("name")
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.pass_context
diff --git a/osmclient/cli_commands/vim.py b/osmclient/cli_commands/vim.py
index c3377a9..0fa8569 100755
--- a/osmclient/cli_commands/vim.py
+++ b/osmclient/cli_commands/vim.py
@@ -41,6 +41,7 @@
@click.command(name="vim-create", short_help="creates a new VIM account")
+# @utils.require_hostname
@click.option("--name", required=True, help="Name to create datacenter")
@click.option("--user", default=None, help="VIM username")
@click.option("--password", default=None, help="VIM password")
@@ -163,6 +164,7 @@
@click.command(name="vim-update", short_help="updates a VIM account")
+# @utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the VIM account")
@click.option("--user", help="VIM username")
@@ -290,6 +292,7 @@
@click.command(name="vim-delete", short_help="deletes a VIM account")
+# @utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
@@ -317,6 +320,7 @@
@click.command(name="vim-list", short_help="list all VIM accounts")
+# @utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -375,6 +379,7 @@
@click.command(name="vim-show", short_help="shows the details of a VIM account")
+# @utils.require_hostname
@click.argument("name")
@click.option(
"--filter",
diff --git a/osmclient/cli_commands/vnf.py b/osmclient/cli_commands/vnf.py
index 9d8acfc..1f7c558 100755
--- a/osmclient/cli_commands/vnf.py
+++ b/osmclient/cli_commands/vnf.py
@@ -92,6 +92,7 @@
@click.command(name="vnf-list", short_help="list all NF instances")
+@utils.require_hostname
@click.option(
"--ns", default=None, help="NS instance id or name to restrict the NF list"
)
@@ -111,6 +112,7 @@
@click.command(name="nf-list", short_help="list all NF instances")
+@utils.require_hostname
@click.option(
"--ns", default=None, help="NS instance id or name to restrict the NF list"
)
@@ -176,6 +178,7 @@
@click.command(name="vnf-show", short_help="shows the info of a VNF instance")
+@utils.require_hostname
@click.argument("name")
@click.option("--literal", is_flag=True, help="print literally, no pretty table")
@click.option(
diff --git a/osmclient/cli_commands/wim.py b/osmclient/cli_commands/wim.py
index 2e24d84..b7f73ee 100755
--- a/osmclient/cli_commands/wim.py
+++ b/osmclient/cli_commands/wim.py
@@ -23,6 +23,7 @@
@click.command(name="wim-create", short_help="creates a new WIM account")
+@utils.require_hostname
@click.option("--name", prompt=True, help="Name for the WIM account")
@click.option("--user", help="WIM username")
@click.option("--password", help="WIM password")
@@ -76,6 +77,7 @@
@click.command(name="wim-update", short_help="updates a WIM account")
+@utils.require_hostname
@click.argument("name")
@click.option("--newname", help="New name for the WIM account")
@click.option("--user", help="WIM username")
@@ -136,6 +138,7 @@
@click.command(name="wim-delete", short_help="deletes a WIM account")
+@utils.require_hostname
@click.argument("name")
@click.option(
"--force", is_flag=True, help="forces the deletion bypassing pre-conditions"
@@ -159,6 +162,7 @@
@click.command(name="wim-list", short_help="list all WIM accounts")
+@utils.require_hostname
@click.option(
"--filter",
default=None,
@@ -181,6 +185,7 @@
@click.command(name="wim-show", short_help="shows the details of a WIM account")
+@utils.require_hostname
@click.argument("name")
@click.pass_context
def wim_show(ctx, name):
diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py
index d2ffeb4..b63d660 100755
--- a/osmclient/scripts/osm.py
+++ b/osmclient/scripts/osm.py
@@ -58,7 +58,6 @@
)
@click.option(
"--hostname",
- required=True,
envvar="OSM_HOSTNAME",
help="OSM NBI endpoint. " + "Also can set OSM_HOSTNAME in environment",
)
@@ -111,8 +110,7 @@
@click.pass_context
def cli_osm(ctx, **kwargs):
global logger
- # hostname is mandatory, so we pop it from kwargs
- hostname = kwargs.pop("hostname")
+ hostname = kwargs.pop("hostname", None)
kwargs = {k: v for k, v in kwargs.items() if v is not None}
ctx.obj = client.Client(version=1, host=hostname, **kwargs)
logger = logging.getLogger("osmclient")
diff --git a/osmclient/sol005/client.py b/osmclient/sol005/client.py
index 133f04f..bbe0536 100644
--- a/osmclient/sol005/client.py
+++ b/osmclient/sol005/client.py
@@ -73,6 +73,10 @@
self._headers = {}
self._token = None
self._url = None
+ if host is None:
+ # This is required to init a dummy Client for those click commands
+ # that do not require a host
+ host = "localhost"
if host.startswith("http://") or host.startswith("https://"):
self._url = host
else: