blob: cb8bedb1f74277ff489de32f3d5641de443cd2b8 [file] [log] [blame]
Shad Ansari6fcfa292022-01-28 00:34:13 +00001"""
2SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
3SPDX-License-Identifier: LicenseRef-ONF-Member-1.01
4"""
5import sys
6
Shad Ansari1dcfdb32022-01-24 23:13:06 +00007from flask import Flask, request
8from flask_restful import Resource, Api
Shad Ansari6fcfa292022-01-28 00:34:13 +00009import logging as log
Shad Ansari5b9d1f52022-01-29 01:42:45 +000010from argparse import ArgumentParser, SUPPRESS
11
12from roc import Roc
Shad Ansari1dcfdb32022-01-24 23:13:06 +000013
14app = Flask(__name__)
15api = Api(app)
16
Shad Ansari5b9d1f52022-01-29 01:42:45 +000017global roc
Shad Ansari6fcfa292022-01-28 00:34:13 +000018
Shad Ansari5b9d1f52022-01-29 01:42:45 +000019
20class Imsi(Resource):
Shad Ansari1dcfdb32022-01-24 23:13:06 +000021 def get(self):
Shad Ansari5b9d1f52022-01-29 01:42:45 +000022 return roc.get_imsi()
23
24class Subnet(Resource):
25 def get(self):
26 return roc.get_subnet()
Shad Ansari1dcfdb32022-01-24 23:13:06 +000027
Shad Ansari6fcfa292022-01-28 00:34:13 +000028
Shad Ansari5b9d1f52022-01-29 01:42:45 +000029api.add_resource(Imsi, '/imsi')
30api.add_resource(Subnet, '/subnet')
31
32
33def build_argparser():
34 parser = ArgumentParser(add_help=False)
35 args = parser.add_argument_group('Options')
36 args.add_argument('-h', '--help',
37 action='help',
38 default=SUPPRESS,
39 help='Show this help message and exit.')
40 args.add_argument("--user",
41 help="ROC username",
42 type=str)
43 args.add_argument("--password",
44 help="ROC password",
45 type=str)
46 return parser
47
Shad Ansari1dcfdb32022-01-24 23:13:06 +000048
49if __name__ == '__main__':
Shad Ansari6fcfa292022-01-28 00:34:13 +000050 log.basicConfig(
Shad Ansari5b9d1f52022-01-29 01:42:45 +000051 format='%(asctime)s %(levelname)-8s %(message)s',
52 level=log.DEBUG,
53 datefmt='%Y-%m-%d %H:%M:%S',
54 stream=sys.stdout)
Shad Ansari6fcfa292022-01-28 00:34:13 +000055
56 log.info("Starting network-diag-app...")
57
Shad Ansari5b9d1f52022-01-29 01:42:45 +000058 args = build_argparser().parse_args()
59
60 roc = Roc(args.user, args.password)
61 #roc.dump()
62 print(roc.get_imsi())
63
Shad Ansari6fcfa292022-01-28 00:34:13 +000064 app.run('0.0.0.0', '3333')