The given python script does below tasks:
- Create a Instance
- Delete a Instance
- Get Healtcheck of created instance
- Get available Methods
User can update the python file to get more flexibility with instance creation.
- You should have python version 3 installed.
- Python modules are "google-api-python-client" And "flask"
Use: pip3 install
In Amazon Linux below commands can be used:
pip3 install --upgrade google-api-python-client
pip3 install flask
-
Create a Project in Google Cloud
-
Get API keys from google cloud dashboard:
APIs & Services > Credentials > Create Credentials > Service Account Keys > Save the json file
-
Export the downloaded json key file:
export GOOGLE_APPLICATION_CREDENTIALS=/path_to_keys/key.json
-
Clone/download this project and update the input.txt file:
project=your_project_id
zone=zone_for_gce
instance_name=instance_name_of_your_choice
Example:
project=analog-bay-13434324
zone=us-east1-c
instance_name=Test-instance
- Run the application file:
python3 simple_python_app.py
- To get the available methods:
http://localhost:5000/
- To create the instance:
curl -H "Content-Type: application/json" -X POST -d '{"username":"Your_User", "password": "Your_passowrd"}' http://localhost:5000/v1/instances/create
- To get healthcheck:
curl http://localhost:5000/healthcheck
- To delete the instance:
curl -X DELETE http://localhost:5000/v1/delete_instance
User can also use postman instead of curl commands.
###Additional info:
- The python application runs on localhost at port 5000. User can also use IP of localhost.
- /healthcheck gives a 200 OK response and no other output.
- If Instance is down /healthcheck will give you error 404
- To login to the instance use the username and password provided during the create instance call.