当前位置: 首页>>代码示例>>Python>>正文


Python boto.connect_vpc函数代码示例

本文整理汇总了Python中boto.connect_vpc函数的典型用法代码示例。如果您正苦于以下问题:Python connect_vpc函数的具体用法?Python connect_vpc怎么用?Python connect_vpc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了connect_vpc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_config

def load_config(show_output=False):
    config_filename = path.join(directory, 'config')
    aws_dirty = False
    if not boto.config.has_option('Credentials', 'aws_access_key_id'):
        aws_access_key_id = getpass.getpass('AWS Access Key ID: ')
        boto.config.save_user_option('Credentials', 'aws_access_key_id', aws_access_key_id)
        aws_dirty = True
    if not boto.config.has_option('Credentials', 'aws_secret_access_key'):
        aws_secret_access_key = getpass.getpass('AWS Secret Access Key: ')
        boto.config.save_user_option('Credentials', 'aws_secret_access_key', aws_secret_access_key)
        aws_dirty = True
    if aws_dirty:
        print "-----> AWS configuration written to {}".format(boto.pyami.config.UserConfigPath)
    else:
        if show_output: print "-----> AWS configuration unchanged, see `{}`".format(boto.pyami.config.UserConfigPath)
    vpc = boto.connect_vpc()
    try:
        with open(config_filename, 'r') as config_file:
            config = json.loads(config_file.read())
    except IOError:
        config = default_config()
    dirty = False
    vpc_id = config.get('vpc_id')
    if not vpc_id:
        vpc_id = raw_input("AWS VPC ID (choose: {}): ".format(', '.join([v.id for v in vpc.get_all_vpcs()])))
        config['vpc_id'] = vpc_id
        dirty = True
    subnet_id = config.get('subnet_id')
    if not subnet_id:
        def format_subnet(s):
            return '{}({})'.format(s.id, s.availability_zone)
        possible_subnets = vpc.get_all_subnets(filters=[('vpcId', vpc_id)])
        subnet_id = raw_input("AWS VPC Subnet ID (choose: {}): ".format(', '.join(map(format_subnet, possible_subnets))))
        config['subnet_id'] = subnet_id
        dirty = True
    subnet = vpc.get_all_subnets(subnet_ids=[subnet_id])[0]
    if config['availability_zone'] != subnet.availability_zone:
        config['availability_zone'] = subnet.availability_zone
        dirty = True
    system_name = config.get('system_name')
    if not system_name:
        config['system_name'] = raw_input("Name of your \"system\" (press return for a uuid): ") or uuid.uuid1().hex
        dirty = True
    if dirty:
        config_filename = path.join(directory, 'config')
        if not path.exists(directory):
            os.makedirs(directory)
        with open(config_filename, 'w') as config_file:
            config_file.write(json.dumps(config, indent=2, separators=(',', ': ')))
            print "-----> Riker configuration written to {}".format(config_filename)
    else:
        if show_output: print "-----> Riker configuration unchanged, see `{}`".format(config_filename)
    def create_sgrs(memo, kvp):
        name = kvp[0]
        rules = kvp[1]
        sgrs = [boto_helpers.SecurityGroupRule(*rule) for rule in rules]
        memo[name] = sgrs
        return memo
    config['security_groups'] = reduce(create_sgrs, config['security_groups'].iteritems(), {})
    return config
开发者ID:gimlids,项目名称:riker,代码行数:60,代码来源:config.py

示例2: connect_vpc

def connect_vpc():
    logger.debug('Connecting to the Amazon Virtual Private Cloud (Amazon VPC) service.')
    vpc = boto.connect_vpc(aws_access_key_id=config['AWS_ACCESS_KEY_ID'],
                           aws_secret_access_key=config['AWS_SECRET_ACCESS_KEY'])
    logger.debug('Connected to Amazon VPC.')

    return vpc
开发者ID:onewheelskyward,项目名称:sky,代码行数:7,代码来源:networking.py

示例3: test_detach_vpn_gateway

def test_detach_vpn_gateway():

    conn = boto.connect_vpc('the_key', 'the_secret')
    vpc = conn.create_vpc("10.0.0.0/16")
    vpn_gateway = conn.create_vpn_gateway('ipsec.1', 'us-east-1a')

    conn.attach_vpn_gateway(
        vpn_gateway_id=vpn_gateway.id,
        vpc_id=vpc.id
    )

    gateway = conn.get_all_vpn_gateways()[0]
    attachments = gateway.attachments
    attachments.should.have.length_of(1)
    attachments[0].vpc_id.should.equal(vpc.id)
    attachments[0].state.should.equal('attached')

    conn.detach_vpn_gateway(
        vpn_gateway_id=vpn_gateway.id,
        vpc_id=vpc.id
    )

    gateway = conn.get_all_vpn_gateways()[0]
    attachments = gateway.attachments
    attachments.should.have.length_of(0)
