Matteo Scandolo | 3896c47 | 2017-08-01 13:31:42 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Matteo Scandolo | 9e557c6 | 2017-03-15 11:03:13 -0700 | [diff] [blame] | 17 | #! /usr/bin/env python |
| 18 | |
| 19 | import json |
| 20 | import os |
| 21 | import requests |
| 22 | import sys |
| 23 | import traceback |
| 24 | |
| 25 | def main(): |
| 26 | global opencloud_auth |
| 27 | |
| 28 | if len(sys.argv)!=5: |
| 29 | print >> sys.stderr, "syntax: run_tosca.py <port> <username> <password> <fn>" |
| 30 | sys.exit(-1) |
| 31 | |
| 32 | port = int(sys.argv[1]) |
| 33 | username = sys.argv[2] |
| 34 | password = sys.argv[3] |
| 35 | tosca_fn = sys.argv[4] |
| 36 | |
| 37 | xos_auth=(username, password) |
| 38 | |
| 39 | hostname = "127.0.0.1" |
| 40 | url = "http://%s:%d/api/utility/tosca/run/" % (hostname, port) |
| 41 | |
| 42 | recipe = open(tosca_fn).read() |
| 43 | |
| 44 | r = requests.post(url, data={"recipe": recipe}, auth=xos_auth) |
| 45 | if (r.status_code != 200): |
| 46 | print >> sys.stderr, "ERR: recieved status %d" % r.status_code |
| 47 | try: |
| 48 | print >> sys.stderr, r.json()["error_text"] |
| 49 | except: |
| 50 | traceback.print_exc("error while printing the error!") |
| 51 | print r.text |
| 52 | sys.exit(-1) |
| 53 | |
| 54 | result = r.json() |
| 55 | if "log_msgs" in result: |
| 56 | print "\n".join(result["log_msgs"])+"\n" |
| 57 | |
| 58 | if __name__ == "__main__": |
| 59 | main() |
| 60 | |