google-cloud-platform - 如何使用 gcp 附加本地 ssd 创建实例
问题描述
我尝试使用 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
但没有任何帮助。
我怎么了?
解决方案
使用GCP 官方文档创建具有本地 SSD 的实例,并参考 Google 的 API,我们可以查看以下内容:
除了上述信息之外,以下是一个示例请求有效负载,它创建了一个具有引导磁盘和本地 SSD 设备的实例:
与使用 Python Google 的 API 客户端的有效负载请求相比,您似乎没有指定每个磁盘的“类型”。API 要求本地 SSD 类型为“ SCRATCH ”,而可启动磁盘需要类型为“ PERSISTENT ”。尝试这样做,看看它是否有任何影响。
推荐阅读
- c# - 从左到右编号坐标和拉绳
- css - 如何使用 React 打印页眉和页脚
- c - 仅写入动态分配的内存块的一部分是否会设置整个块的有效类型?
- php - laravel ErrorException 未定义变量:(服务器更改后)
- linux - 如何让 CANbus 在 beaglebone green 上工作
- bash - Dockerfile RUN 命令是否在登录 shell 环境中运行?
- node.js - 更新 mongodb 中数组对象数组的嵌入文档
- python - 将多个 json 对象放入一个列表中
- javascript - 从函数内的数组中获取随机元素
- sql-server - 如何使用 azure 流分析根据输出/blob 存储中的数据仅插入不同的行?