Skip to content

Instantly share code, notes, and snippets.

@bgulla
Created February 23, 2015 21:22
Show Gist options
  • Save bgulla/1715ca625b98a7f7a483 to your computer and use it in GitHub Desktop.
Save bgulla/1715ca625b98a7f7a483 to your computer and use it in GitHub Desktop.
Python marathon client for submitting jobs.
#!/usr/bin/python
#curl -X POST -H "Content-Type: application/json" localhost:8080/v2/apps -d@Docker2.json
import httplib,urllib
import os
import json
class MarathonClient(object):
cpus = 1
memory = 1
instances = 1
docker_image = ""
id = ""
def __init__(self,id,docker_image):
self.id = id
self.docker_image = docker_image
def jsonify(self):
myjson = """{
"container" : {
"type" : "DOCKER",
"docker" : {
"image": "%s"
},
"volumes" : []
},
"id" : "%s",
"args" : ["hello"],
"cpus" : %d,
"mem" : %d,
"instances" : 1
}""" % (self.docker_image, self.id, self.cpus, self.memory)
return myjson
# End of class declaration
def sendToMarathon(marathonclient):
headers = {"Content-Type": "application/json"}
params = marathonclient.jsonify()
conn = httplib.HTTPConnection("localhost:8080")
conn.request("POST", "/v2/apps", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
conn.close()
# End of posting method
fling = MarathonClient(id="rainbowroad32c", docker_image="bgulla/rainbowroad")
sendToMarathon(fling)
#print fling.jsonify()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment