有没有办法通过libcloud获取AWS上所有可用区域的列表?
通过powershell AWS SDK,我可以使用:
$regions = @(Get-AWSRegion)
foreach ($region in $regions)
{
$region.Region
}
我如何使用Python和libcloud来做同样的事情呢?
非常感谢,约翰尼
发布于 2015-08-05 19:59:40
尝尝这个。获取AWS区域的原始方法:
from libcloud.compute.types import Provider
aws_regions = []
for kw,reg in Provider.__dict__.iteritems():
if 'EC2' in kw and reg not in aws_regions:
aws_regions.append(reg)
print aws_regions
发布于 2017-02-20 09:57:50
我们可以使用libcloud API list_regions()
(Pdb) import libcloud
(Pdb) p libcloud.__version__
'1.5.0'
(Pdb) p driver.list_regions()
['ap-northeast-2', 'us-east-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-south-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-2', 'us-gov-west-1', 'us-west-1', 'eu-central-1', 'ap-northeast-1']
发布于 2019-02-12 17:47:25
我们可以在Provider.EC2
对象上使用get_driver()
函数。list_regions()
方法将为您提供连接到区域时要传递的可接受值的列表。list_regions
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
driver = get_driver(Provider.EC2)
driver.list_regions()
['ap-northeast-1', 'ap-northeast-2', 'ap-northeast-3', 'ap-south-1', 'ap-southeast-1', 'ap-southeast-2', 'ca-central-1', 'cn-north-1', 'cn-northwest-1', 'eu-central-1', 'eu-west-1', 'eu-west-2', 'eu-west-3', 'sa-east-1', 'us-east-1', 'us-east-2', 'us-gov-west-1', 'us-west-1', 'us-west-2']
https://stackoverflow.com/questions/31836211
复制相似问题