开发者ID:2rs2ts,项目名称:moto,代码行数:25,代码来源:test_virtual_private_gateways.py

示例4: test_route_tables_filters_standard

def test_route_tables_filters_standard():
    conn = boto.connect_vpc('the_key', 'the_secret')

    vpc1 = conn.create_vpc("10.0.0.0/16")
    route_table1 = conn.create_route_table(vpc1.id)

    vpc2 = conn.create_vpc("10.0.0.0/16")
    route_table2 = conn.create_route_table(vpc2.id)

    all_route_tables = conn.get_all_route_tables()
    all_route_tables.should.have.length_of(4)

    # Filter by main route table
    main_route_tables = conn.get_all_route_tables(filters={'association.main':'true'})
    main_route_tables.should.have.length_of(2)
    main_route_table_ids = [route_table.id for route_table in main_route_tables]
    main_route_table_ids.should_not.contain(route_table1.id)
    main_route_table_ids.should_not.contain(route_table2.id)

    # Filter by VPC
    vpc1_route_tables = conn.get_all_route_tables(filters={'vpc-id':vpc1.id})
    vpc1_route_tables.should.have.length_of(2)
    vpc1_route_table_ids = [route_table.id for route_table in vpc1_route_tables]
    vpc1_route_table_ids.should.contain(route_table1.id)
    vpc1_route_table_ids.should_not.contain(route_table2.id)

    # Filter by VPC and main route table
    vpc2_main_route_tables = conn.get_all_route_tables(filters={'association.main':'true', 'vpc-id':vpc2.id})
    vpc2_main_route_tables.should.have.length_of(1)
    vpc2_main_route_table_ids = [route_table.id for route_table in vpc2_main_route_tables]
    vpc2_main_route_table_ids.should_not.contain(route_table1.id)
    vpc2_main_route_table_ids.should_not.contain(route_table2.id)

    # Unsupported filter
    conn.get_all_route_tables.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
开发者ID:DarthLorenzo,项目名称:moto,代码行数:35,代码来源:test_route_tables.py

示例5: test_eip_reassociate_nic

def test_eip_reassociate_nic():
    """reassociate EIP"""
    conn = boto.connect_vpc('the_key', 'the_secret')

    vpc = conn.create_vpc("10.0.0.0/16")
    subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
    eni1 = conn.create_network_interface(subnet.id)
    eni2 = conn.create_network_interface(subnet.id)

    eip = conn.allocate_address()
    conn.associate_address(network_interface_id=eni1.id,
                           public_ip=eip.public_ip)

    # Same ID is idempotent
    conn.associate_address(network_interface_id=eni1.id,
                           public_ip=eip.public_ip)

    # Different ID detects resource association
    with assert_raises(EC2ResponseError) as cm:
        conn.associate_address(
            network_interface_id=eni2.id, public_ip=eip.public_ip)
    cm.exception.code.should.equal('Resource.AlreadyAssociated')
    cm.exception.status.should.equal(400)
    cm.exception.request_id.should_not.be.none

    conn.associate_address.when.called_with(
        network_interface_id=eni2.id, public_ip=eip.public_ip, allow_reassociation=True).should_not.throw(EC2ResponseError)

    eip.release()
    eip = None
开发者ID:Affirm,项目名称:moto,代码行数:30,代码来源:test_elastic_ip_addresses.py

示例6: test_run_instance_with_nic_autocreated

def test_run_instance_with_nic_autocreated():
    conn = boto.connect_vpc('the_key', 'the_secret')
    vpc = conn.create_vpc("10.0.0.0/16")
    subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")
    security_group1 = conn.create_security_group('test security group #1', 'this is a test security group')
    security_group2 = conn.create_security_group('test security group #2', 'this is a test security group')
    private_ip = "54.0.0.1"

    reservation = conn.run_instances('ami-1234abcd', subnet_id=subnet.id,
                                                     security_groups=[security_group1.name],
                                                     security_group_ids=[security_group2.id],
                                                     private_ip_address=private_ip)
    instance = reservation.instances[0]

    all_enis = conn.get_all_network_interfaces()
    all_enis.should.have.length_of(1)
    eni = all_enis[0]

    instance.interfaces.should.have.length_of(1)
    instance.interfaces[0].id.should.equal(eni.id)

    instance.subnet_id.should.equal(subnet.id)
    instance.groups.should.have.length_of(2)
    set([group.id for group in instance.groups]).should.equal(set([security_group1.id,security_group2.id]))

    eni.subnet_id.should.equal(subnet.id)
    eni.groups.should.have.length_of(2)
    set([group.id for group in eni.groups]).should.equal(set([security_group1.id,security_group2.id]))
    eni.private_ip_addresses.should.have.length_of(1)
    eni.private_ip_addresses[0].private_ip_address.should.equal(private_ip)
