【发布时间】:2020-11-24 21:50:00
【问题描述】:
下面有人分享的代码(Starting a Google Compute instance with Python),我做了一些修改,它非常适合我启动一个虚拟机。我想知道是否可以调整此代码以在同一函数中启动多个实例? 这是代码:
from googleapiclient import discovery
service = discovery.build('compute', 'v1')
def autostart_vm(request):
# Project ID for this request.
project = 'secret-metrics-278618'
# The name of the zone for this request.
zone = 'us-central1-a'
# Name of the instance resource to start.
instance = 'devops1'
instance2 = 'devops-2'
request = service.instances().start(project=project, zone=zone, instance=instance)
response = request.execute()
print('VM Instance started')
【问题讨论】:
-
您不需要将
request作为参数传递给您的函数以使其工作。
标签: python google-cloud-functions multiple-instances