简体   繁体   English

如何使用 google-api-client 创建实例?

[英]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.但该文件完全无法理解。

Please see the tutorial I mentioned in my answer to your other question.请参阅我在回答您的其他问题时提到的教程 I'm confident it will get you exactly what you need.我相信它会为您提供您所需要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pip 如何在 Virtual Studio Code 中安装 Google-API-Client? - How to pip install Google-API-Client in Virtual Studio Code? 使用 google-api-client 在 memory 中存储的烧瓶/python 中使用可恢复上传将大文件从客户端上传到 GDrive - Upload large File from client to GDrive using google-api-client using resumable upload in flask/python storing in memory 如何使用Twisted Words Python库创建简单的Google Talk客户端? - How do you create a simple Google Talk Client using the Twisted Words Python library? 如何在 Python 中使用 function 创建 class 的实例? - How do you create an instance of a class using a function in Python? 如何使用Google API客户端创建Python代码 - How to Create Python Code with Google API Client 如何检查 MongoDB 实例的客户端是否有效? - How do you check if the client for a MongoDB instance is valid? Google Cloud Storage API:如何使用存储类别和位置选项调用`create_bucket()`? - Google Cloud Storage API: How do you call `create_bucket()` with storage class and location options? 使用Google Analytics(分析)API及其客户端google-api-python-client创建一个Web应用程序? - create a web application using google analytics api and its client google-api-python-client? 如何使用bigquery_datatransfer Python客户端创建AdWords BigQuery传输和传输运行? - How do you create a Adwords BigQuery Transfer and Transfer Runs using the bigquery_datatransfer Python client? 第一步如何使用 Python API 客户端在 google cloud 上创建项目 - How can take the first step create a project on google cloud using Python API client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM