def get_node(index, name=DEFAULT_SUBSCRIBE): all_servers = utils.read_from_json(SERVER_CONFIG) try: servers = all_servers[name] except KeyError: click.echo("No subscribe named %s found!" % name) sys.exit(1) node = servers[index] click.echo("switch to node:") utils.ping(name=name, index=index, all_servers=all_servers) return node
def get_node(index, name=DEFAULT_SUBSCRIBE): all_servers = utils.read_from_json(SERVER_CONFIG) try: servers = all_servers[name] except KeyError: click.echo("No subscribe named %s found!" % name) sys.exit(1) try: utils.check_index(index) node = servers[index - 1] click.echo("switch to node:") utils.ping(name=name, index=index, all_servers=all_servers) except IndexError: click.echo("Invalid index: %s, please check it." % index) sys.exit(1) return node
def ping(name, index): """test node delay by ping.""" utils.ping(name=name, index=index)