From f9385381ef2a0ff86cc72a8b173c267bf2b8cee8 Mon Sep 17 00:00:00 2001 From: x4nth055 Date: Wed, 6 Nov 2019 11:05:25 +0100 Subject: [PATCH] added automating server management tutorial --- README.md | 1 + .../automating-server-management/README.md | 5 +++ .../automating-server-management/automate.py | 35 +++++++++++++++++++ .../requirements.txt | 1 + 4 files changed, 42 insertions(+) create mode 100644 general/automating-server-management/README.md create mode 100644 general/automating-server-management/automate.py create mode 100644 general/automating-server-management/requirements.txt diff --git a/README.md b/README.md index 836a034c..a32cc896 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy - [How to Compress and Decompress Files in Python](https://www.thepythoncode.com/article/compress-decompress-files-tarfile-python). ([code](general/compressing-files)) - [How to Extract PDF Tables in Python](https://www.thepythoncode.com/article/extract-pdf-tables-in-python-camelot). ([code](general/pdf-table-extractor)) - [How to Use Pickle for Object Serialization in Python](https://www.thepythoncode.com/article/object-serialization-saving-and-loading-objects-using-pickle-python). ([code](general/object-serialization)) + - [How to Automate your VPS or Dedicated Server Management in Python](https://www.thepythoncode.com/article/automate-veesp-server-management-in-python). ([code](general/automating-server-management)) - ### [Web Scraping](https://www.thepythoncode.com/topic/web-scraping) - [How to Access Wikipedia in Python](https://www.thepythoncode.com/article/access-wikipedia-python). ([code](web-scraping/wikipedia-extractor)) diff --git a/general/automating-server-management/README.md b/general/automating-server-management/README.md new file mode 100644 index 00000000..856466e7 --- /dev/null +++ b/general/automating-server-management/README.md @@ -0,0 +1,5 @@ +# [How to Automate your VPS or Dedicated Server Management in Python](https://www.thepythoncode.com/article/automate-veesp-server-management-in-python) +To run this: +- `pip3 install -r requirements.txt` +- Edit `automate.py` and run the code line by line. +- This tutorial introduces you to web APIs, feel free to make your own scripts of your own needs. \ No newline at end of file diff --git a/general/automating-server-management/automate.py b/general/automating-server-management/automate.py new file mode 100644 index 00000000..012b7a34 --- /dev/null +++ b/general/automating-server-management/automate.py @@ -0,0 +1,35 @@ +import requests +from pprint import pprint + +# email and password +auth = ("email@example.com", "ffffffff") + +# get the HTTP Response +res = requests.get("https://secure.veesp.com/api/details", auth=auth) + +# get the account details +account_details = res.json() + +pprint(account_details) + +# get the bought services +services = requests.get('https://secure.veesp.com/api/service', auth=auth).json() +pprint(services) + +# get the upgrade options +upgrade_options = requests.get('https://secure.veesp.com/api/service/32723/upgrade', auth=auth).json() +pprint(upgrade_options) + +# list all bought VMs +all_vms = requests.get("https://secure.veesp.com/api/service/32723/vms", auth=auth).json() +pprint(all_vms) + +# stop a VM automatically +stopped = requests.post("https://secure.veesp.com/api/service/32723/vms/18867/stop", auth=auth).json() +print(stopped) +# {'status': True} + +# start it again +started = requests.post("https://secure.veesp.com/api/service/32723/vms/18867/start", auth=auth).json() +print(started) +# {'status': True} \ No newline at end of file diff --git a/general/automating-server-management/requirements.txt b/general/automating-server-management/requirements.txt new file mode 100644 index 00000000..663bd1f6 --- /dev/null +++ b/general/automating-server-management/requirements.txt @@ -0,0 +1 @@ +requests \ No newline at end of file