def _choose_instances(self): the_input = raw_input( "\t%s: choose from %s (space-delimited) or 'all' (blank line to cancel): " % (self.name, sorted(INSTANCES.keys()))).strip() # enable exit on blank line if the_input == '': return [''] return self._cleanse_input(the_input)
def run_for(self, the_input): names = self._cleanse_input(the_input) if len(names) == 0: self.run() if 'all' in names: names = INSTANCES.keys() self._run_for_all(self.sub_fn, names)
def _cleanse_input(self, the_input): names = the_input.strip().split(' ') # eliminate extra inner whitespace and filter out empty strings names = [name.strip() for name in names if name != ''] # eliminate duplicate names names = set(names) # check for unknown instances for name in names: if name not in INSTANCES.keys() and name != 'all': print("\tno known instance called %s" % name) return [] return names
def _choose_and_run(self, fn): while True: names = self._choose_instances() if '' in names: return to_return = False if 'all' in names: names = INSTANCES.keys() to_return = True self._run_for_all(fn, names) if to_return: return
def _start_node(instance): node0 = None if 'node-0' in INSTANCES.keys(): node0 = INSTANCES['node-0'] if instance.name != 'node-0' and node0 is not None and node0.node.descriptor != "": instance.start_node(node0.node.descriptor) elif instance.name == 'node-0' and node0 is not None and node0.node.descriptor == "": instance.start_node() else: print("FAILED TO START %s: did you forget about node-0?" % instance.name) print( "\t(if you are trying to start node-0, this means it may already be running)" )
def _start_cluster(count): try: iterations_left = int(count) except ValueError: print("FAILED TO START cluster: %s is not an integer" % count) return sorted_instances = sorted(INSTANCES.iteritems(), key=lambda (key, value): value.node_id) available_instances = filter(lambda (key, value): value.node.descriptor == '', sorted_instances) cluster_descriptor = _find_descriptor_by_max_key_of_running_instances(sorted_instances) for instance_name, instance in available_instances: if iterations_left == 0: break if cluster_descriptor == '': cluster_descriptor = instance.start_node() else: instance.start_node(cluster_descriptor) iterations_left -= 1
def _start_daisy_chain(count): try: iterations_left = int(count) except ValueError: print("FAILED TO START daisy chain: %s is not an integer" % count) return next_descriptor = '' for node_name, instance in sorted(INSTANCES.iteritems()): if iterations_left == 0: break if node_name == 'node-0': if instance.node.descriptor == '': next_descriptor = instance.start_node() print('started node-0 %s' % next_descriptor) else: next_descriptor = instance.node.descriptor else: next_descriptor = instance.start_node(next_descriptor) print('started %s %s' % (node_name, next_descriptor)) iterations_left -= 1
def _print_info(): for name in sorted(INSTANCES.keys()): instance = INSTANCES[name] # TODO this will wait forever (not blow up) if the instance is not running... check first! print("%s @ %s (%s)" % (name, instance.get_ip(), instance.instance_api.__class__))