指定磁盘类型时,无法使用python代码创建磁盘



我正在使用python3创建磁盘。在尝试创建磁盘时,我正在使用下面的body配置。如果我不使用";类型":"pd标准";或";类型":"pd ssd":

config = {
"name": "mytestdisk",
"description": "this disk is created using python code",
"sizeGb": '1',
"type": "pd-standard",
"zone": zone
}

但是当使用";类型":"pd标准";或";类型":"pd ssd";我得到以下错误:

Traceback (most recent call last):
File "C:/Users/myuser/PycharmProjects/pythonProject/cretedisk.py", line 31, in <module>
print(create_disk(compute, project, zone))
File "C:/Users/myuser/PycharmProjects/pythonProject/cretedisk.py", line 24, in create_disk
return compute.disks().insert(
File "C:UsersmyuserPycharmProjectspythonProjectvenvlibsite-packagesgoogleapiclient_helpers.py", line 134, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:UsersmyuserPycharmProjectspythonProjectvenvlibsite-packagesgoogleapiclienthttp.py", line 907, in execute
raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://compute.googleapis.com/compute/v1/projects/superman/zones/us-central1-a/disks?alt=json returned "Invalid value for field 'resource.type': 'pd-standard'. The URL is malformed.">

url应该是

'type': 'https://www.googleapis.com/compute/v1/projects/superman/zones/us-central1-a/diskTypes/pd-standard',
'type': 'https://www.googleapis.com/compute/v1/projects/superman/zones/us-central1-a/diskTypes/pd-ssd'

我不确定为什么它正在尝试不正确的网址:

https://compute.googleapis.com/compute/v1/projects/superman/zones/us-central1-a/disks

在我看来,图书馆里好像有个bug。有没有人尝试过并面临过这样的问题,或者有解决这个错误的方法?

感谢

来源https://cloud.google.com/compute/docs/reference/rest/v1/disks,type字段显示:

磁盘类型资源的URL,描述用于创建磁盘的磁盘类型。在创建磁盘时提供此选项。例如:projects/<project>/zones/<zone>/diskTypes/pd-standard

我想你想要type的完整URL,而不仅仅是pd-standard,所以:

https://www.googleapis.com/compute/v1/projects/superman/zones/us-central1-a/diskTypes/pd-standard

最新更新