import pprint import utils from himlarcli.nova import Nova print "Depricated! Use aggregate.py" sys.exit(1) desc = 'Perform action on all instances on host' actions = ['list', 'start', 'start_from_state', 'stop', 'delete', 'save'] options = utils.get_host_action_options(desc, actions) novaclient = Nova(options.config, options.host, options.debug) if options.action[0] == 'list': pp = pprint.PrettyPrinter(indent=2) pp.pprint(novaclient.list_instances()) elif options.action[0] == 'start': novaclient.start_instances() elif options.action[0] == 'start_from_state': novaclient.start_instances_from_state() elif options.action[0] == 'stop': novaclient.stop_instances() elif options.action[0] == 'save': novaclient.save_states() elif options.action[0] == 'delete': q = "Delete all stopped instances on %s (yes|no)? " % options.host answer = raw_input(q) if answer.lower() == 'yes': print "We are now deleting all instances" novaclient.delete_instances() else:
print "Depricated! Use aggregate.py" sys.exit(1) options = utils.get_options('Notify users of rebuild host', dry_run=True, hosts=1) notify = Notify(options.config, debug=options.debug) with open('misc/notify_email.txt', 'r') as body_txt: body_content = body_txt.read() # Find users novaclient = Nova(options.config, options.host[0], debug=options.debug) region = novaclient.get_config('openstack', 'region') if not novaclient.valid_host(): print "ERROR: could not find host %s" % options.host[0] sys.exit(1) toaddr = novaclient.list_instances() for user, instance in toaddr.iteritems(): user_instances = "" for server, info in instance.iteritems(): user_instances += "%s (%s)\n" % (server, info['ip']) msg = MIMEText(user_instances + body_content) msg['Subject'] = 'UH-IaaS: Terminating instance (%s)' % region if not options.dry_run: notify.send_mail(user, msg) print '\nUser: %s' % user print 'Servers:\n' + user_instances + '\n' notify.close()