Code Monkey home page Code Monkey logo

pontoon's Introduction

pontoon

A Python CLI (and library) for Digital Ocean.

No Maintenance Intended

Note: This Project is No Longer Maintained

Code and any binaries will remain available.

Consider using the official Digital Ocean CLI tool instead.

Linux CI Windows CI Code Coverage Docs
Build Status on Linux Build status on Windows Coverage Status Documentation Status

Introduction

Pontoon makes interacting with Digital Ocean on the command line smooth sailing.

It is designed for human consumption, and aims to have good defaults.

Caveats

Pontoon has one rule it imposes on top of Digital Ocean:

Names are unique.

Unique names make for a much easier command line experience. For Droplets, names are hostnames, and hostnames should be unique anyway; it's just a good idea.

They don't have to be unique forever though; once a Droplet is destroyed, it's fine to use the name again.

Anything "recommended" (like secure-erasing the drive on termination) is optional, but enabled by default.

Installation

Install via pip:

$ pip install pontoon

To install the latest (development, unstable) release:

$ pip install https://github.com/duggan/pontoon/archive/master.zip

If you'd like to package pontoon for your favourite OS, feel free to do so (and please send a PR to this README!)

More options are on the way.

CLI Usage

Configure

Set up your credentials and preferences:

$ pontoon configure

You'll be prompted for your Digital Ocean API credentials (available here), and whether you want to use existing SSH credentials or for them to be generated (using OpenSSH).

The rest are preferences, and can be set at any time by running configure again, editing the ~/.pontoon config file (YAML format), or by specifying them with options on the command line.

Create your first Droplet!

Now you can create your first droplet:

$ pontoon droplet create foobar
Creating Droplet foobar (512MB using Ubuntu 12.04 x64 in Amsterdam 1)...
.......active

SSH into your Droplet

If everything's configured correctly, you should be able to SSH into your Droplet like so:

$ pontoon droplet ssh foobar
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-virtual x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Fri May  3 18:23:56 2013
root@foobar:~#

List your Droplets

$ pontoon droplet list
foobar:         (512MB, Ubuntu 12.04 x64, Amsterdam 1, 192.0.2.128, active)

or for more detail:

$ pontoon droplet list --detail
foobar
   id:                  998
   name:                foobar
   size:                512MB
   image:               Ubuntu 12.04 x64
   region:              Amsterdam 1
   status:              active
   locked:              False
   private_ip_address:  None
   created_at:          2013-11-09T13:22:40Z
   backups_active:      False
   ip_address:          192.0.2.128

Library

Pontoon bundles a modified fork of python-digitalocean, which can be imported and used as pontoon.lib. The main difference the fork introduces is a system for interacting with mock API responses from DigitalOcean for more thorough testing.

Contributing

Pull requests for bugs are always welcome! New functionality should generally be preceded by a discussion, though if you've written something that you needed and want to contribute back, a pull request is a fine way to start that discussion 🎉

All of the code in pontoon is PEP-8 audited (using pytest-pep8), and there's a full suite of tests written for py.test (library code) and Bats (interface). Contributions should, therefore, include tests and pass a PEP-8 audit.

Running the tests

Tests are run via Tox.

For example, to test the library, CLI and coverage for Python 2.7, run:

$ pip install tox
$ tox -e py27,lib,cli,coverage

The .travis.yml file in this repository enumerates all the tests that are performed.

The CLI tests require BATS, and PEP8 checks are performed in both the lib tests and cli tests.

On OSX, bats can be installed with homebrew:

$ brew install bats

On Debian/Ubuntu, I've set up a PPA for easy installation of bats:

$ add-apt-repository ppa:duggan/bats
$ apt-get update
$ apt-get install bats

The main project is MIT licensed, and the bundled library inherits LGPLv3.

Debugging

Set the DEBUG environment variable (to anything) to enable debug output for pontoon.

This will give a step through of most methods being executed during a command, like so:

$ DEBUG=1 pontoon droplet destroy foobar
2013-11-09 18:37:06,187 [pontoon.configure:DEBUG] combined: (){}
2013-11-09 18:37:06,187 [pontoon.configure:DEBUG] read_config: (){}
Destroying foobar and scrubbing data...
2013-11-09 18:37:06,204 [pontoon.droplet:DEBUG] destroy: (<pontoon.droplet.Droplet instance at 0x10ce1fd40>, 'foobar', False){}
2013-11-09 18:37:06,204 [pontoon.droplet:DEBUG] id_from_name: (<pontoon.droplet.Droplet instance at 0x10ce1fd40>, 'foobar'){}
2013-11-09 18:37:06,204 [pontoon.droplet:DEBUG] list: (<pontoon.droplet.Droplet instance at 0x10ce1fd40>,){}
2013-11-09 18:37:06,205 [pontoon.pontoon:DEBUG] render: (<pontoon.pontoon.Pontoon instance at 0x10ce1fcf8>, 'droplets', '/droplets'){}
2013-11-09 18:37:06,205 [pontoon.pontoon:DEBUG] request: (<pontoon.pontoon.Pontoon instance at 0x10ce1fcf8>, '/droplets'){'params': {}, 'method': 'GET'}
2013-11-09 18:37:07,498 [pontoon.pontoon:DEBUG] render: (<pontoon.pontoon.Pontoon instance at 0x10ce1fcf8>, 'event_id', '/droplets/998/destroy'){'params': {'scrub_data': 1}}
2013-11-09 18:37:07,498 [pontoon.pontoon:DEBUG] request: (<pontoon.pontoon.Pontoon instance at 0x10ce1fcf8>, '/droplets/998/destroy'){'params': {'scrub_data': 1}, 'method': 'GET'}

