1

Google の Web サイトにある次のガイドを複製しようとしました 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()
4

2 に答える 2