Example #1
0
def destroy_ec2_eip(context, instance_id):
    ec2 = get_ec2_instance_by_id(instance_id)
    if not ec2:
        click.echo(error('EC2 instance {} not found'.format(instance_id)))
        context.exit(-1)

    clean_eip_for_ec2_instance(ec2)
    click.echo(info('All elastic IP removed from {}'.format(instance_id)))
Example #2
0
def ec2_eip_binding_info(context, instance_id):
    ec2 = get_ec2_instance_by_id(instance_id)
    if not ec2:
        click.echo(error('EC2 instance {} not found'.format(instance_id)))
        context.exit(-1)

    for interface in ec2.subnet.network_interfaces.iterator():
        click.echo(info('Interface {}'.format(interface.id)))

        data = [(n['PrivateIpAddress'], n.get('Association',
                                              {}).get('PublicIp', ''))
                for n in interface.private_ip_addresses]
        click.echo(tabulate(data, headers=INFO_HEADER, tablefmt='fancy_grid'))
Example #3
0
def init_ec2_eip(context, instance_id, n_interface, n_per_interface):
    ec2 = get_ec2_instance_by_id(instance_id)
    if not ec2:
        click.echo(error('EC2 instance {} not found'.format(instance_id)))
        context.exit(-1)

    # we may need to create some interfaces here
    interfaces = list(ec2.subnet.network_interfaces.iterator())
    still_need_interface = n_interface - len(interfaces)
    for _ in range(still_need_interface):
        create_interface_for_ec2_instance(ec2)

    create_eip_for_ec2_instance(ec2, n_per_interface)
    click.echo(info('Elastic IP created and bound done'))
Example #4
0
def export_proxy(context, instance_id, filename='proxy'):
    ec2 = get_ec2_instance_by_id(instance_id)
    if not ec2:
        click.echo(error('EC2 instance {} not found'.format(instance_id)))
        context.exit(-1)

    ifs = ec2.subnet.network_interfaces.iterator()
    data = [(n['PrivateIpAddress'], n.get('Association',
                                          {}).get('PublicIp', '')) for i in ifs
            for n in i.private_ip_addresses]
    data = sorted(data)

    data = [
        '{}:{}\n'.format(k[1], index) for index, k in enumerate(data, 12000)
    ]
    with open(filename, 'w') as f:
        for d in data:
            f.write(d)

    click.echo(info('proxy generated at {}'.format(filename)))
Example #5
0
def export_squid_conf(context, instance_id, filename='squid.conf'):
    ec2 = get_ec2_instance_by_id(instance_id)
    if not ec2:
        click.echo(error('EC2 instance {} not found'.format(instance_id)))
        context.exit(-1)

    ifs = ec2.subnet.network_interfaces.iterator()
    data = [(n['PrivateIpAddress'], n.get('Association',
                                          {}).get('PublicIp', '')) for i in ifs
            for n in i.private_ip_addresses]
    data = sorted(data)

    privates = [{
        'ip': k[0],
        'port': index
    } for index, k in enumerate(data, 12000)]
    content = TEMPLATE.render_template('/squid.jinja', privates=privates)
    with open(filename, 'w') as f:
        f.write(content)

    click.echo(info('squid config generated at {}'.format(filename)))