Running Jobs in Zerocloud

#!/usr/bin/env python
import requests
import json
import sys
import os
def get_url_and_token():
	user = os.getenv('ST_USER', None)
	auth = os.getenv('ST_AUTH', None)
	key = os.getenv('ST_KEY', None)
	if not (user and auth and key):
		print 'must supply ST_USER, ST_AUTH and ST_KEY env vars'
	res = requests.get(auth, headers={'x-storage-user': user,
					'x-storage-pass': key})
	return(res.headers.get('x-storage-url', None),
		res.headers.get('x-auth-token', None))
def zebra_execute(endpoint, token, manifest):
			'X-Auth-Token': token,
			'Content-Type': 'application/json',
			'X-ZeroVM-Execute': '1.0',
			'X-Zerovm-Deferred': 'always'},
def get_object(endpoint, token, container, object):
	resp = requests.get(
		"%s/%s/%s" % (endpoint, container, object),
		headers={'X-Auth-Token': token})
	if resp.status_code != 200:
		sys.stderr.write('Result code %d getting json file' % resp.result_code)
	return resp.content
def usage():
	print 'zexec <local file> or zexec <container> <job>'
# either run as 'zexec <local file>' or zexec <container> <job>'
json_file = ''
url, token = get_url_and_token()
if len(sys.argv) == 2:
	with open(sys.argv[1], 'r') as f:
		json_file =
elif len(sys.argv) == 3:
	container = sys.argv[1]
	obj = sys.argv[2]
	json_file = get_object(url, token, container, obj)
resp = zebra_execute(url, token, json_file)
print resp.content


ট্যাগসমূহ:, , , ,

মন্তব্য করুন

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / পরিবর্তন )

Twitter picture

You are commenting using your Twitter account. Log Out / পরিবর্তন )

Facebook photo

You are commenting using your Facebook account. Log Out / পরিবর্তন )

Google+ photo

You are commenting using your Google+ account. Log Out / পরিবর্তন )

Connecting to %s

%d bloggers like this: