| """ |
| SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org> |
| SPDX-License-Identifier: LicenseRef-ONF-Member-1.01 |
| """ |
| import sys |
| |
| from flask import Flask, request |
| from flask_restful import Resource, Api |
| import logging as log |
| from argparse import ArgumentParser, SUPPRESS |
| |
| from roc import Roc |
| |
| app = Flask(__name__) |
| api = Api(app) |
| |
| global roc |
| |
| |
| class Imsi(Resource): |
| def get(self): |
| return roc.get_imsi() |
| |
| class Subnet(Resource): |
| def get(self): |
| return roc.get_subnet() |
| |
| |
| api.add_resource(Imsi, '/imsi') |
| api.add_resource(Subnet, '/subnet') |
| |
| |
| def build_argparser(): |
| parser = ArgumentParser(add_help=False) |
| args = parser.add_argument_group('Options') |
| args.add_argument('-h', '--help', |
| action='help', |
| default=SUPPRESS, |
| help='Show this help message and exit.') |
| args.add_argument("--user", |
| help="ROC username", |
| type=str) |
| args.add_argument("--password", |
| help="ROC password", |
| type=str) |
| return parser |
| |
| |
| if __name__ == '__main__': |
| log.basicConfig( |
| format='%(asctime)s %(levelname)-8s %(message)s', |
| level=log.DEBUG, |
| datefmt='%Y-%m-%d %H:%M:%S', |
| stream=sys.stdout) |
| |
| log.info("Starting network-diag-app...") |
| |
| args = build_argparser().parse_args() |
| |
| roc = Roc(args.user, args.password) |
| #roc.dump() |
| print(roc.get_imsi()) |
| |
| app.run('0.0.0.0', '3333') |