forked from x4nth055/pythoncode-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added automating server management tutorial
- Loading branch information
Showing
4 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests |