shutdown.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/python
  2. # -*- encoding: utf-8 -*-
  3. import ConfigParser
  4. import xmlrpclib
  5. import optparse
  6. import os.path
  7. if __name__ == '__main__':
  8. parser = optparse.OptionParser()
  9. parser.add_option('-c', '--config', dest = 'config', help = 'config file', metavar = 'CONFIG')
  10. parser.add_option('-s', '--server', dest = 'server', help = 'URI for the grid server', metavar = 'SERVER')
  11. parser.add_option('-p', '--password', dest = 'password', help = 'password for the grid server', metavar = 'PASSWD')
  12. (options, args) = parser.parse_args()
  13. configFile = options.config
  14. if not configFile:
  15. if os.path.isfile(os.path.expanduser('~/.opensim-console.rc')):
  16. configFile = os.path.expanduser('~/.opensim-console.rc')
  17. if not configFile:
  18. parser.error('missing option config')
  19. sys.exit(1)
  20. config = ConfigParser.ConfigParser()
  21. config.readfp(open(configFile))
  22. server = config.get('opensim', 'server')
  23. password = config.get('opensim', 'password')
  24. if options.server: server = options.server
  25. if options.password: password = options.password
  26. gridServer = xmlrpclib.Server(server)
  27. res = gridServer.admin_shutdown({'password': password})
  28. if res['success'] == 'true':
  29. print 'shutdown of %s initiated' % server
  30. else:
  31. print 'shutdown of %s failed' % server