Created
February 23, 2015 21:22
-
-
Save bgulla/1715ca625b98a7f7a483 to your computer and use it in GitHub Desktop.
Python marathon client for submitting jobs.
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
#!/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