Make OSM_HOSTNAME/--hostname mandatory and update message in case of NotFound exception due to nginx
Change-Id: I1e1705843b45bfc3e154193ff530aca78a83b0ad
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
diff --git a/osmclient/scripts/osm.py b/osmclient/scripts/osm.py
index 2976e19..d2ffeb4 100755
--- a/osmclient/scripts/osm.py
+++ b/osmclient/scripts/osm.py
@@ -58,9 +58,9 @@
)
@click.option(
"--hostname",
- default="127.0.0.1",
+ required=True,
envvar="OSM_HOSTNAME",
- help="hostname of server. " + "Also can set OSM_HOSTNAME in environment",
+ help="OSM NBI endpoint. " + "Also can set OSM_HOSTNAME in environment",
)
@click.option(
"--user",
@@ -111,16 +111,8 @@
@click.pass_context
def cli_osm(ctx, **kwargs):
global logger
- hostname = kwargs.pop("hostname", None)
- if hostname is None:
- print(
- (
- "either hostname option or OSM_HOSTNAME "
- + "environment variable needs to be specified"
- )
- )
- exit(1)
- # Remove None values
+ # hostname is mandatory, so we pop it from kwargs
+ hostname = kwargs.pop("hostname")
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")
@@ -363,15 +355,16 @@
cli_osm()
exit(0)
except RequestException as exc:
- print(exc)
+ print("RequestException: {}".format(exc))
print(
- 'Maybe "--hostname" option or OSM_HOSTNAME environment variable needs to be specified'
+ 'Check OSM NBI endpoint, and set OSM_HOSTNAME env variable or "--hostname" option'
)
except NotFound as exc:
print("NOT FOUND: {}".format(exc))
- print(
- 'Maybe "--hostname" option or OSM_HOSTNAME environment variable needs to be specified'
- )
+ if "Error 404: <html>" in str(exc):
+ print(
+ "Check OSM NBI endpoint, and set OSM_HOSTNAME env variable or '--hostname' option"
+ )
except ClientException as exc:
print("ERROR: {}".format(exc))
except (FileNotFoundError, PermissionError) as exc: