0

有没有办法通过 libcloud 获取 AWS 上所有可用区域的列表?

使用 powershell AWS SDK 我可以使用:

$regions = @(Get-AWSRegion)
foreach ($region in $regions)
{
$region.Region
}

我怎样才能对 Python 和 libcloud 做同样的事情?

非常感谢,约翰尼

4

3 回答 3

1

尝试这个。获取 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
于 2015-08-05T19:59:40.043 回答
0

我们可以使用 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']
于 2017-02-20T09:57:50.003 回答
0

我们可以在对象上使用该get_driver()函数。Provider.EC2list_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']
于 2019-02-12T17:47:24.587 回答