SharonTools

Google Cloud automation using python

First steps i made in Google cloud automation

Google offers 1 year free trail (Up to 300$) for using Google Cloud Platform (GCP)
In this script i created a new virtual machine via python script

I used Ubuntu linux to run the script,

_

1. Enable Google compute API

go to – https://console.developers.google.com/apis/library/compute.googleapis.com

_

2. Create a new project

Click the small arrow at the top (near Google APIs) and choose ‘New Project’ and give the new project a name (Project1 in my case)

_

3. Create service account

this account will use to connect to the cloud via the API script, go to https://console.developers.google.com/iam-admin/serviceaccounts

and click ‘Create service account’

_

Set the new account name (in my case – ServiceAcc1)

_

Select the role of the new account (in my case – Owner)

Click ‘Continue’ , Click ‘Finish’

_

4. Create Key

Choose Action -> Create key and Choose ‘JSON’ key type and click ‘Create’

A new file will be download automatically , the file name will be somthing like – “project1-12345-2sfdgs9e35522.json”

_

5. Install Python Cloud library

SSH to the linux machine that will run the Python script and install apache-libcloud python library

_

6. Copy the JSON file the the Linux machine

Via FTP/SCP or copy the file content and paste to a new file via VI,

For example (Using Copy/Paste):

vim project1-12345-2sfdgs9e35522.json

Paste the data from the file you downloaded

Save the file and exit ( [ESC] & :wq )

_

7. Create the Python script

vim test.py

Update this parameters:

1 your service account email (You can found this inside the JSON file)
2 path to JSON file (The JSON file you downloaded)
3 your project id (You can found this inside the JSON file)

_

8. Run the script

Attention– This script will create a new VM, This can cost money $$$ in case you not eligible for free use

And after few seconds you have the new VM ‘node-web1’ running at Google Cloud, Don’t forget to delete it later 🙂

_

Summary

Google cloud automation is friendly and easy to use for python users

_

_

Exit mobile version