开发者ID:EvaSDK,项目名称:moto,代码行数:30,代码来源:test_instances.py

示例7: test_route_tables_filters_associations

def test_route_tables_filters_associations():
    conn = boto.connect_vpc('the_key', 'the_secret')

    vpc = conn.create_vpc("10.0.0.0/16")
    subnet1 = conn.create_subnet(vpc.id, "10.0.0.0/18")
    subnet2 = conn.create_subnet(vpc.id, "10.0.1.0/18")
    subnet3 = conn.create_subnet(vpc.id, "10.0.2.0/18")
    route_table1 = conn.create_route_table(vpc.id)
    route_table2 = conn.create_route_table(vpc.id)

    association_id1 = conn.associate_route_table(route_table1.id, subnet1.id)
    association_id2 = conn.associate_route_table(route_table1.id, subnet2.id)
    association_id3 = conn.associate_route_table(route_table2.id, subnet3.id)

    all_route_tables = conn.get_all_route_tables()
    all_route_tables.should.have.length_of(3)

    # Filter by association ID
    association1_route_tables = conn.get_all_route_tables(filters={'association.route-table-association-id':association_id1})
    association1_route_tables.should.have.length_of(1)
    association1_route_tables[0].id.should.equal(route_table1.id)
    association1_route_tables[0].associations.should.have.length_of(2)

    # Filter by route table ID
    route_table2_route_tables = conn.get_all_route_tables(filters={'association.route-table-id':route_table2.id})
    route_table2_route_tables.should.have.length_of(1)
    route_table2_route_tables[0].id.should.equal(route_table2.id)
    route_table2_route_tables[0].associations.should.have.length_of(1)

    # Filter by subnet ID
    subnet_route_tables = conn.get_all_route_tables(filters={'association.subnet-id':subnet1.id})
    subnet_route_tables.should.have.length_of(1)
    subnet_route_tables[0].id.should.equal(route_table1.id)
    association1_route_tables[0].associations.should.have.length_of(2)
开发者ID:DarthLorenzo,项目名称:moto,代码行数:34,代码来源:test_route_tables.py

示例8: test_start_vpc_spot_instance

    def test_start_vpc_spot_instance(self):
        c = self.botoSetup()

        vpc_conn = boto.connect_vpc()
        vpc = vpc_conn.create_vpc("192.168.0.0/24")
        subnet = vpc_conn.create_subnet(vpc.id, "192.168.0.0/24")
        amis = c.get_all_images()

        sg = c.create_security_group("test_sg", "test_sg", vpc.id)

        bs = ec2.EC2LatentWorker('bot1', 'sekrit', 'm1.large',
                                 identifier='publickey',
                                 secret_identifier='privatekey',
                                 keypair_name="test_key",
                                 ami=amis[0].id, spot_instance=True,
                                 max_spot_price=1.5,
                                 security_group_ids=[sg.id],
                                 subnet_id=subnet.id,
                                 )

        instance_id, _, _ = bs._start_instance()
        instances = [i for i in c.get_only_instances()
                     if i.state != "terminated"]

        self.assertTrue(bs.spot_instance)
        self.assertEqual(len(instances), 1)
        self.assertEqual(instances[0].id, instance_id)
        self.assertEqual(instances[0].subnet_id, subnet.id)
        self.assertEqual(len(instances[0].groups), 1)
        self.assertEqual(instances[0].groups[0].id, sg.id)
开发者ID:aelsabbahy,项目名称:buildbot,代码行数:30,代码来源:test_worker_ec2.py

示例9: connect

def connect(vpc_region):
    access_key, secret_key = read_credentials()
    s3_conn = boto.connect_s3(access_key, secret_key)
    ec2_conn = boto.ec2.connect_to_region(vpc_region, aws_access_key_id=access_key, aws_secret_access_key=secret_key)
    region = boto.ec2.get_region(vpc_region, aws_access_key_id=access_key, aws_secret_access_key=secret_key)
    vpc_conn = boto.connect_vpc(access_key, secret_key, region=region)
    return Connections(ec2_conn, vpc_conn, s3_conn)
