)
@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",
@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")
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: