def add_instances(args): launcher = Launcher(**launcher_args(args)) manager = [ i for i in running_or_pending_instances(launcher.get_reservations()) if 'manager' in i.tags.get('Name', '') ] if len(manager) > 1: print "There is more than one Manager instance. Can't add workers.", \ "Managers:" for m in manager: print_instance(m) return 1 elif len(manager) == 0: print "No manager instances are running. Can't add workers." return 1 if args.num_instances < 1: print "--num-instances must be greater or equal to 1." return 1 manager = manager[0] launcher.vpc_id = manager.vpc_id launcher.subnet_id = manager.subnet_id launcher.instance_type = manager.instance_type launcher.security_group_id = manager.groups[0].id print "Launching worker instance(s):" status_printer = StatusPrinter() workers = launcher.launch_workers(args.num_instances, manager.key_name, manager.id, args.spot_price, callback=status_printer.on_status) status_printer.done() print "Workers started:" for worker in workers: print_instance(worker, 'worker') print "" print "Waiting for services:" if launcher.wait_for_services(workers, callback=status_printer.on_status): status_printer.done() else: status_printer.failed()
def add_instances(args): launcher = Launcher(**launcher_args(args)) manager = [i for i in running_or_pending_instances(launcher.get_reservations()) if 'manager' in i.tags.get('Name', '')] if len(manager) > 1: print "There is more than one Manager instance. Can't add workers.", \ "Managers:" for m in manager: print_instance(m) return 1 elif len(manager) == 0: print "No manager instances are running. Can't add workers." return 1 if args.num_instances < 1: print "--num-instances must be greater or equal to 1." return 1 manager = manager[0] launcher.vpc_id = manager.vpc_id launcher.subnet_id = manager.subnet_id launcher.instance_type = manager.instance_type launcher.security_group_id = manager.groups[0].id print "Launching worker instance(s):" status_printer = StatusPrinter() workers = launcher.launch_workers(args.num_instances, manager.key_name, manager.id, args.spot_price, callback=status_printer.on_status) status_printer.done() print "Workers started:" for worker in workers: print_instance(worker, 'worker') print "" print "Waiting for services:" if launcher.wait_for_services(workers, callback=status_printer.on_status): status_printer.done() else: status_printer.failed()