开发者ID:arunsingh,项目名称:aws_vpc_py,代码行数:7,代码来源:aws.py

示例10: create_network

def create_network():
    vpc_connection = boto.connect_vpc()
    vpc = vpc_connection.create_vpc("10.0.0.0/24")
    subnet = vpc_connection.create_subnet(vpc.id, "10.0.0.0/25")
    gateway = vpc_connection.create_internet_gateway()
    vpc_connection.attach_internet_gateway(gateway.id, vpc.id)
    return subnet.id
开发者ID:CharlesGust,项目名称:sea-b27-python,代码行数:7,代码来源:fabfile.py

示例11: test_elastic_network_interfaces

def test_elastic_network_interfaces():
    conn = boto.connect_vpc('the_key', 'the_secret')
    vpc = conn.create_vpc("10.0.0.0/16")
    subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")

    with assert_raises(JSONResponseError) as ex:
        eni = conn.create_network_interface(subnet.id, dry_run=True)
    ex.exception.reason.should.equal('DryRunOperation')
    ex.exception.status.should.equal(400)
    ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the CreateNetworkInterface operation: Request would have succeeded, but DryRun flag is set')

    eni = conn.create_network_interface(subnet.id)

    all_enis = conn.get_all_network_interfaces()
    all_enis.should.have.length_of(1)
    eni = all_enis[0]
    eni.groups.should.have.length_of(0)
    eni.private_ip_addresses.should.have.length_of(0)

    with assert_raises(JSONResponseError) as ex:
        conn.delete_network_interface(eni.id, dry_run=True)
    ex.exception.reason.should.equal('DryRunOperation')
    ex.exception.status.should.equal(400)
    ex.exception.message.should.equal('An error occurred (DryRunOperation) when calling the DeleteNetworkInterface operation: Request would have succeeded, but DryRun flag is set')

    conn.delete_network_interface(eni.id)

    all_enis = conn.get_all_network_interfaces()
    all_enis.should.have.length_of(0)

    with assert_raises(EC2ResponseError) as cm:
        conn.delete_network_interface(eni.id)
    cm.exception.code.should.equal('InvalidNetworkInterfaceID.NotFound')
    cm.exception.status.should.equal(400)
    cm.exception.request_id.should_not.be.none
开发者ID:balintzs,项目名称:moto,代码行数:35,代码来源:test_elastic_network_interfaces.py

示例12: test_get_instances_filtering_by_vpc_id

def test_get_instances_filtering_by_vpc_id():
    conn = boto.connect_vpc('the_key', 'the_secret')
    vpc1 = conn.create_vpc("10.0.0.0/16")
    subnet1 = conn.create_subnet(vpc1.id, "10.0.0.0/27")
    reservation1 = conn.run_instances(
        'ami-1234abcd', min_count=1, subnet_id=subnet1.id)
    instance1 = reservation1.instances[0]

    vpc2 = conn.create_vpc("10.1.0.0/16")
    subnet2 = conn.create_subnet(vpc2.id, "10.1.0.0/27")
    reservation2 = conn.run_instances(
        'ami-1234abcd', min_count=1, subnet_id=subnet2.id)
    instance2 = reservation2.instances[0]

    reservations1 = conn.get_all_instances(filters={'vpc-id': vpc1.id})
    reservations1.should.have.length_of(1)
    reservations1[0].instances.should.have.length_of(1)
    reservations1[0].instances[0].id.should.equal(instance1.id)
    reservations1[0].instances[0].vpc_id.should.equal(vpc1.id)
    reservations1[0].instances[0].subnet_id.should.equal(subnet1.id)

    reservations2 = conn.get_all_instances(filters={'vpc-id': vpc2.id})
    reservations2.should.have.length_of(1)
    reservations2[0].instances.should.have.length_of(1)
    reservations2[0].instances[0].id.should.equal(instance2.id)
    reservations2[0].instances[0].vpc_id.should.equal(vpc2.id)
    reservations2[0].instances[0].subnet_id.should.equal(subnet2.id)
开发者ID:whummer,项目名称:moto,代码行数:27,代码来源:test_instances.py

示例13: assume_service

