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


Python VPCConnection.create_subnet方法代码示例

本文整理汇总了Python中boto.vpc.VPCConnection.create_subnet方法的典型用法代码示例。如果您正苦于以下问题:Python VPCConnection.create_subnet方法的具体用法?Python VPCConnection.create_subnet怎么用?Python VPCConnection.create_subnet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boto.vpc.VPCConnection的用法示例。


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

示例1: create_subnet

# 需要导入模块: from boto.vpc import VPCConnection [as 别名]
# 或者: from boto.vpc.VPCConnection import create_subnet [as 别名]
def create_subnet(vpc_id, cidr_block, availability_zone, subnet_name, region):
    vpc = VPCConnection(aws_access_key_id=access_key, aws_secret_access_key=secret_key)
    datacenters = vpc.create_subnet(vpc_id=vpc_id, cidr_block=cidr_block, availability_zone=availability_zone)
        
    ec2_conn = boto.ec2.connect_to_region(region,
                    aws_access_key_id=access_key,
                    aws_secret_access_key=secret_key)
    time.sleep(1)
    ec2_conn.create_tags(datacenters.id, {"Name": subnet_name, "Project": 'LiveLiveProd'})
    return datacenters.id
开发者ID:panxincheng,项目名称:Python,代码行数:12,代码来源:Provision_AWS_v2.py

示例2: test_db_subnet_group

# 需要导入模块: from boto.vpc import VPCConnection [as 别名]
# 或者: from boto.vpc.VPCConnection import create_subnet [as 别名]
    def test_db_subnet_group(self):
        vpc_api  = VPCConnection()
        rds_api  = RDSConnection()
        vpc      = vpc_api.create_vpc('10.0.0.0/16')

        az_list = vpc_api.get_all_zones(filters={'state':'available'})
        subnet = list()
        n      = 0;
        for az in az_list:
            try:
                subnet.append(vpc_api.create_subnet(vpc.id, '10.0.'+str(n)+'.0/24',availability_zone=az.name))
                n = n+1
            except:
                pass

        grp_name     = 'db_subnet_group'+str(int(time.time()))
        subnet_group = rds_api.create_db_subnet_group(grp_name, grp_name, [subnet[0].id,subnet[1].id])
        if not _is_ok(subnet_group, vpc.id, grp_name, [subnet[0].id,subnet[1].id]):
            raise Exception("create_db_subnet_group returned bad values")

        rds_api.modify_db_subnet_group(grp_name, description='new description')
        subnet_grps = rds_api.get_all_db_subnet_groups(name=grp_name)
        if not _is_ok(subnet_grps[0], vpc.id, 'new description', [subnet[0].id,subnet[1].id]):
            raise Exception("modifying the subnet group desciption returned bad values")

        rds_api.modify_db_subnet_group(grp_name, subnet_ids=[subnet[1].id,subnet[2].id])
        subnet_grps = rds_api.get_all_db_subnet_groups(name=grp_name)
        if not _is_ok(subnet_grps[0], vpc.id, 'new description', [subnet[1].id,subnet[2].id]):
            raise Exception("modifying the subnet group subnets returned bad values")

        rds_api.delete_db_subnet_group(subnet_group.name)
        try:
            rds_api.get_all_db_subnet_groups(name=grp_name)
            raise Exception(subnet_group.name+" still accessible after delete_db_subnet_group")
        except:
            pass
            
        while n > 0:
            n = n-1
            vpc_api.delete_subnet(subnet[n].id)
        vpc_api.delete_vpc(vpc.id)
开发者ID:10sr,项目名称:hue,代码行数:43,代码来源:test_db_subnet_group.py

示例3: len

# 需要导入模块: from boto.vpc import VPCConnection [as 别名]
# 或者: from boto.vpc.VPCConnection import create_subnet [as 别名]
    print "Existing VPC ID: {}\n".format(aws_vpc_id)
    # Use existing VPC
    new_vpc = vpcc.get_all_vpcs(filters=[("cidrBlock", VPC_CIDR)])
"""
   # Doesn't work due to VPC dependency
    print "Requested VPC already exists! Will attempt to delete vpc and recreate"
    del_status = vpcc.delete_vpc(aws_vpc_id)
    print "Deletion Completed", del_status
"""

exist_subnet1 = vpcc.get_all_subnets(filters=[("cidrBlock", VPC_SUBNET1)])
exist_subnet2 = vpcc.get_all_subnets(filters=[("cidrBlock", VPC_SUBNET2)])

if not len(exist_subnet1):
    print "Creating new subnet ..."
    new_subnet1 = vpcc.create_subnet(aws_vpc_id, VPC_SUBNET1, AVAIL_ZONE1, dry_run=BOOLEAN_DRYRUN)
    subnet1_id = new_subnet1.id
    print "New subnet 1 ID: {}\n".format(subnet1_id)
else:
    print "Subnet with {} already exists.  Skipped creation".format(VPC_SUBNET1)
    subnet1_id = str(exist_subnet1.pop(0))[7:]
    print "Existing subnet 1 ID: {}\n".format(subnet1_id)

if not len(exist_subnet2):
    print "Creating new subnet2 ..."
    new_subnet2 = vpcc.create_subnet(aws_vpc_id, VPC_SUBNET2, AVAIL_ZONE2, dry_run=BOOLEAN_DRYRUN)
    subnet2_id = new_subnet2.id
    print "New subnet 2 ID: {}\n".format(subnet2_id)
else:
    print "Subnet with {} already exists.  Skipped creation".format(VPC_SUBNET2)
    subnet2_id = str(exist_subnet2.pop(0))[7:]
开发者ID:AnthonyWC,项目名称:aws_boto,代码行数:33,代码来源:deploy.py

示例4: VPCConnection

# 需要导入模块: from boto.vpc import VPCConnection [as 别名]
# 或者: from boto.vpc.VPCConnection import create_subnet [as 别名]
import time

cloud_network		= '10.1.0.0/16'
blue_subnet 		= '10.1.0.0/24'
green_subnet 		= '10.1.1.0/24'
generic_linux_image	= 'ami-a250ecca'
nat_linux_image		= 'ami-184dc970'

connection			= VPCConnection()
private_cloud 		= connection.create_vpc(cloud_network)

time.sleep(2) #fix race condition later
private_cloud.add_tag('Name', 'virtual-private-cloud')
print ("created vpc", private_cloud.id)

private_subnet = connection.create_subnet(private_cloud.id, green_subnet)
time.sleep(2) #fix race condition later
private_subnet.add_tag('Name', 'green_subnet')
public_subnet = connection.create_subnet(private_cloud.id, blue_subnet)
time.sleep(2)
public_subnet.add_tag('Name', 'blue_subnet')
print "created public and private subnets"

igw = connection.create_internet_gateway()
connection.attach_internet_gateway(igw.id, private_cloud.id)

print "created and attached internet gateway"

host_security_group = connection.create_security_group('private_cloud_sg', 'private_cloud_sg', private_cloud.id)
host_security_group.authorize('tcp', 80, 80, '0.0.0.0/0')
host_security_group.authorize('tcp', 22, 22, '0.0.0.0/0')
开发者ID:kaiho,项目名称:awstests,代码行数:33,代码来源:create-environment.py

示例5: create_subnet

# 需要导入模块: from boto.vpc import VPCConnection [as 别名]
# 或者: from boto.vpc.VPCConnection import create_subnet [as 别名]
def create_subnet(vpc, subnet_cidr):
    ec2region = vpc.region
    conn = VPCConnection(region=ec2region)
    return conn.create_subnet(vpc.id, subnet_cidr)
开发者ID:syokenz,项目名称:aws-scripts,代码行数:6,代码来源:vpc.py

示例6: create_security_group

# 需要导入模块: from boto.vpc import VPCConnection [as 别名]
# 或者: from boto.vpc.VPCConnection import create_subnet [as 别名]
def create_security_group(ec2_conn,vpc_id,security_group_name):
	        groups = ec2_conn.get_all_security_groups()
		for group in groups :
			if group.name == security_group_name :
				return group
		web = ec2_conn.create_security_group(security_group_name,vpc_id=vpc_id,description='ABC Talks Group')
		web.authorize('tcp',8080,8080,'0.0.0.0/0')
		return web
def create_network_interface(ec2_conn,domain='vpc',public=False,subnet=None,groups=None,description=None):
	elastic_network_interface = ec2_conn.create_network_interface(subnet,groups=groups,description=description)
	if public:
		elastic_ip_address = ec2_conn.allocate_address(domain=domain)
		associated_address = ec2_conn.associate_address(allocation_id=elastic_ip_address.allocation_id,network_interface_id=elastic_network_interface.id)
	return elastic_netowrk_interface 
vpc_connection = VPCConnection(aws_access_key_id='',aws_secret_access_key='')
vpc = vpc_connection.create_vpc('10.0.0.0/16')
print vpc.id
print vpc.state
time.sleep(60)
print vpc.state
subnet = vpc_connection.create_subnet(vpc.id,'10.0.0.0/25')
print subnet.state
print subnet.available_ip_address_count
ec2_conn = ec2.connect_to_region('us-east-1',aws_access_key_id='',aws_secret_access_key='')

web = create_security_group(ec2_conn,vpc.id,'abctalks1')
#address = address.Address(connection=ec2_conn,instance_id=ec2_instance.instances[0].id)
print address
network_interface = create_network_interface(ec2_conn,public=True,subnet=subnet,groups=[web.id],description='Storm Cluster')
ec2_instance = create_ec2_instance(ec2_conn,'ami-d05e75b8','abctalks',get_user_data(),web.id,subnet.id,network_interface)
开发者ID:ctaram,项目名称:AWS_Basics,代码行数:32,代码来源:vpn.py


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