Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """Command line client for Digium Gateways API"""
- from __future__ import print_function
- import sys
- import argparse
- import json
- import re
- import string
- import urllib3
- # do system shipped libraries, then added libraries, then self-written libraries
- import requests
- def main(argv=None):
- """Main function of script.
- processes command line args and carries out operations
- """
- if argv is None:
- argv = sys.argv
- args = get_options(argv[1:])
- try:
- # TODO: check for -c and read in config file
- api = GatewayApi(machine=args.machine,
- gateway_ip=args.gateway_ip,
- admin_user=args.admin_user,
- admin_pass=args.admin_pass)
- except:
- #Bad args recovery here
- pass
- if str(api.login()[0])[0] != '2':
- eprint('ERROR, failed to login: code:{}\n {}'.format(status[0], status[1]))
- exit(1)
- try:
- api_args = {
- 'request': args.request,
- 'login': args.login,
- 'port': args.port,
- 'method': args.method,
- 'params': args.params
- }
- if args.subparser_name == 'info':
- status = api.info(**api_args)
- elif args.subparser_name == 'system':
- status = api.system(**api_args)
- elif args.subparser_name == 'raw_api':
- status = api.raw_api(**api_args)
- elif args.subparser_name == 'support':
- status = api.support(**api_args)
- else:
- status = "Invalid input: %s" % arg.subparser_name
- except:
- #Recover here
- pass
- print_result(status)
- if str(status[0])[0] != '2':
- exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement