Skip to content

Instantly share code, notes, and snippets.

@allanino
Created February 26, 2016 17:57
Show Gist options
  • Select an option

  • Save allanino/c1c51e3b94e003519f6a to your computer and use it in GitHub Desktop.

Select an option

Save allanino/c1c51e3b94e003519f6a to your computer and use it in GitHub Desktop.
Just some commands I need for my project.
import requests
class DockerAPI(object):
""" Helper for using Fleet API to deploy services to a CoreOS cluster."""
def __init__(self, docker_endpoint):
self.docker_endpoint = docker_endpoint
def containers(self):
""" Return a list of pairs with container's names and ids """
containers = requests.get('http://%s/containers/json' % self.docker_endpoint).json()
return [ (c['Names'][0][1:], c['Id']) for c in containers ]
def stop(self, _id):
""" Stop container with given id """
res = requests.post('http://%s/containers/%s/stop' % (self.docker_endpoint, _id))
return res.status_code
def delete(self, _id):
""" Delete container with given id """
res = requests.delete('http://%s/containers/%s' % (self.docker_endpoint, _id))
return res.status_code
def destroy(self, _id):
""" Stop and delete container with given id """
self.stop(_id)
return self.delete(_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment