blob: 35a0fb7a8ff0aa7184f18417d0f916701aef5cf1 [file] [log] [blame]
Scott Baker50421662016-06-27 22:09:48 -07001#! /usr/bin/env python
2
3import json
4import os
5import requests
6import sys
7import traceback
8
9def main():
10 global opencloud_auth
11
12 if len(sys.argv)!=5:
13 print >> sys.stderr, "syntax: run_tosca.py <port> <username> <password> <fn>"
14 sys.exit(-1)
15
16 port = int(sys.argv[1])
17 username = sys.argv[2]
18 password = sys.argv[3]
19 tosca_fn = sys.argv[4]
20
21 xos_auth=(username, password)
22
23 hostname = "127.0.0.1"
24 url = "http://%s:%d/api/utility/tosca/run/" % (hostname, port)
25
26 recipe = open(tosca_fn).read()
27
28 r = requests.post(url, data={"recipe": recipe}, auth=xos_auth)
29 if (r.status_code != 200):
30 print >> sys.stderr, "ERR: recieved status %d" % r.status_code
31 try:
32 print >> sys.stderr, r.json()["error_text"]
33 except:
34 traceback.print_exc("error while printing the error!")
35 print r.text
36 sys.exit(-1)
37
38 result = r.json()
39 if "log_msgs" in result:
40 print "\n".join(result["log_msgs"])+"\n"
41
42if __name__ == "__main__":
43 main()
44