0

When I run a python program it's as simple as writing into terminal python myprogram.py. Now, I'm trying to run that program on a google vm instance and shut it off with as few steps as possible. I'm trying to get it all written down in a python program, but I was told that my method of using the subprocess module is not the right way to do it. I was told that the best way to do it is to use the googleapiclient module. So the current I use to create an instance is:

def create_instance(name='', machine_type=''):
    name = 'kfoley76'
    machine_type = 'n1-standard-1'

    subprocess.run(['gcloud', 'compute', 'instances', 'create',
                     name, f'--machine-type={machine_type}',
                     '--zone=us-west2-a', '--boot-disk-auto-delete'])

How would I rewrite that using googleapiclient module. I assume the answer would be located here

https://cloud.google.com/compute/docs/reference/rest/v1/instances/start

but that documentation is utterly incomprehensible.

1

1 Answer 1

1

Please see the tutorial I mentioned in my answer to your other question. I'm confident it will get you exactly what you need.

Sign up to request clarification or add additional context in comments.

2 Comments

In the following code: def create_instance(compute, project, zone, name, bucket): image_response = compute.images().getFromFamily( project='debian-cloud', family='debian-9').execute() source_disk_image = image_response['selfLink'] it's not clear what type of object compute is.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.