我想通过实例模板机制从我的自定义映像创建一个VM。我可以看到实例模板是可用的。下面是我的配置:
config = {
'name': name,
'machineType': machine_type,
# Specify the boot disk and the image to use as a source.
'disks': [
{
'boot': True,
'autoDelete': True,
'initializeParams': {
'sourceImage': source_disk_image,
}
}
],
# Specify a network interface with NAT to access the public
# internet.
'networkInterfaces': [{
'network': 'global/networks/default',
'accessConfigs': [
{'type': 'ONE_TO_ONE_NAT', 'name': 'External NAT'}
]
}],
# Allow the instance to access cloud storage and logging.
'serviceAccounts': [{
'email': 'default',
'scopes': [
'https://www.googleapis.com/auth/devstorage.read_write',
'https://www.googleapis.com/auth/logging.write'
]
}],
# Metadata is readable from the instance and allows you to
# pass configuration from deployment scripts to instances.
'metadata': {
'items': [{
# Startup script is automatically executed by the
# instance upon startup.
'key': 'startup-script',
'value': startup_script,
'VIDEOPATH': videopath,
'uuid': uuid
}]
}
}如何通过实例模板使用python api创建VM实例?
compute.instances().insert(
project=project,
zone=zone,
body=config).execute()发布于 2020-05-29 02:53:25
下面的项应该添加到json中,包括设备名称和sourceImage,Google Compute实例将从特定的图像创建。
# Specify the boot disk and the image to use as a source.
"disks": [
{
"kind": "compute#attachedDisk",
"type": "PERSISTENT",
"boot": True,
"mode": "READ_WRITE",
"autoDelete": True,
"deviceName": "instance-template-1",
"initializeParams": {
"sourceImage": "projects/supereye/global/images/image-1",
"diskType": "projects/supereye/zones/europe-west2-b/diskTypes/pd-standard",
"diskSizeGb": "10"
}, "diskEncryptionKey": {}
}
],https://stackoverflow.com/questions/62005025
复制相似问题