我想使用Python api创建一个Google Compute Engine实例。特别是,我希望源图像是Ubuntu 14.04。
在doc中,编写它来指定请求的json主体,如下所示:
{
"name": "example-instance",
"machineType": "zones/us-central1-f/machineTypes/f1-micro"
"networkInterfaces": [{
"accessConfigs": [{
"type": "ONE_TO_ONE_NAT",
"name": "External NAT"
}],
"network": "global/networks/default"
}],
"disks": [{
"autoDelete": "true",
"boot": "true",
"type": "PERSISTENT",
"initializeParams": {
"sourceImage": "projects/debian-cloud/global/images/v20150818"
}
}]
}
如何修改sourceImage
参数值,使其指向ubuntu 14.04图像?实际上,语法“projects / debian-cloud / global / images / v20150818”太具体,无法理解如何将其用于其他公共图像。
答案 0 :(得分:1)
我猜您指的是使用以下网址格式的these docs(source code):
"projects/debian-cloud/global/images/debian-7-wheezy-v20150320"
这里的模式是:
"projects/${PROJECT}/global/images/${IMAGE}"
您可以通过以下方式找到可用的图片:
$ gcloud compute images list
将显示类似于以下内容的输出:
NAME PROJECT ALIAS DEPRECATED STATUS
centos-6-v20151104 centos-cloud centos-6 READY
centos-7-v20151104 centos-cloud centos-7 READY
coreos-alpha-891-0-0-v20151211 coreos-cloud READY
coreos-beta-877-1-0-v20151202 coreos-cloud READY
coreos-stable-835-9-0-v20151208 coreos-cloud coreos READY
backports-debian-7-wheezy-v20151104 debian-cloud debian-7-backports READY
debian-7-wheezy-v20151104 debian-cloud debian-7 READY
debian-8-jessie-v20151104 debian-cloud debian-8 READY
container-vm-v20151103 google-containers container-vm READY
opensuse-13-1-v20150822 opensuse-cloud opensuse-13 READY
opensuse-13-2-v20150511 opensuse-cloud opensuse-13 READY
opensuse-leap-42-1-v20151124 opensuse-cloud READY
rhel-6-v20151104 rhel-cloud rhel-6 READY
rhel-7-v20151104 rhel-cloud rhel-7 READY
sles-11-sp4-v20150714 suse-cloud sles-11 READY
sles-12-sp1-v20151215 suse-cloud sles-12 READY
ubuntu-1204-precise-v20151119 ubuntu-os-cloud ubuntu-12-04 READY
ubuntu-1404-trusty-v20151113 ubuntu-os-cloud ubuntu-14-04 READY
ubuntu-1504-vivid-v20151120 ubuntu-os-cloud ubuntu-15-04 READY
ubuntu-1510-wily-v20151114 ubuntu-os-cloud READY
windows-server-2008-r2-dc-v20151006 windows-cloud windows-2008-r2 READY
windows-server-2012-r2-dc-v20151006 windows-cloud windows-2012-r2 READY
因此,对于Ubuntu 14.04,图像路径为:
"projects/ubuntu-os-cloud/global/images/ubuntu-1404-trusty-v20151113"
您还可以通过以下方式找到有关图像的更多元数据:
$ gcloud compute images describe --project ubuntu-os-cloud ubuntu-1404-trusty-20151113
并且输出中的selfLink
属性将提供图像的完整URL。