def assume_service(account_number, service, region='us-east-1'):
    conn = boto.connect_sts()

    role = conn.assume_role('arn:aws:iam::{0}:role/{1}'.format(
        account_number, current_app.config.get('LEMUR_INSTANCE_PROFILE', 'Lemur')), 'blah')

    if service in 'iam':
        return boto.connect_iam(
            aws_access_key_id=role.credentials.access_key,
            aws_secret_access_key=role.credentials.secret_key,
            security_token=role.credentials.session_token)

    elif service in 'elb':
        return boto.ec2.elb.connect_to_region(
            region,
            aws_access_key_id=role.credentials.access_key,
            aws_secret_access_key=role.credentials.secret_key,
            security_token=role.credentials.session_token)

    elif service in 'vpc':
        return boto.connect_vpc(
            aws_access_key_id=role.credentials.access_key,
            aws_secret_access_key=role.credentials.secret_key,
            security_token=role.credentials.session_token)

    elif service in 's3':
        return boto.s3.connect_to_region(
            region,
            aws_access_key_id=role.credentials.access_key,
            aws_secret_access_key=role.credentials.secret_key,
            security_token=role.credentials.session_token)
开发者ID:EADPCloudSeattle,项目名称:lemur,代码行数:31,代码来源:sts.py

示例14: test_start_vpc_instance

    def test_start_vpc_instance(self):
        c = self.botoSetup()

        vpc_conn = boto.connect_vpc()
        vpc = vpc_conn.create_vpc("192.168.0.0/24")
        subnet = vpc_conn.create_subnet(vpc.id, "192.168.0.0/24")
        amis = c.get_all_images()

        sg = c.create_security_group("test_sg", "test_sg", vpc.id)
        bs = ec2.EC2LatentWorker(
            "bot1",
            "sekrit",
            "m1.large",
            identifier="publickey",
            secret_identifier="privatekey",
            keypair_name="latent_buildbot_worker",
            security_group_ids=[sg.id],
            subnet_id=subnet.id,
            ami=amis[0].id,
        )

        instance_id, _, _ = bs._start_instance()
        instances = [i for i in c.get_only_instances() if i.state != "terminated"]

        self.assertEqual(len(instances), 1)
        self.assertEqual(instances[0].id, instance_id)
        self.assertEqual(instances[0].subnet_id, subnet.id)
        self.assertEqual(len(instances[0].groups), 1)
        self.assertEqual(instances[0].groups[0].id, sg.id)
        self.assertEqual(instances[0].key_name, "latent_buildbot_worker")
开发者ID:stefanseefeld,项目名称:buildbot,代码行数:30,代码来源:test_worker_ec2.py

示例15: test_elastic_network_interfaces_filtering

def test_elastic_network_interfaces_filtering():
    conn = boto.connect_vpc('the_key', 'the_secret')
    vpc = conn.create_vpc("10.0.0.0/16")
    subnet = conn.create_subnet(vpc.id, "10.0.0.0/18")

    security_group1 = conn.create_security_group('test security group #1', 'this is a test security group')
    security_group2 = conn.create_security_group('test security group #2', 'this is a test security group')

    eni1 = conn.create_network_interface(subnet.id, groups=[security_group1.id,security_group2.id])
    eni2 = conn.create_network_interface(subnet.id, groups=[security_group1.id])
    eni3 = conn.create_network_interface(subnet.id)

    all_enis = conn.get_all_network_interfaces()
    all_enis.should.have.length_of(3)

    # Filter by ENI ID
    enis_by_id = conn.get_all_network_interfaces(filters={'network-interface-id':eni1.id})
    enis_by_id.should.have.length_of(1)
    set([eni.id for eni in enis_by_id]).should.equal(set([eni1.id]))

    # Filter by Security Group
    enis_by_group = conn.get_all_network_interfaces(filters={'group-id':security_group1.id})
    enis_by_group.should.have.length_of(2)
    set([eni.id for eni in enis_by_group]).should.equal(set([eni1.id,eni2.id]))

    # Filter by ENI ID and Security Group
    enis_by_group = conn.get_all_network_interfaces(filters={'network-interface-id':eni1.id, 'group-id':security_group1.id})
    enis_by_group.should.have.length_of(1)
    set([eni.id for eni in enis_by_group]).should.equal(set([eni1.id]))

    # Unsupported filter
    conn.get_all_network_interfaces.when.called_with(filters={'not-implemented-filter': 'foobar'}).should.throw(NotImplementedError)
开发者ID:DreadPirateShawn,项目名称:moto,代码行数:32,代码来源:test_elastic_network_interfaces.py


注:本文中的boto.connect_vpc函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。