[英]How do you create an instance using google-api-client?
When I run a python program it's as simple as writing into terminal python myprogram.py
.当我运行 python 程序时,它就像写入终端
python myprogram.py
一样简单。 Now, I'm trying to run that program on a google vm instance and shut it off with as few steps as possible.现在,我正在尝试在 google vm 实例上运行该程序,并以尽可能少的步骤将其关闭。 I'm trying to get it all written down in a python program, but I was told that my method of using the subprocess module is not the right way to do it.
我试图将其全部写在 python 程序中,但有人告诉我,我使用 subprocess 模块的方法不是正确的方法。 I was told that the best way to do it is to use the
googleapiclient
module.有人告诉我,最好的方法是使用
googleapiclient
模块。 So the current I use to create an instance is:所以我用来创建实例的电流是:
def create_instance(name='', machine_type=''):
name = 'kfoley76'
machine_type = 'n1-standard-1'
subprocess.run(['gcloud', 'compute', 'instances', 'create',
name, f'--machine-type={machine_type}',
'--zone=us-west2-a', '--boot-disk-auto-delete'])
How would I rewrite that using googleapiclient
module.我将如何使用
googleapiclient
模块重写它。 I assume the answer would be located here我认为答案将位于此处
https://cloud.google.com/compute/docs/reference/rest/v1/instances/start https://cloud.google.com/compute/docs/reference/rest/v1/instances/start
but that documentation is utterly incomprehensible.但该文件完全无法理解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.