Advertisement
Guest User

Untitled

a guest
Jul 14th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #!/usr/bin/env python
  2. """Command line client for Digium Gateways API"""
  3. from __future__ import print_function
  4.  
  5. import sys
  6. import argparse
  7. import json
  8. import re
  9. import string
  10. import urllib3
  11.  
  12. # do system shipped libraries, then added libraries, then self-written libraries
  13. import requests
  14.  
  15. def main(argv=None):
  16. """Main function of script.
  17.  
  18. processes command line args and carries out operations
  19. """
  20. if argv is None:
  21. argv = sys.argv
  22. args = get_options(argv[1:])
  23.  
  24. try:
  25. # TODO: check for -c and read in config file
  26. api = GatewayApi(machine=args.machine,
  27. gateway_ip=args.gateway_ip,
  28. admin_user=args.admin_user,
  29. admin_pass=args.admin_pass)
  30. except:
  31. #Bad args recovery here
  32. pass
  33.  
  34. if str(api.login()[0])[0] != '2':
  35. eprint('ERROR, failed to login: code:{}\n {}'.format(status[0], status[1]))
  36. exit(1)
  37.  
  38. try:
  39. api_args = {
  40. 'request': args.request,
  41. 'login': args.login,
  42. 'port': args.port,
  43. 'method': args.method,
  44. 'params': args.params
  45. }
  46. if args.subparser_name == 'info':
  47. status = api.info(**api_args)
  48. elif args.subparser_name == 'system':
  49. status = api.system(**api_args)
  50. elif args.subparser_name == 'raw_api':
  51. status = api.raw_api(**api_args)
  52. elif args.subparser_name == 'support':
  53. status = api.support(**api_args)
  54. else:
  55. status = "Invalid input: %s" % arg.subparser_name
  56. except:
  57. #Recover here
  58. pass
  59.  
  60. print_result(status)
  61. if str(status[0])[0] != '2':
  62. exit(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement