Moving utils script from service-profile
Change-Id: I779013a83f4f26c6d2b96782a468d25934a68eac
diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh
new file mode 100755
index 0000000..b156706
--- /dev/null
+++ b/scripts/cleanup.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+function cleanup_network {
+ NETWORK=$1
+ SUBNETS=`neutron net-show $NETWORK | grep -i subnets | awk '{print $4}'`
+ if [[ $SUBNETS != "" ]]; then
+ PORTS=`neutron port-list | grep -i $SUBNETS | awk '{print $2}'`
+ for PORT in $PORTS; do
+ echo "Deleting port $PORT"
+ neutron port-delete $PORT
+ done
+ fi
+ neutron net-delete $NETWORK
+}
+
+source ./admin-openrc.sh
+
+echo "Deleting VMs"
+# Delete all VMs
+VMS=$( nova list --all-tenants|grep mysite|awk '{print $2}' )
+for VM in $VMS
+do
+ nova delete $VM
+done
+
+echo "Waiting 5 seconds..."
+sleep 5
+
+cleanup_network lan_network
+cleanup_network wan_network
+cleanup_network mysite_vcpe-private
+cleanup_network mysite_vsg-access
+cleanup_network management
+cleanup_network management_hosts
+
+echo "Deleting networks"
+# Delete all networks beginning with mysite_
+NETS=$( neutron net-list --all-tenants|grep mysite|awk '{print $2}' )
+for NET in $NETS
+do
+ neutron net-delete $NET
+done
+
+neutron net-delete lan_network || true
+neutron net-delete subscriber_network || true
+neutron net-delete public_network || true
+neutron net-delete hpc_client_network || true
+neutron net-delete ceilometer_network || true
+neutron net-delete management || true
+neutron net-delete management_hosts || true
+neutron net-delete mysite_vsg-access || true
+neutron net-delete public || true
+neutron net-delete exampleservice_network || true
diff --git a/scripts/run_tosca.py b/scripts/run_tosca.py
new file mode 100755
index 0000000..35a0fb7
--- /dev/null
+++ b/scripts/run_tosca.py
@@ -0,0 +1,44 @@
+#! /usr/bin/env python
+
+import json
+import os
+import requests
+import sys
+import traceback
+
+def main():
+ global opencloud_auth
+
+ if len(sys.argv)!=5:
+ print >> sys.stderr, "syntax: run_tosca.py <port> <username> <password> <fn>"
+ sys.exit(-1)
+
+ port = int(sys.argv[1])
+ username = sys.argv[2]
+ password = sys.argv[3]
+ tosca_fn = sys.argv[4]
+
+ xos_auth=(username, password)
+
+ hostname = "127.0.0.1"
+ url = "http://%s:%d/api/utility/tosca/run/" % (hostname, port)
+
+ recipe = open(tosca_fn).read()
+
+ r = requests.post(url, data={"recipe": recipe}, auth=xos_auth)
+ if (r.status_code != 200):
+ print >> sys.stderr, "ERR: recieved status %d" % r.status_code
+ try:
+ print >> sys.stderr, r.json()["error_text"]
+ except:
+ traceback.print_exc("error while printing the error!")
+ print r.text
+ sys.exit(-1)
+
+ result = r.json()
+ if "log_msgs" in result:
+ print "\n".join(result["log_msgs"])+"\n"
+
+if __name__ == "__main__":
+ main()
+