【发布时间】:2020-01-07 09:21:48
【问题描述】:
我想使用google-api-client 通过 SSH 连接到 GCE VM 实例。我可以使用google-api-client 使用以下代码启动一个实例:
from googleapiclient import discovery
from oauth2client.client import GoogleCredentials
credentials = GoogleCredentials.get_application_default()
service = discovery.build('compute', 'v1', credentials=credentials)
project = 'my_project'
zone = 'us-west2-a'
instance = 'my_instance'
request = service.instances().start(project=project, zone=zone, instance=instance)
response = request.execute()
在命令行中,上面的代码呈现为:
gcloud compute instances start my_instance
类似地,使用 SSH 连接到 GCE VM 实例的命令行如下:
gcloud init && gcloud compute ssh my_instance --project my_project --verbosity=debug --zone=us-west2-a
我已经设置了 SSH 密钥等等。
我想知道如何在 Google Api Client 或 Python 中编写上述命令行。
【问题讨论】:
标签: ssh google-cloud-platform google-compute-engine gcloud google-api-client