Account creation

As a HEPIA student enrolled in the Cloud & Deployment module, you have a credit of 50 US$ (in the form of coupon) from Google Cloud Higher education Program.

Here is the URL you will need to access in order to request a Google Cloud Platform coupon. You will be asked to provide your school email address (select the @etu.hesge.ch domain) and name. Before receiving the coupon, you will receive an Email to confirm these details.

For further information on how to use the coupon you received, read this URL.

Create a project

Please read this URL.

Create an instance using the GCE Web portal

The following tutorial will guide you through the creation of your first instance.

Note: This tutorial aims to start a Windows instance. To start a linux instance (ubuntu, debian,...) choose a linux image in step 5

https://cloud.google.com/compute/docs/instances/create-start-instance?hl=fr#publicimage

Setting up a local dev environment

Manual installation.

  1. Install Google Cloud SDK

    https://cloud.google.com/sdk/install?hl=fr

  2. Initialize Google Cloud SDK using the following command and follow on screen instructions

    Note: When asked to login type enter "y", choose the project you just created. When asked to configure a default Compute Region and Zone, enter "n"

    gcloud init
  3. Install Google api python client

    pip install --upgrade google-api-python-client
  4. Run the following command and follow on screen instruction to setup your account as the default account for the Google api python client

    gcloud auth application-default login

Resources and code examples

INSTANCE CREATION

    # Get the latest Debian Jessie image.
    image_response = compute.images().getFromFamily(
        project='debian-cloud', family='debian-9').execute()
    source_disk_image = image_response['selfLink']

    # Configure the machine
    machine_type = "zones/%s/machineTypes/n1-standard-1" % zone
    startup_script = open(
        os.path.join(
            os.path.dirname(__file__), 'startup-script.sh'), 'r').read()

     config = {
        'name': name,
        'machineType': machine_type,
... }

     compute.instances().insert(
        project=project,
        zone=zone,
        body=config).execute()
GET THE STATUS OF AN INSTANCE
    instances = list_instances(compute, project, zone)

    print('Instances in project %s and zone %s:' % (project, zone))
    for instance in instances:
        print(' - ' + instance['name'])

INSTANCE DELETION
    compute.instances().delete(
        project=project,
        zone=zone,
        instance=name).execute()
Storage
Upload file
    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)
    blob = bucket.blob(destination_blob_name)

    blob.upload_from_filename(source_file_name)

For more details, view this link

Download file
    storage_client = storage.Client()
    bucket = storage_client.bucket(bucket_name)

blob = bucket.blob(source_blob_name) blob.download_to_filename(destination_file_name)

For more details, view this link


MORE INFORMATION

Google Compute Engine API documentation:

https://developers.google.com/resources/api-libraries/documentation/compute/v1/python/latest/index.html

https://developers.google.com/resources/api-libraries/documentation/compute/v1/python/latest/compute_v1.instances.html

Provision instance

The following tutorial explains how to deploy an instance using the Google Cloud Client Libraries for Python

https://cloud.google.com/compute/docs/tutorials/python-guide?hl=fr

If you have any questions, please send an Email to Raoul(dot)Dupuis(at)hesge(dot)ch

Modifié le: mardi 26 septembre 2023, 14:57