Shad Ansari | 6fcfa29 | 2022-01-28 00:34:13 +0000 | [diff] [blame] | 1 | """ |
| 2 | SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org> |
| 3 | SPDX-License-Identifier: LicenseRef-ONF-Member-1.01 |
| 4 | """ |
| 5 | import sys |
| 6 | |
Shad Ansari | 1dcfdb3 | 2022-01-24 23:13:06 +0000 | [diff] [blame] | 7 | from flask import Flask, request |
| 8 | from flask_restful import Resource, Api |
Shad Ansari | 6fcfa29 | 2022-01-28 00:34:13 +0000 | [diff] [blame] | 9 | import logging as log |
Shad Ansari | 5b9d1f5 | 2022-01-29 01:42:45 +0000 | [diff] [blame] | 10 | from argparse import ArgumentParser, SUPPRESS |
| 11 | |
| 12 | from roc import Roc |
Shad Ansari | 1dcfdb3 | 2022-01-24 23:13:06 +0000 | [diff] [blame] | 13 | |
| 14 | app = Flask(__name__) |
| 15 | api = Api(app) |
| 16 | |
Shad Ansari | 5b9d1f5 | 2022-01-29 01:42:45 +0000 | [diff] [blame] | 17 | global roc |
Shad Ansari | 6fcfa29 | 2022-01-28 00:34:13 +0000 | [diff] [blame] | 18 | |
Shad Ansari | 5b9d1f5 | 2022-01-29 01:42:45 +0000 | [diff] [blame] | 19 | |
| 20 | class Imsi(Resource): |
Shad Ansari | 1dcfdb3 | 2022-01-24 23:13:06 +0000 | [diff] [blame] | 21 | def get(self): |
Shad Ansari | 5b9d1f5 | 2022-01-29 01:42:45 +0000 | [diff] [blame] | 22 | return roc.get_imsi() |
| 23 | |
| 24 | class Subnet(Resource): |
| 25 | def get(self): |
| 26 | return roc.get_subnet() |
Shad Ansari | 1dcfdb3 | 2022-01-24 23:13:06 +0000 | [diff] [blame] | 27 | |
Shad Ansari | 6fcfa29 | 2022-01-28 00:34:13 +0000 | [diff] [blame] | 28 | |
Shad Ansari | 5b9d1f5 | 2022-01-29 01:42:45 +0000 | [diff] [blame] | 29 | api.add_resource(Imsi, '/imsi') |
| 30 | api.add_resource(Subnet, '/subnet') |
| 31 | |
| 32 | |
| 33 | def 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 Ansari | 1dcfdb3 | 2022-01-24 23:13:06 +0000 | [diff] [blame] | 48 | |
| 49 | if __name__ == '__main__': |
Shad Ansari | 6fcfa29 | 2022-01-28 00:34:13 +0000 | [diff] [blame] | 50 | log.basicConfig( |
Shad Ansari | 5b9d1f5 | 2022-01-29 01:42:45 +0000 | [diff] [blame] | 51 | format='%(asctime)s %(levelname)-8s %(message)s', |
| 52 | level=log.DEBUG, |
| 53 | datefmt='%Y-%m-%d %H:%M:%S', |
| 54 | stream=sys.stdout) |
Shad Ansari | 6fcfa29 | 2022-01-28 00:34:13 +0000 | [diff] [blame] | 55 | |
| 56 | log.info("Starting network-diag-app...") |
| 57 | |
Shad Ansari | 5b9d1f5 | 2022-01-29 01:42:45 +0000 | [diff] [blame] | 58 | args = build_argparser().parse_args() |
| 59 | |
| 60 | roc = Roc(args.user, args.password) |
| 61 | #roc.dump() |
| 62 | print(roc.get_imsi()) |
| 63 | |
Shad Ansari | 6fcfa29 | 2022-01-28 00:34:13 +0000 | [diff] [blame] | 64 | app.run('0.0.0.0', '3333') |