Small project used mostly to have something to deploy to GCP. Will calculate availability for the day/week/month/year given an input of downtime.
The file availability_cloudfunction.py is ready to deploy to a cloud function The current version is used as http trigger function and will return json
Deploy by copying the file into GCP console in a new cloud function. Or deploy with the SDK on condition code is hosted on gcloud repositories (see doc)
gcloud function deploy <your function name> --region=<REGION> \
--trigger-http --runtime=python37 \
[--entry-point=<function to execute in the deployed file>] \
[--memory=<memory limit>] \
[--source=<https://source.developers.google.com/projects/PROJECT_ID/repos/REPOSITORY_ID/moveable-aliases/master/paths/SOURCE>]
See all the option
$ gcloud functions deploy --help
Use with this format:
curl 'https://gcloud-region-project-id.cloudfunctions.net/function_name?downtime=0d5h54m'
OR
curl -X POST -H "Content-Type: application/json" -d '{"downtime":"0d5h54m"}' 'https://gcloud-region-project-id.cloudfunctions.net/function_name'
Also possible to filter period :
curl 'https://gcloud-region-project-id.cloudfunctions.net/function_name?downtime=0d5h54m&period=monthly'
curl -X POST -H "Content-Type: application/json" -d '{"downtime":"0d5h54m", "period":"monthly"}' 'https://gcloud-region-project-id.cloudfunctions.net/function_name'
OR
The above will output
{"daily": 75.417, "weekly": 96.488, "monthly": 99.207, "yearly": 99.933}
Calculations are made on the current month and year.
gcloud app deploy app.yaml
File necessary for AppEngine:
- app.yaml
- main.py
- availability.py
- templates/*
app.yaml directs to the backend logic files.
Here main.py
is necessary to use that name for AppEngine.
See more Official Doc
Build the container from the Dockerfile
docker build -t availapp:latest .
Run it
docker run -d --name container_avail_1 -p 80:8000 availapp
Units are in the tests.py file
This project is licensed under the GNU GPLv3 License - see the LICENSE.md file for details