我试图复制谷歌网站 https://cloud.google.com/compute/docs/tutorials/python-guide上的以下指南
我无法弄清楚存储桶和计算的含义。我需要将什么样的参数传递给脚本?如果我想启动我的私有映像,我应该在 getFromFamily(project='debian-cloud', family='debian-8').execute() 中放入什么?我是否像下面这样传递变量?
create_instance(compute,projectname, us-east1-a, instance-1, bucket)
我已将脚本简化如下。我取出了我认为不需要的参数。
def create_instance(compute, project, zone, name, bucket):
image_response = compute.images().getFromFamily(
project='debian-cloud', family='debian-8').execute()
source_disk_image = image_response['selfLink']
# Configure the machine
machine_type = "us-east1-b/%s/machineTypes/f1-micro" % zone
startup_script = open(
os.path.join(
os.path.dirname(__file__), 'startup-script.sh'), 'r').read()
config = {
'name': instance-1,
'machineType': f1-micro,
# Specify the boot disk and the image to use as a source.
'disks': [
{
'boot': True,
'autoDelete': True,
'initializeParams': {
'sourceImage': /global/imagename,
}
}
],
# Specify a network interface with NAT to access the public
# internet.
'networkInterfaces': [{
'network': 'global/networks/default',
'accessConfigs': [
{'type': 'ONE_TO_ONE_NAT', 'name': 'External NAT'}
]
}],
# Allow the instance to access cloud storage and logging.
'serviceAccounts': [{
'email': 'default',
'scopes': [
'https://www.googleapis.com/auth/devstorage.read_write',
]
}],
# Metadata is readable from the instance and allows you to
# pass configuration from deployment scripts to instances.
'metadata': {
'items': [{
# Startup script is automatically executed by the
# instance upon startup.
'key': 'startup-script',
'value': startup_script
}, {
'key': 'bucket',
'value': bucket
}]
}
}
return compute.instances().insert(
project=project,
zone=zone,
body=config).execute()