A timestamp, followed by the module, debug level, the method called and the arguments to that method (positional as brackets, keywords as curlies).

This functionality is implemented by the @debug decorator, the code for which can be seen at pontoon/log.py.

Mocking

Set the MOCK environment variable (to anything) to return mock request data instead of querying Digital Ocean.

This is implemented solely for end-to-end testing of the CLI, but you may find it useful in some other scenarios.

pontoon's People

Contributors

bendtherules avatar benjmin-r avatar duggan avatar jwilk avatar nanobeep avatar patrickod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pontoon's Issues

Investigate a better free and hosted CI server with cross-platform support

Popular hosted CI servers:

  1. Gitlab CI
  2. Drone.io CI
  3. Jenkins (somewhere hosted)

Requirements:

  1. Cross-Platform, free and hosted
  2. Easy integration with Github

Is this possible?

It would be great if the CI server could report back which part of the test failed rather than just a FAIL message for any error. For eg. sometimes its good to know that only the PEP8 tests failed or it failed only on Python3 cases, without looking into the whole log.

When DO retires an image, it breaks image listing

Example:

ross@air:~/duggan/pontoon (master)$ pontoon droplet list
foo-api-1:   (512MB, 1505447 [could not determine image name], Amsterdam 2, 192.0.2.128, active)
ross@air:~/duggan/pontoon (master)$ pontoon droplet show foo-api-1
No image found for id 1505447

Doesn't work with Python 3.5(.1)

Hi & thanks for making pontoon! Most things work with my Python 3, but not all:

I get:

$ pontoon configure
[...]
Droplet login username? (currently 'root'): 
write() argument must be str, not bytes

$ pontoon droplet list --detail
dictionary changed size during iteration

Use API documentation to build models and urls for tests

Test models and mock URL scheme should be built using the official Digital Ocean API docs.

The documentation at developers.digitalocean.com is almost good enough to generate tests from, but needs its example code syntax checked.

Current hacky work (how do I even XML):

pip install requests
pip install lxml

# -*- coding: utf-8 -*-

from StringIO import StringIO
from requests import get
from lxml import etree
import json

doc = StringIO(get('https://developers.digitalocean.com/').text)
parser = etree.HTMLParser()
tree = etree.parse(doc, parser)
api_docs = tree.xpath('//*[@id="api"]/*[@class="api-section"]')

data = {}
for section in api_docs:
    root_url = section.xpath('h2')[0].text
    data[root_url] = []
    for ul in section:
        for li in ul:
            for div in li:
                for ddiv in div:
                    for child in ddiv:
                        if child.tag == 'pre':
                            data[root_url].append(child.text)

for k, v in data.iteritems():
    print(len(v))

Add wheel and windows builds on pypi

Pontoon on PyPi doesnt have wheel and other builds like .msi or .exe for windows.

Although the later ones are not that important, wheels are the new standard for python packaging and so, we should definitely use that. As they are pre-compiled, they are also easier to install in some cases.

Appveyor has a way of building stuffs within it and making those packages available for download called artifacts - which is already setup and available for each job. For eg, here is one https://ci.appveyor.com/project/duggan/pontoon/build/1.0.24/job/6f0truodogexy7ul/artifacts .

We can directly upload that during release to pypi or build it on dev machines using python setup.py bdist_wheel bdist_wininst bdist_msi. I am not sure if the windows builds are possible on linux machines. Also, we should build it using different major versions of Python.

Replace BATS test with something more cross-platform

From what I understand, BATS is used for testing the cmdline scripts, but works only on linux - As we're trying to make them cross-platform, we should also move away from BATS to some Python module which does this well. That'll ease and streamline the testing process on Windows, although it might not be observable in the CI.

It should be easy to put together some glue python code for this, but there might be some well-developed module just for this - That will be the preferred solution.

Edit:

Possibly useful modules:

scripttest [Small and to the point]

Edit 2 :

I'll give it a try to translate the cli test cases using scripttest. What do you think, will it be a good replacement for BATS?

Also, the code coverage has fall sharply after moving the scripts to cmd, how can we improve that? Should we run the same cli tests both in cli mode and import pontoon-configure mode to keep the stats happy?

pontoon configure: No command 'interactive'

I wanted to configure my pontoon, but it failed with a cryptic message:

$ pontoon configure

------------------------------------------------------------
|                                                          |
|    Configure your Digital Ocean account with pontoon.    |
|                                                          |
------------------------------------------------------------

Personal Access Token: 0000000000000000000000000000000000000000000000000000000000000000

************************************************************
*                                                          *
*  Pontoon can either use an existing SSH key or generate  *
*       a new one using OpenSSH (Linux/BSD/Mac only)       *
*                                                          *
************************************************************

Use an existing keypair? (y/n): n
Path to SSH private key (default ~/.ssh/id_rsa): 
Generating public/private rsa key pair.
Your identification has been saved in /home/jwilk/.ssh/id_rsa.
Your public key has been saved in /home/jwilk/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:6KjkbrKApS1m8MkRLYgBFeAf1vXuZOfYL4WG1r+pZOg jwilk@borsuk
The key's randomart image is:
+---[RSA 2048]----+
|=oo.   .         |
|oo .. . .        |
|o.oo..   .       |
|  oo.  ..        |
|. o.  . S+o..    |
|o* o o  +o*+ .   |
|=o* . . .+.=o    |
|=+..    . o....  |
|.=+      E .o+.  |
+----[SHA256]-----+
No command 'interactive'

CLI doesnt work on windows directly

Pontoon put a few scripts inside scripts dir, but they seem to be just the python files without any file extension.

Trying to run configure as python .\pontoon-configure only shows the cli usage docs Usage: pontoon configure [--help] and nothing else happens.

Is the cli thing using anything linux specific?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.