From 6ddeded5129e36c83d91374265ac31eb5a355a42 Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 16 May 2017 15:40:26 +0200 Subject: [PATCH] Add version primitive at http server and client Change-Id: I02a93f6f43700dbc95f8d42a27dd905eb5483f19 Signed-off-by: tierno --- openmano | 18 ++++++++++++++++-- openmanod | 2 ++ osm_ro/httpserver.py | 3 +++ osm_ro/nfvo.py | 4 ++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/openmano b/openmano index 1e90cad4..7b33cb46 100755 --- a/openmano +++ b/openmano @@ -1462,6 +1462,15 @@ def datacenter_edit(args): args.verbose += 1 return _print_verbose(mano_response, args.verbose) +def version(args): + headers_req = {'Accept': 'application/json', 'content-type': 'application/json'} + URLrequest = "http://%s:%s/openmano/version" % (mano_host, mano_port) + + mano_response = requests.get(URLrequest, headers=headers_req) + logger.debug("openmano response: %s", mano_response.text) + print mano_response.text + + global mano_host global mano_port global mano_tenant @@ -1474,8 +1483,10 @@ if __name__=="__main__": mano_datacenter = os.getenv('OPENMANO_DATACENTER',None) main_parser = ThrowingArgumentParser(description='User program to interact with OPENMANO-SERVER (openmanod)') - main_parser.add_argument('--version', action='version', version='%(prog)s ' + __version__ ) - + main_parser.add_argument('--version', action='version', help="get version of this client", + version='%(prog)s client version ' + __version__ + + " (Note: use '%(prog)s version' to get server version)") + subparsers = main_parser.add_subparsers(help='commands') parent_parser = argparse.ArgumentParser(add_help=False) @@ -1486,6 +1497,9 @@ if __name__=="__main__": config_parser.add_argument("-n", action="store_true", help="resolves tenant and datacenter names") config_parser.set_defaults(func=config) + version_parser = subparsers.add_parser('version', parents=[parent_parser], help="get server version") + version_parser.set_defaults(func=version) + vnf_create_parser = subparsers.add_parser('vnf-create', parents=[parent_parser], help="adds a vnf into the catalogue") vnf_create_parser.add_argument("file", action="store", help="location of the JSON file describing the VNF").completer = FilesCompleter vnf_create_parser.add_argument("--name", action="store", help="name of the VNF (if it exists in the VNF descriptor, it is overwritten)") diff --git a/openmanod b/openmanod index f1ce0a7d..0ad7a9e3 100755 --- a/openmanod +++ b/openmanod @@ -186,6 +186,8 @@ if __name__=="__main__": else: assert False, "Unhandled option" global_config = load_configuration(config_file) + global_config["version"] = __version__ + global_config["version_date"] = version_date #print global_config # Override parameters obtained by command line if port: diff --git a/osm_ro/httpserver.py b/osm_ro/httpserver.py index 4841a98b..d6dc0c7a 100644 --- a/osm_ro/httpserver.py +++ b/osm_ro/httpserver.py @@ -305,6 +305,9 @@ def enable_cors(): '''Don't know yet if really needed. Keep it just in case''' bottle.response.headers['Access-Control-Allow-Origin'] = '*' +@bottle.route(url_base + '/version', method='GET') +def http_get_version(): + return nfvo.get_version() # # VNFs # diff --git a/osm_ro/nfvo.py b/osm_ro/nfvo.py index 76469946..5a29eedf 100644 --- a/osm_ro/nfvo.py +++ b/osm_ro/nfvo.py @@ -194,6 +194,10 @@ def stop_service(): for thread in global_config["console_thread"]: thread.terminate = True +def get_version(): + return ("openmanod version {} {}\n(c) Copyright Telefonica".format(global_config["version"], + global_config["version_date"] )) + def get_flavorlist(mydb, vnf_id, nfvo_tenant=None): '''Obtain flavorList -- 2.25.1