gpt4 book ai didi

python - 使用 Python API 创建 GCE 实例

转载 作者:行者123 更新时间:2023-12-04 19:17:08 24 4
gpt4 key购买 nike

我想使用 Python api 创建一个 Google Compute Engine 实例。特别是,我希望源图像是 Ubuntu 14.04。

在文档中,写到指定请求的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”过于具体,无法理解如何将其用于其他公共(public)镜像。

最佳答案

我猜你指的是these docs ( source code ) 使用以下 URL 格式:

"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。

关于python - 使用 Python API 创建 GCE 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34287290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com