Python Client for Digital Ocean Droplets
Project description
pydrop: Minimal Python Client for Digital Ocean Droplets
This is a minimal tool designed to interact with the Digital Ocean API. This does not translate all functionalities of the API but is a template I created for some of the most common operations I could perform. New tools will be added in the future as I familiarize myself further with the API structure and use as a student. For now this tool allows you to summarize all your droplets running, including and necessarily a price summary to keep tabs on your droplets monthly and hourly rates. The tool also allows you to seach by tags, delete a drop or perfrom actions such as start, stop or shutdown a droplet.
Table of contents
Installation
This assumes that you have native python & pip installed in your system, you can test this by going to the terminal (or windows command prompt) and trying
python
and then pip list
If you get no errors and you have python 2.7.14 or higher you should be good to go. Please note that I have tested this only on python 2.7.15 but can be easily modified for python 3.
To install Python CLI for Digital Ocean you can install using two methods
pip install pydrop
or you can also try
git clone https://github.com/samapriya/pydrop.git
cd pydrop
python setup.py install
For linux use sudo.
Installation is an optional step; the application can be also run directly by executing pydrop.py script. The advantage of having it installed is being able to execute ppipe as any command line tool. I recommend installation within virtual environment. If you don't want to install, browse into the pydrop folder and try python pydrop.py
to get to the same result.
Getting started
As usual, to print help:
usage: pydrop [-h]
{dokey,accinfo,dropinfo,volinfo,snapinfo,sshread,sshpost,sshdelete,dropaction,dropdelete,dropreset}
...
Digital Ocean API Python CLI
positional arguments:
{dokey,accinfo,dropinfo,volinfo,snapinfo,sshread,sshpost,sshdelete,dropaction,dropdelete,dropreset}
dokey Enter your Digital Ocean API Key
accinfo Prints your account info
dropinfo Prints information about all your droplets
volinfo Prints information about all your volumes
snapinfo Prints information about all your snapshots
sshread Prints information about your ssh keys
sshpost Adds new ssh keys to account
sshdelete Deletes a ssh keys from account
dropaction Performs an action on your droplets
dropdelete Permanently deletes the droplet
dropreset Resets password for the droplet
optional arguments:
-h, --help show this help message and exit
To obtain help for a specific functionality, simply call it with help switch, e.g.: pydrop dropinfo -h
. If you didn't install pydrop, then you can run it just by going to pydrop directory and running python pydrop.py [arguments go here]
Digital Ocean Python CLI Tools
The Digital Ocean Python CLI and tools setup contains minimal CLI in python to perform basic actions on droplets along with query and analyze your DO enviroment quickly.
Digital Ocean Key
This tool basically asks you to input your Digital Ocean API Key using a password prompt this is then used for all subsequent tools. This tool now includes an option for a quiet authentication using the API key incase it is unable to invoke an interactive environment such as in Google colaboratory.
usage: pydrop dokey [-h] [--key KEY]
optional arguments:
-h, --help show this help message and exit
Optional named arguments:
--key KEY Your Digital Ocean API Key
If using on a private machine the Key is saved as a csv file for all future runs of the tool.
Droplets Info
This tool prints account info about your account including, droplet and volume limit, your email, and so on. The setup would be
pydrop accinfo
Droplets Info
The droplets info tool prints summary info about all your droplets. You can choose to narrow it down further using a droplet tag so only those droplets with speific tags will be printed. Since I wanted the ability of including price summaries, I have included prices summaries.
usage: pydrop dropinfo [-h] [--tag TAG]
optional arguments:
-h, --help show this help message and exit
Optional named arguments:
--tag TAG Use a tag to refine your search
Volume Info
As the name suggest incase you have any volumes attched, this will print information about the volumes attached. If no volumes exists, it will print that and exit out. The setup would be
pydrop volinfo
Snapshot Info
This will print information about any existing snapshot that you might have. Setup again is
pydrop snapinfo
ssh read
This setup will simply read all your ssh keys and print them including the key, the id , name and so on. Setup would be
pydrop sshread
ssh post
This will allow you to add a new ssh key to your existing ssh keys. The required inputs are name and the key
usage: pydrop sshpost [-h] --name NAME --keyfile KEYFILE
optional arguments:
-h, --help show this help message and exit
Required named arguments.:
--name NAME name for ssh key
--keyfile KEYFILE file with ssh key
ssh delete
This will delete an ssh key, if no key id is provided, the tool first prints out all the ssh keys and their ids to choose from. Setup with a keyid would be simply
pydrop sshdelete
The above command will essentially call a sshread function to get you the key ids. If you know the key id the command then takes that as an input
usage: pydrop sshdelete [-h] [--keyid KEYID]
optional arguments:
-h, --help show this help message and exit
Optional named arguments:
--keyid KEYID ssh key id
Droplets Delete
This deletes a droplet and you can specify either the droplet name or id. Incase you don't remember the name or id, just run the tool without any arguments and it will list out all droplet id(s) and names.
usage: pydrop dropdelete [-h] [--id ID] [--name NAME]
optional arguments:
-h, --help show this help message and exit
Optional named arguments:
--id ID Use an image ID to delete droplet
--name NAME Use an image name to delete droplet
Droplets Reset
This resets the password of a droplet and you can specify either the droplet name or id. Incase you don't remember the name or id, just run the tool without any arguments and it will list out all droplet id(s) and names.
usage: pydrop dropreset [-h] [--id ID] [--name NAME]
optional arguments:
-h, --help show this help message and exit
Optional named arguments:
--id ID Use an image ID to delete droplet
--name NAME Use an image name to delete droplet
Droplets Action
The droplet action tool was designed to achieve and have more control over individual droplet actions and I included actions such as shutdown, power off, power on and rename. Just like the droplet delete tool, this tool will print the name and id of all droplets if no arguments are passed and you can then choose the one on which to perform the action.
usage: pydrop dropaction [-h] [--id ID] [--name NAME] [--action ACTION]
[--rename RENAME]
optional arguments:
-h, --help show this help message and exit
Optional named arguments:
--id ID Use an image ID to perform action
--name NAME Use an image name to perform action
--action ACTION Action type |shutdown="graceful shutdown"|power_off="hard
shutdown"|power_on="power on"|rename="rename
--rename RENAME Incase you are renaming droplet you can provide new name
Changelog
v0.0.6
- Fixed action tool for id
- Added reboot and snapshot actions.
v0.0.5
- Added additional tools like sshfunctions, volume and snapshot reads
- General improvements to overall tool
v0.0.4
- Now calculates total cost till date based on active droplets
v0.0.3
- Now checks for keys and auto initializes if missing
- Includes password reset tool
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pydrop-0.0.6.tar.gz
.
File metadata
- Download URL: pydrop-0.0.6.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.32.1 CPython/2.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee6a0f3cd49e1111dbd4de59d2f69cb25d14ade334b677ad3df7214747842e10 |
|
MD5 | 530cf5456214f91b3bcb9d039b46fee1 |
|
BLAKE2b-256 | e36221ec350bd384516703c3d741e1c14b4d4eab3373cd33e0470e8f50021d17 |
File details
Details for the file pydrop-0.0.6-py2.py3-none-any.whl
.
File metadata
- Download URL: pydrop-0.0.6-py2.py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.32.1 CPython/2.7.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5644ce22930fbed28f6d2fd4cd230c6a8a457e624994b53e369a0311b95cb1d0 |
|
MD5 | 98d503504d8741e350eb2fc11466243e |
|
BLAKE2b-256 | 3bb09fcb3660b53ecb5c664f3494551a2b30b0ec2c36eb50dadf77fb2a56af42 |