本文整理汇总了Python中boto.vpc方法的典型用法代码示例。如果您正苦于以下问题:Python boto.vpc方法的具体用法?Python boto.vpc怎么用?Python boto.vpc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto
的用法示例。
在下文中一共展示了boto.vpc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_sg_subnets
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def get_sg_subnets(name, vpc_id, region, profile=None):
"""
Args:
name (str): The name of the security group you are looking for.
vpc_id (str): The VPC id where this security group resides.
region (str): The AWS region.
Basic Usage:
>>> name = 'ProductionELB'
>>> region = 'us-west-2'
>>> vpc_id = 'vpc-123456'
>>> subnets = get_sg_subnets(name, vpc_id, region)
>>> print subnets
Returns:
String
"""
cidrs = get_sg_cidrs(name, vpc_id, region, profile)
subnets = list()
for subnet in cidrs:
subnets.append(subnet.split("/")[0])
return subnets
示例2: get_vpc_ids_from_names
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def get_vpc_ids_from_names(vpc_names, region=None, profile=None):
"""Return a list of vpc ids from the list of vpc names that were matched.
Args:
vpc_names (list): List of vpc names you are searching for.
client (Boto3.Client): The instantiated boto3 client.
"""
vpc_ids = list()
client = aws_client(region, 'ec2', profile)
vpcs = client.describe_vpcs()
for vpc in vpcs['Vpcs']:
if 'Tags' in vpc:
for tag in vpc['Tags']:
if tag['Key'] == 'Name':
for name in vpc_names:
if re.search(name, tag['Value'], re.IGNORECASE):
vpc_ids.append(vpc['VpcId'])
return vpc_ids
示例3: vpc_exists
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def vpc_exists(name, region):
"""
Args:
name (str): The name of the vpc you are retrieving the id for.
region (str): The AWS region.
Basic Usage:
>>> vpc_name = 'test'
>>> aws_region = 'us-west-2'
>>> vpc_id = vpc_exists(vpc_name, aws_region)
'vpc-1234567'
Returns:
VPC ID
"""
vpc_id = None
try:
vpc_id = get_vpc_id_by_name(name, region)
except Exception:
vpc_id = 'does not exist'
return vpc_id
示例4: __init__
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def __init__(self, region):
self.uid='ut_{}'.format(random.randint(1, 10000000000))
self.region_name = region
self.ec2_conn = boto.ec2.connect_to_region(region)
self.vpc_conn = boto.vpc.connect_to_region(region)
self.key_name = self.uid+'_kp'
self.vpc_id = ''
self.vpc_name = self.uid+'_vpc'
self.vpc_netmask = '10.0.0.0/24'
self.subnet_id = ''
self.subnet_name = self.uid+'_subnet'
self.subnet_netmask = self.vpc_netmask
示例5: _get_net_info
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def _get_net_info(self, server, resources):
"""
Look up the IP address, gateway, and subnet range.
"""
# gw_type, gw_info = self._get_nat_info(server["vpc"], server["subnet"])
# gw = gw_info["nics"][0]["ip_address"]
# gw = "0.0.0.0"
cidr = server["cidr"].split("/")[1]
ip = self._get_data_ip(server)
gw_info = server["cidr"].split("/")[0].split(".")
gw = "%s.%s.%s.1" % (gw_info[0], gw_info[1], gw_info[2])
# We want to use the host NIC, so modify LXC to use phys networking, and
# then start the docker containers on the server.
lxc_opts = ["lxc.network.type = phys",
"lxc.network.ipv4 = %s/%s" % (ip, cidr),
"lxc.network.ipv4.gateway = %s" % gw,
"lxc.network.link = eth1",
"lxc.network.name = eth1",
"lxc.network.flags = up"]
return lxc_opts, ip
示例6: vpc
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def vpc(self):
"""
fetch vpc connection, open if necessary
"""
if self._region['vpc_conn']:
return self._region['vpc_conn']
region = self.region()
if self._region['vpc_conn'] is None:
log.debug("Connecting to VPC region {}".format(region))
self._region['vpc_conn'] = boto.vpc.connect_to_region(
region,
is_secure=False
)
assert self._region['vpc_conn'] is not None, (
("Failed to connect to VPC service in region {!r}"
.format(region)))
return self._region['vpc_conn']
示例7: get_sg
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def get_sg(name, vpc_id, region, profile=None):
"""
Args:
name (str): The name of the security group you are looking for.
vpc_id (str): The VPC id where this security group resides.
region (str): The AWS region.
Basic Usage:
>>> name = 'ProductionELB'
>>> region = 'us-west-2'
>>> vpc_id = 'vpc-123456'
>>> security_group_id = get_sg(name, vpc_id, region)
>>> print security_group_id
Returns:
String
"""
connect = boto.ec2.connect_to_region(region)
filter_by = {
"tag-key": "Name",
"tag-value": name,
"vpc-id": vpc_id
}
try:
sg_groups = connect.get_all_security_groups(filters=filter_by)
if len(sg_groups) == 1:
return sg_groups[0].id
elif len(sg_groups) > 1:
raise errors.AnsibleFilterError(
"Too many results for {0}: {1}".format(
name, ",".join(sg_groups)
)
)
else:
raise errors.AnsibleFilterError(
"Security Group {0} was not found".format(name)
)
except botocore.exceptions.ClientError as e:
raise e
示例8: get_route_table_ids
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def get_route_table_ids(vpc_id, region=None, profile=None):
"""
Args:
vpc_id (str): The vpc id in which the subnet you are looking
for lives in,
Basic Usage:
>>> vpc_id = 'vpc-12345678'
>>> get_route_table_ids(vpc_id)
['rtb-1234567a']
Returns:
List of route table ids
"""
route_ids = list()
client = aws_client(region, 'ec2', profile)
params = {
'Filters': [
{
'Name': 'vpc-id',
'Values': [vpc_id],
},
{
'Name': 'association.main',
'Values': ['false']
}
]
}
routes = client.describe_route_tables(**params)
if routes:
route_ids = (
map(lambda route: route['RouteTableId'], routes['RouteTables'])
)
return route_ids
else:
raise errors.AnsibleFilterError("No routes were found")
示例9: get_all_route_table_ids_except
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def get_all_route_table_ids_except(vpc_id, region=None, profile=None):
"""
Args:
vpc_id (str): The vpc you want to exclude routes from.
Basic Usage:
>>> vpc_id = 'vpc-98c797fd'
>>> get_all_route_table_ids_except(vpc_id)
['rtb-5f78343a']
Returns:
List of route table ids
"""
route_ids = list()
client = aws_client(region, 'ec2', profile)
params = {
'Filters': [
{
'Name': 'association.main',
'Values': ['false']
}
]
}
routes = client.describe_route_tables(**params)
if routes:
for route in routes['RouteTables']:
if route['VpcId'] != vpc_id:
route_ids.append(route['RouteTableId'])
if len(route_ids) > 0:
return route_ids
else:
raise errors.AnsibleFilterError("No routes were found")
else:
raise errors.AnsibleFilterError("No routes were found")
示例10: get_all_route_table_ids_except_vpc_names
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def get_all_route_table_ids_except_vpc_names(vpc_names, region=None,
profile=None):
"""
Args:
vpc_names (list): List of vpc names you are searching for.
Kwargs:
region (str): The AWS region.
Basic Usage:
>>> vpc_names = ['test', 'foo']
>>> get_all_route_table_ids_except_vpc_names(vpc_names)
['rtb-123456']
Returns:
List of route table ids
"""
route_ids = list()
client = aws_client(region, 'ec2', profile)
vpc_ids = get_vpc_ids_from_names(vpc_names, region, profile)
params = {
'Filters': [
{
'Name': 'association.main',
'Values': ['false']
}
]
}
routes = client.describe_route_tables(**params)
if routes:
for route in routes['RouteTables']:
if route['VpcId'] not in vpc_ids:
route_ids.append(route['RouteTableId'])
if len(route_ids) > 0:
return route_ids
else:
raise errors.AnsibleFilterError("No routes were found")
else:
raise errors.AnsibleFilterError("No routes were found")
示例11: get_subnet_ids_in_zone
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def get_subnet_ids_in_zone(vpc_id, zone, region=None, profile=None):
"""
Args:
vpc_id (str): The vpc id in which the subnet you are looking
for lives in,
zone (str): The region in which the subnet resides.
Basic Usage:
>>> vpc_id = 'vpc-12345678'
>>> aws_region = 'us-west-2'
>>> zone = 'us-west-2c'
>>> get_subnet_ids_in_zone(vpc_id, zone, aws_region)
[u'subnet-4324567', u'subnet-12345678', u'subnet-6543210']
Returns:
List of subnet ids
"""
subnet_ids = list()
client = aws_client(region, 'ec2', profile)
params = {
'Filters': [
{
'Name': 'vpc-id',
'Values': [vpc_id],
},
{
'Name': 'availabilityZone',
'Values': [zone],
}
]
}
subnets = client.describe_subnets(**params)['Subnets']
if subnets:
subnet_ids = map(lambda subnet: subnet['SubnetId'], subnets)
return subnet_ids
else:
raise errors.AnsibleFilterError("No subnets were found")
示例12: vpc
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def vpc(self):
"""
:rtype: VPCConnection
"""
if self.__vpc is None:
self.__vpc = self.__aws_connect(vpc)
return self.__vpc
# ec2 = vpc works, too, but confuses the type hinter in PyCharm
示例13: _init_aws_clients
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def _init_aws_clients(self):
# We will need to use both EC2 and VPC.
self.ec2 = boto.ec2.connect_to_region(self.default_dc,
aws_access_key_id = self.aws_access_key,
aws_secret_access_key = self.aws_secret_key)
self.vpc = boto.vpc.VPCConnection(aws_access_key_id = self.aws_access_key,
aws_secret_access_key = self.aws_secret_key)
self.cf = boto.cloudformation.connect_to_region(self.default_dc,
aws_access_key_id = self.aws_access_key,
aws_secret_access_key = self.aws_secret_key)
示例14: _create_routetable
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def _create_routetable(self, name, subnet, vpc):
plan = { name : { "Type" : "AWS::EC2::RouteTable",
"Properties" : { "VpcId" : vpc}}}
desc = { name : { "type" : "AWS::EC2::RouteTable",
"vpc" : vpc }}
return plan, desc
示例15: _create_floatingip_plan
# 需要导入模块: import boto [as 别名]
# 或者: from boto import vpc [as 别名]
def _create_floatingip_plan(self, cluster_uuid, instances):
"""
Assign an elastic IP to the secondary device of each instance.
"""
plan = { "AWSTemplateFormatVersion" : "2010-09-09",
"Description" : "Ferry generated CloudFormation plan",
"Resources" : {} }
desc = {}
for instance in instances:
eip_name = "FerryEIP" + instance["name"]
assoc_name = "FerryEIPAssoc" + instance["name"]
eip_resource = {
"Type" : "AWS::EC2::EIP",
"Properties" : {
"Domain" : "vpc"
}
}
assoc_resource = {
"Type": "AWS::EC2::EIPAssociation",
"Properties": {
"AllocationId" : { "Fn::GetAtt" : [ eip_name, "AllocationId" ]},
"NetworkInterfaceId": { "Ref" : instance["data_nic"] }
# "InstanceId": { "Ref" : instance["name"] }
}
}
plan["Resources"][eip_name] = eip_resource
plan["Resources"][assoc_name] = assoc_resource
desc[eip_name] = { "type" : "AWS::EC2::EIP" }
return plan, desc