【发布时间】:2020-08-11 08:20:18
【问题描述】:
我尝试使用 python googleapiclient 创建一个带有启动盘和本地 ssd 盘的实例。 这是构建系统的 gcp 映像,我想要更好的性能
def create_instance(compute, image_name):
image_response = compute.images().get(project=GCP_PROJECT_ID,
image=GCP_IMAGE_NAME).execute()
source_disk_image = image_response['selfLink']
machine_type = f"zones/{GCP_ZONE}/machineTypes/n2-standard-4"
config = {
'name': image_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,
}
},
{
'boot': False,
'autoDelete': True,
'initializeParams': {
'disk_type': 'local-ssd'
}
}
],
# 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/cloud-platform"
]
}]
}
operation = compute.instances().insert(
project=GCP_PROJECT_ID,
zone=GCP_ZONE,
body=config).execute()
return operation
作为。很难我尝试给不同的 initializeParams diskTypes 它总是为我创建一个标准的持久 500GB 磁盘而不是本地 ssd。我已经试过了:
- 本地-ssd
- https://www.googleapis.com/compute/v1/projects/project/zones/zone/diskTypes/local-ssd
- https://www.googleapis.com/compute/v1/projects/project/zones/us-central1-a/diskTypes/local-ssd
但没有任何帮助。
我做错了什么?
【问题讨论】: