1
0

wheeltest.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # -*- coding: utf-8 -*-
  2. #!/usr/bin/env python
  3. '''
  4. Test interacting with the wheel system. This script is useful when testing
  5. wheel modules
  6. '''
  7. # Import Python libs
  8. from __future__ import absolute_import
  9. import optparse
  10. import pprint
  11. # Import Salt Libs
  12. import salt.config
  13. import salt.wheel
  14. import salt.auth
  15. def parse():
  16. '''
  17. Parse the command line options
  18. '''
  19. parser = optparse.OptionParser()
  20. parser.add_option('-f',
  21. '--fun',
  22. '--function',
  23. dest='fun',
  24. help='The wheel function to execute')
  25. parser.add_option('-a',
  26. '--auth',
  27. dest='eauth',
  28. help='The external authentication mechanism to use')
  29. options, args = parser.parse_args()
  30. cli = options.__dict__
  31. for arg in args:
  32. if '=' in arg:
  33. comps = arg.split('=')
  34. cli[comps[0]] = comps[1]
  35. return cli
  36. class Wheeler(object):
  37. '''
  38. Set up communication with the wheel interface
  39. '''
  40. def __init__(self, cli):
  41. self.opts = salt.config.master_config('/etc/salt')
  42. self.opts.update(cli)
  43. self.__eauth()
  44. self.wheel = salt.wheel.Wheel(self.opts)
  45. def __eauth(self):
  46. '''
  47. Fill in the blanks for the eauth system
  48. '''
  49. if self.opts['eauth']:
  50. resolver = salt.auth.Resolver(self.opts)
  51. res = resolver.cli(self.opts['eauth'])
  52. self.opts.update(res)
  53. def run(self):
  54. '''
  55. Execute the wheel call
  56. '''
  57. return self.wheel.master_call(**self.opts)
  58. if __name__ == '__main__':
  59. wheeler = Wheeler(parse())
  60. pprint.pprint(wheeler.run())