Scott Baker | 5042166 | 2016-06-27 22:09:48 -0700 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | |
| 3 | import json |
| 4 | import os |
| 5 | import requests |
| 6 | import sys |
| 7 | import traceback |
| 8 | |
| 9 | def 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 | |
| 42 | if __name__ == "__main__": |
| 43 | main() |
| 44 | |