Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
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)"
        )
Exemplo n.º 6
0
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__))