Add decorator for all click commands requiring a hostname 47/15247/1
authorgarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 18 Jun 2025 13:06:13 +0000 (15:06 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Wed, 18 Jun 2025 14:01:25 +0000 (16:01 +0200)
Change-Id: I02d72d42d9fd1cd9dba8b4ed418b800e444742d7
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
33 files changed:
osmclient/cli_commands/alarms.py
osmclient/cli_commands/app_profile.py
osmclient/cli_commands/cluster.py
osmclient/cli_commands/infra_config_profile.py
osmclient/cli_commands/infra_controller_profile.py
osmclient/cli_commands/k8scluster.py
osmclient/cli_commands/ksu.py
osmclient/cli_commands/metrics.py
osmclient/cli_commands/netslice_instance.py
osmclient/cli_commands/netslice_ops.py
osmclient/cli_commands/netslice_template.py
osmclient/cli_commands/nfpkg.py
osmclient/cli_commands/ns.py
osmclient/cli_commands/nslcm.py
osmclient/cli_commands/nslcm_ops.py
osmclient/cli_commands/nspkg.py
osmclient/cli_commands/oka.py
osmclient/cli_commands/other.py
osmclient/cli_commands/packages.py
osmclient/cli_commands/pdus.py
osmclient/cli_commands/profiles.py
osmclient/cli_commands/rbac.py
osmclient/cli_commands/repo.py
osmclient/cli_commands/resource_profile.py
osmclient/cli_commands/sdnc.py
osmclient/cli_commands/subscriptions.py
osmclient/cli_commands/utils.py
osmclient/cli_commands/vca.py
osmclient/cli_commands/vim.py
osmclient/cli_commands/vnf.py
osmclient/cli_commands/wim.py
osmclient/scripts/osm.py
osmclient/sol005/client.py

index bc6d52e..5428e86 100755 (executable)
@@ -25,6 +25,7 @@ logger = logging.getLogger("osmclient")
 
 
 @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 @@ def ns_alarm_create(
 
 
 @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 @@ def alarm_show(ctx, uuid):
 
 # 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 @@ def alarm_list(ctx, ns_id):
 
 # 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")
index af5647f..75f364a 100755 (executable)
@@ -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 @@ logger = logging.getLogger("osmclient")
 
 
 @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 @@ def app_profile_create(ctx, name, description, **kwargs):
 
 
 @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 @@ def app_profile_delete(ctx, name, force):
 
 
 @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 @@ def app_profile_list(ctx, filter, output):
     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 @@ def app_profile_show(ctx, name, output):
 
 
 @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")
index 6f4b56f..2acbed2 100755 (executable)
@@ -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 @@ logger = logging.getLogger("osmclient")
 
 
 @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 @@ def cluster_create(
 
 
 @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 @@ def cluster_delete(ctx, name, force):
 
 
 @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 @@ def cluster_list(ctx, filter, output):
     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 @@ def cluster_show(ctx, name, output):
 @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 @@ def cluster_edit(ctx, name, newname, description, **kwargs):
 @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 @@ def cluster_upgrade(ctx, name, version, **kwargs):
 
 
 @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 @@ def cluster_scale(ctx, name, node_count, **kwargs):
 
 
 @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 @@ def cluster_update(ctx, name, version, node_count, node_size, **kwargs):
 @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 @@ def cluster_get_credentials(ctx, name, **kwargs):
 @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 @@ def cluster_get_kubeconfig(ctx, name, **kwargs):
 
 
 @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 @@ def cluster_register(
 
 
 @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)"
index e9f592d..7a86c93 100755 (executable)
@@ -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 @@ logger = logging.getLogger("osmclient")
 @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 @@ def infra_config_profile_create(ctx, name, description, **kwargs):
 @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 @@ def infra_config_profile_delete(ctx, name, force):
 
 
 @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 @@ def infra_config_profile_list(ctx, filter, output):
     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 @@ def infra_config_profile_show(ctx, name, output):
 @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")
index c764bae..213c158 100755 (executable)
@@ -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 @@ logger = logging.getLogger("osmclient")
     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 @@ def infra_controller_profile_create(ctx, name, description, **kwargs):
     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 @@ def infra_controller_profile_delete(ctx, name, force):
 
 
 @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 @@ def infra_controller_profile_list(ctx, filter, output):
     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 @@ def infra_controller_profile_show(ctx, name, output):
     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")
index 380d311..a61978f 100755 (executable)
@@ -24,6 +24,7 @@ logger = logging.getLogger("osmclient")
 
 
 @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 @@ def k8scluster_add(
 
 
 @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 @@ def k8scluster_update(
 
 
 @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 @@ def k8scluster_delete(ctx, name, force, wait):
 
 
 @click.command(name="k8scluster-list")
+@utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -281,6 +285,7 @@ def k8scluster_list(ctx, filter, literal, long):
 
 
 @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
index 8fddacb..63ff78c 100755 (executable)
@@ -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 @@ def process_ksu_params(ctx, param, value):
         ignore_unknown_options=True,
     ),
 )
+@utils.require_hostname
 @click.argument(
     "args",
     nargs=-1,
@@ -264,6 +265,7 @@ def ksu_create(ctx, args, ksu_params):
 
 
 @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 @@ def ksu_delete(ctx, ksus, force):
 
 
 @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 @@ def ksu_list(ctx, filter, output):
 
 
 @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 @@ def ksu_show(ctx, name, output):
         ignore_unknown_options=True,
     ),
 )
+@utils.require_hostname
 @click.argument(
     "args",
     nargs=-1,
index fc62595..327a598 100755 (executable)
@@ -25,6 +25,7 @@ logger = logging.getLogger("osmclient")
     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)"
index 3799f47..1b7015d 100755 (executable)
@@ -58,6 +58,7 @@ def nsi_list(ctx, filter):
 
 
 @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 @@ def nsi_list1(ctx, filter):
 @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 @@ def nsi_show(ctx, name, literal, filter):
 @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 @@ def nsi_show1(ctx, name, literal, filter):
     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 @@ def nsi_create(
 
 
 @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 @@ def nsi_create1(
 @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 @@ def nsi_delete(ctx, name, force, wait):
 
 
 @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 @@ def nsi_delete1(ctx, name, force, wait):
 @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"
index d891f45..0345c79 100755 (executable)
@@ -37,6 +37,7 @@ def nsi_op_list(ctx, name):
     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 @@ def nsi_op_list1(ctx, name):
     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 @@ def nsi_op_show(ctx, id, filter):
     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 @@ def nsi_op_show1(ctx, id, filter):
     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",
index 8ae780c..d04a4e0 100755 (executable)
@@ -38,6 +38,7 @@ def nst_list(ctx, filter):
 
 
 @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 @@ def nst_list1(ctx, filter):
 @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 @@ def nst_show(ctx, name, literal):
 @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 @@ def nst_show1(ctx, name, literal):
     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 @@ def nst_create(ctx, filename, overwrite):
 @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 @@ def nst_create1(ctx, filename, overwrite):
     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 @@ def nst_update(ctx, name, content):
 
 
 @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 @@ def nst_update1(ctx, name, content):
 @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 @@ def nst_delete(ctx, name, force):
 
 
 @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 @@ def nst_delete1(ctx, name, force):
 @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"
index 8d3f01b..c8691bb 100755 (executable)
@@ -106,6 +106,7 @@ def vnfd_list(ctx, nf_type, filter, long):
 
 
 @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 @@ def vnfd_list1(ctx, nf_type, filter, long):
 
 
 @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 @@ def vnfd_list2(ctx, nf_type, filter, long):
 
 
 @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 @@ def vnfd_show(ctx, name, literal):
 
 
 @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 @@ def vnfd_show1(ctx, name, literal):
 
 
 @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 @@ def vnfd_show2(ctx, name, literal):
 
 
 @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 @@ def vnfd_create(
 
 
 @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 @@ def vnfd_create1(
 
 
 @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 @@ def vnfd_create2(
 
 
 @click.command(name="nfpkg-create", short_help="creates a new NFpkg")
+@utils.require_hostname
 @click.argument("filename")
 @click.option(
     "--overwrite",
@@ -489,6 +498,7 @@ def vnfd_update(ctx, name, content):
 
 
 @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 @@ def vnfd_update1(ctx, name, content):
 
 
 @click.command(name="vnfpkg-update", short_help="updates a VNFD/VNFpkg")
+@utils.require_hostname
 @click.argument("name")
 @click.option(
     "--content",
@@ -523,6 +534,7 @@ def vnfd_update2(ctx, name, content):
 
 
 @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 @@ def vnfd_delete(ctx, name, force):
 
 
 @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 @@ def vnfd_delete1(ctx, name, force):
 
 
 @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 @@ def vnfd_delete2(ctx, name, force):
 
 
 @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"
index 972bfa3..d7687b9 100755 (executable)
@@ -27,6 +27,7 @@ logger = logging.getLogger("osmclient")
 
 
 @click.command(name="ns-list", short_help="list all NS instances")
+@utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -280,6 +281,7 @@ def ns_list(ctx, filter, long, output):
 
 
 @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 @@ def ns_show(ctx, name, literal, filter, output):
 
 
 @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 @@ def process_ns_multi_delete_params(ctx, param, value):
 
 
 @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
 )
index d206db2..9e58844 100755 (executable)
@@ -26,6 +26,7 @@ logger = logging.getLogger("osmclient")
 @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 @@ def ns_action(
 @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 @@ def process_ns_heal_params(ctx, param, value):
         ignore_unknown_options=True,
     ),
 )
+@utils.require_hostname
 @click.argument("ns_name")
 @click.argument(
     "args",
@@ -362,6 +365,7 @@ def process_vnf_heal_params(ctx, param, value):
         ignore_unknown_options=True,
     ),
 )
+@utils.require_hostname
 @click.argument("vnf_name")
 @click.argument(
     "args",
index 9528d08..f9b3c0f 100755 (executable)
@@ -27,6 +27,7 @@ logger = logging.getLogger("osmclient")
 @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 @@ def ns_op_list(ctx, name, long):
 
 
 @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 @@ def ns_op_show(ctx, id, filter, literal):
 
 
 @click.command(name="ns-op-cancel", short_help="cancels an ongoing NS operation")
+@utils.require_hostname
 @click.argument("id")
 @click.option(
     "--cancel_mode",
index 5195d81..ab920cf 100755 (executable)
@@ -78,6 +78,7 @@ def nsd_list(ctx, filter, long):
 
 
 @click.command(name="nsd-list", short_help="list all NS packages")
+@utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -93,6 +94,7 @@ def nsd_list1(ctx, filter, long):
 
 
 @click.command(name="nspkg-list", short_help="list all NS packages")
+@utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -124,6 +126,7 @@ def nsd_show(ctx, name, literal):
 
 
 @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 @@ def nsd_show1(ctx, name, literal):
 
 
 @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 @@ def nsd_create(ctx, filename, overwrite, skip_charm_build, repo, vendor, version
 
 
 @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 @@ def nsd_create1(ctx, filename, overwrite, skip_charm_build, repo, vendor, versio
 
 
 @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 @@ def nsd_update(ctx, name, content):
 
 
 @click.command(name="nsd-update", short_help="updates a NSD/NSpkg")
+@utils.require_hostname
 @click.argument("name")
 @click.option(
     "--content",
@@ -278,6 +285,7 @@ def nsd_update1(ctx, name, content):
 
 
 @click.command(name="nspkg-update", short_help="updates a NSD/NSpkg")
+@utils.require_hostname
 @click.argument("name")
 @click.option(
     "--content",
@@ -304,6 +312,7 @@ def nsd_delete(ctx, name, force):
 
 
 @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 @@ def nsd_delete1(ctx, name, force):
 
 
 @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 @@ def nsd_delete2(ctx, name, force):
 
 
 @click.command(name="nsconfig-list", short_help="list all NS Config Templates")
+@utils.require_hostname
 @click.option(
     "--nsd",
     default=None,
@@ -407,6 +418,7 @@ def nsconfig_list(ctx, nsd, long):
 @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 @@ def nsconfig_show(ctx, name, literal):
 
 
 @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 @@ def nsconfig_delete(ctx, name, force):
 
 
 @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 @@ def nsconfig_create(ctx, name, config_file, nsd):
 @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(
index a6457d9..55b1d3c 100755 (executable)
@@ -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 @@ def oka_generate(
 
 
 @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 @@ def oka_add(ctx, name, path, profile_type, description):
 @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 @@ def oka_delete(ctx, name, force):
 
 
 @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 @@ def oka_list(ctx, filter, output):
     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 @@ def oka_show(ctx, name, output):
 @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 @@ def oka_update(ctx, name, newname, description, **kwargs):
     name="oka-update-content",
     short_help="updates the content of an OKA",
 )
+@utils.require_hostname
 @click.argument("name")
 @click.argument("path")
 @click.pass_context
index d2ce70f..28b46be 100755 (executable)
@@ -22,6 +22,7 @@ logger = logging.getLogger("osmclient")
 
 
 @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"""
index 3853a30..7426981 100755 (executable)
@@ -282,6 +282,7 @@ def descriptor_translate(ctx, descriptor_file):
 
 # 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",
index b1fc768..0d6d23c 100755 (executable)
@@ -25,6 +25,7 @@ logger = logging.getLogger("osmclient")
 
 
 @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 @@ def pdu_list(ctx, filter):
 @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 @@ def pdu_show(ctx, name, literal, filter):
 @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 @@ def pdu_create(
 @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 @@ def create_pdu_dictionary(
 
 
 @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"
index cfc7faf..821fca3 100755 (executable)
 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 @@ def patch_cluster_profile(ctx, profile, cluster, profile_type, patch_string):
 
 
 @click.command(name="attach-profile")
+@utils.require_hostname
 @click.argument("profile")
 @click.argument("cluster")
 @click.option(
@@ -114,6 +117,7 @@ def attach_profile(ctx, profile, cluster, profile_type):
 
 
 @click.command(name="detach-profile")
+@utils.require_hostname
 @click.argument("profile")
 @click.argument("cluster")
 @click.option(
index c51e229..2bab34a 100755 (executable)
@@ -30,6 +30,7 @@ logger = logging.getLogger("osmclient")
 
 
 @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 @@ def role_create(ctx, name, permissions):
 
 
 @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 @@ def role_update(ctx, name, set_name, add, remove):
 
 
 @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 @@ def role_delete(ctx, name):
 
 
 @click.command(name="role-list", short_help="list all roles")
+@utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -111,6 +115,7 @@ def role_list(ctx, filter):
 
 
 @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 @@ def role_show(ctx, name):
 
 
 @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 @@ def _process_project_quotas(quota_list):
 
 
 @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 @@ def project_delete(ctx, name):
 
 
 @click.command(name="project-list", short_help="list all projects")
+@utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -222,6 +230,7 @@ def project_list(ctx, filter):
 
 
 @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 @@ def project_show(ctx, name):
 @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 @@ def project_update(ctx, project, name, quotas):
 
 
 @click.command(name="user-create", short_help="creates a new user")
+@utils.require_hostname
 @click.argument("username")
 @click.option(
     "--password",
@@ -338,6 +349,7 @@ def user_create(
 
 
 @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 @@ def user_update(
 
 
 @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 @@ def user_delete(ctx, name):
 
 
 @click.command(name="user-list", short_help="list all users")
+@utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -499,6 +513,7 @@ def user_list(ctx, filter):
 
 
 @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 @@ def user_show(ctx, name):
 
 
 @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):
index b2ecd9a..3a80735 100755 (executable)
@@ -25,6 +25,7 @@ logger = logging.getLogger("osmclient")
 
 
 @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 @@ def repo_add(ctx, **kwargs):
 
 
 @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 @@ def repo_delete(ctx, name, force):
 
 
 @click.command(name="repo-list")
+@utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -191,6 +194,7 @@ def repo_list(ctx, filter, literal):
 
 
 @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
index d084afe..e1ff670 100755 (executable)
@@ -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 @@ logger = logging.getLogger("osmclient")
 @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 @@ def resource_profile_create(ctx, name, description, **kwargs):
 
 
 @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 @@ def resource_profile_delete(ctx, name, force):
 
 
 @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 @@ def resource_profile_list(ctx, filter, output):
     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 @@ def resource_profile_show(ctx, name, output):
 
 
 @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")
index 2bcd770..1ad18fc 100755 (executable)
@@ -23,6 +23,7 @@ logger = logging.getLogger("osmclient")
 
 
 @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 @@ def sdnc_create(ctx, **kwargs):
 
 
 @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 @@ def sdnc_update(ctx, **kwargs):
 
 
 @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 @@ def sdnc_delete(ctx, name, force, wait):
 
 
 @click.command(name="sdnc-list", short_help="list all SDN controllers")
+@utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -195,6 +199,7 @@ def sdnc_list(ctx, filter):
 
 
 @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):
index 3dc3c38..31506ad 100755 (executable)
@@ -27,6 +27,7 @@ logger = logging.getLogger("osmclient")
     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 @@ def subscription_create(ctx, event_type, event, event_file):
 
 
 @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 @@ def subscription_delete(ctx, event_type, subscription_id, force):
 
 
 @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 @@ def subscription_list(ctx, event_type, filter):
 @click.command(
     name="subscription-show", short_help="shows the details of a subscription"
 )
+@utils.require_hostname
 @click.argument("subscription_id")
 @click.option(
     "--event_type",
index e34926a..4ef7ad4 100755 (executable)
 #    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 @@ def create_config(config_file, json_string):
         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
index fc33962..7cec847 100755 (executable)
@@ -27,6 +27,7 @@ logger = logging.getLogger("osmclient")
 
 
 @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 @@ def load_file(file_path: str) -> Dict:
 
 
 @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 @@ def vca_update(
 
 
 @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 @@ def vca_delete(ctx, name, force):
 
 
 @click.command(name="vca-list")
+# @utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -277,6 +281,7 @@ def vca_list(ctx, filter, literal, long):
 
 
 @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
index c3377a9..0fa8569 100755 (executable)
@@ -41,6 +41,7 @@ def _check_ca_cert(vim_config: dict) -> None:
 
 
 @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 @@ def vim_create(
 
 
 @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 @@ def vim_update(
 
 
 @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 @@ def vim_delete(ctx, name, force, wait):
 
 
 @click.command(name="vim-list", short_help="list all VIM accounts")
+# @utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -375,6 +379,7 @@ def vim_list(ctx, filter, long, output):
 
 
 @click.command(name="vim-show", short_help="shows the details of a VIM account")
+# @utils.require_hostname
 @click.argument("name")
 @click.option(
     "--filter",
index 9d8acfc..1f7c558 100755 (executable)
@@ -92,6 +92,7 @@ def vnf_list(ctx, ns, filter, long, output):
 
 
 @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 @@ def vnf_list1(ctx, ns, filter, long, output):
 
 
 @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 @@ def nf_list(ctx, ns, filter, long, output):
 
 
 @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(
index 2e24d84..b7f73ee 100755 (executable)
@@ -23,6 +23,7 @@ logger = logging.getLogger("osmclient")
 
 
 @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 @@ def wim_create(
 
 
 @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 @@ def wim_update(
 
 
 @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 @@ def wim_delete(ctx, name, force, wait):
 
 
 @click.command(name="wim-list", short_help="list all WIM accounts")
+@utils.require_hostname
 @click.option(
     "--filter",
     default=None,
@@ -181,6 +185,7 @@ def wim_list(ctx, filter):
 
 
 @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):
index d2ffeb4..b63d660 100755 (executable)
@@ -58,7 +58,6 @@ from requests import RequestException
 )
 @click.option(
     "--hostname",
-    required=True,
     envvar="OSM_HOSTNAME",
     help="OSM NBI endpoint.  " + "Also can set OSM_HOSTNAME in environment",
 )
@@ -111,8 +110,7 @@ from requests import RequestException
 @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")
index 133f04f..bbe0536 100644 (file)
@@ -73,6 +73,10 @@ class Client(object):
         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: