[英]Is there any equivalent in terraform to the gcloud compute instances create-with-container command?
[英]Can I replicate `create-with-container` gcloud sdk command using the googleapiclient python client
我目前在 gcloud 容器存儲庫上有一個 docker 容器,我想啟動一個實例以運行計算、保存結果並關閉:
gcloud compute instances create-with-container test-1 \
--machine-type=n1-standard-4 \
--boot-disk-size=20GB \
--container-image=eu.gcr.io/<container-link> \
--container-env=GCLOUD_INPUT_FILENAME=file.txt \
--container-env=GCLOUD_PROJECT=project-name
但是,我希望能夠使用網絡界面(flask)啟動這些實例,這意味着我想使用googleapiclient (python)來創建和管理這些實例:
看起來您可以使用發現 API 創建實例創建順序:
compute = googleclientapi.discovery.build('compute', 'v1')
compute.instances().insert(...).execute()
但看起來似乎無法模擬create-with-container
gcloud sdk 命令,盡管您可以將“machineImage”作為創建請求的一部分傳遞。
可以在不使用subprocess
進程調用 gcloud sdk 的情況下創建一個計算實例“with-container”
或者
我可以將create-with-container
實例轉換為機器映像,然后使用googleapi client
嗎?
僅供參考,我從 log-http 日志中發現的內容(我知道這不是正確答案)
==== request start ====
uri: https://compute.googleapis.com/batch/compute/v1
method: POST
== headers start ==
b'authorization': --- Token Redacted ---
b'content-length': b'479'
b'content-type': b'multipart/mixed; boundary="===============34234234234234=="'
b'user-agent': b'google-cloud-sdk gcloud/329.0.0 command/gcloud.compute.instances.create-with-container invocation-id/0dd6a37ac0624ac4b00e30a44da environment/devshell environment-version/None interactive/False from-script/False python/3.7.3 term/screen (Linux 5.4.89+)'
== headers end ==
“create-with-container”是通過標題傳遞的,我沒有找到相同的正文。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.