Skip to content

Commit

Permalink
added automating server management tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
x4nth055 committed Nov 6, 2019
1 parent ea081e7 commit f938538
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions general/automating-server-management/README.md
Original file line number Diff line number Diff line change
@@ -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.
35 changes: 35 additions & 0 deletions general/automating-server-management/automate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import requests
from pprint import pprint

# email and password
auth = ("[email protected]", "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}
1 change: 1 addition & 0 deletions general/automating-server-management/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests

0 comments on commit f938538

Please sign in to comment.