Add version primitive at http server and client 33/1833/3
authortierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 16 May 2017 13:40:26 +0000 (15:40 +0200)
committertierno <alfonso.tiernosepulveda@telefonica.com>
Tue, 16 May 2017 14:18:00 +0000 (16:18 +0200)
Change-Id: I02a93f6f43700dbc95f8d42a27dd905eb5483f19
Signed-off-by: tierno <alfonso.tiernosepulveda@telefonica.com>
openmano
openmanod
osm_ro/httpserver.py
osm_ro/nfvo.py

index 1e90cad..7b33cb4 100755 (executable)
--- 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)")
index f1ce0a7..0ad7a9e 100755 (executable)
--- 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:
index 4841a98..d6dc0c7 100644 (file)
@@ -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
 #
index 7646994..5a29eed 100644 (file)
@@ -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