Esempio n. 1
0
def ping(idx):
    config = npw.config.default()
    client = boto3.client('s3')
    rc = config["control_plane"]
    password = rc["password"]
    port = rc["port"]
    prefix = rc["control_plane_prefix"].strip("/")
    bucket = config["s3"]["bucket"]
    keys = list_all_keys(prefix=prefix, bucket=bucket)
    if (idx >= len(keys)):
        click.echo("idx must be less that number of total control planes")
        return
    key = keys[idx]
    info = json.loads(
        client.get_object(Key=key,
                          Bucket=config["s3"]["bucket"])["Body"].read())
    host = info["public_ip"]
    redis_client = redis.StrictRedis(host=host, port=port, password=password)
    while (True):
        try:
            redis_client.ping()
            click.echo("successful ping!")
            break
        except redis.exceptions.ConnectionError as e:
            click.echo("ping failed.")
            pass
Esempio n. 2
0
def get_control_plane_id(config=None):
    ''' If there are multiple active control planes
        connect return first one, if there are none
        return None'''
    if (config == None):
        config = npw.config.default()
    rc = config["control_plane"]
    prefix = rc["control_plane_prefix"].strip("/") + "/"
    keys = list_all_keys(prefix=prefix)
    if (len(keys) == 0):
        return None
    else:
        return keys[0]
Esempio n. 3
0
def get_control_plane_id(config=None):
    ''' If there are multiple active control planes
        connect return first one, if there are none
        return None'''
    if (config == None):
        config = npw.config.default()
    rc = config["control_plane"]
    prefix = rc["control_plane_prefix"].strip("/")
    bucket = config["s3"]["bucket"]
    keys = list_all_keys(prefix=prefix, bucket=bucket)
    if (len(keys) == 0):
        return None
    else:
        return os.path.basename(keys[0])
Esempio n. 4
0
def list():
    config = npw.config.default()
    client = boto3.client('s3')
    rc = config["control_plane"]
    prefix = rc["control_plane_prefix"].strip("/")
    bucket = config["s3"]["bucket"]
    keys = list_all_keys(prefix=prefix, bucket=bucket)
    dicts = []
    for i, key in enumerate(keys):
        dicts.append(
            json.loads(
                client.get_object(
                    Key=key, Bucket=config["s3"]["bucket"])["Body"].read()))
    if (len(dicts) > 0):
        # maybe custom pretty printing here, but pandas does a god enough job
        click.echo(pd.DataFrame(dicts))
    else:
        click.echo("No control planes found")
Esempio n. 5
0
def terminate(idx):
    config = npw.config.default()
    client = boto3.client('s3')
    rc = config["control_plane"]
    prefix = rc["control_plane_prefix"].strip("/")
    bucket = config["s3"]["bucket"]
    keys = list_all_keys(prefix=prefix, bucket=bucket)
    if (idx >= len(keys)):
        click.echo("idx must be less that number of total control planes")
        return
    key = keys[idx]
    info = json.loads(
        client.get_object(Key=key,
                          Bucket=config["s3"]["bucket"])["Body"].read())
    instance_id = info['id']
    ec2_client = boto3.client('ec2')
    click.echo("terminating control plane {0}".format(idx))
    resp = ec2_client.terminate_instances(InstanceIds=[instance_id])
    client.delete_object(Key=key, Bucket=bucket)