fix base_url for public url 23/38823/1
authorgrakiss <grakiss.wanglei@huawei.com>
Mon, 7 Aug 2017 06:53:15 +0000 (14:53 +0800)
committergrakiss <grakiss.wanglei@huawei.com>
Mon, 7 Aug 2017 06:54:21 +0000 (14:54 +0800)
Change-Id: I171e9b0bce1891594bf7ef577809e73f05556810
Signed-off-by: grakiss <grakiss.wanglei@huawei.com>
dovetail/utils/local_db/get_db_schema.py [new file with mode: 0644]
dovetail/utils/local_db/launch_db.sh

diff --git a/dovetail/utils/local_db/get_db_schema.py b/dovetail/utils/local_db/get_db_schema.py
new file mode 100644 (file)
index 0000000..1106355
--- /dev/null
@@ -0,0 +1,61 @@
+##############################################################################
+# Copyright (c) 2016 HUAWEI TECHNOLOGIES CO.,LTD and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import requests
+import json
+
+
+source_url = 'http://116.66.187.136:9999/api/v1'
+
+
+def get(url):
+    try:
+        ret = requests.get(url)
+        return ret.json()
+    except:
+        return None
+
+
+def pod():
+    source = '{}/pods'.format(source_url)
+    try:
+        pods = get(source)['pods']
+        with open("pods.json", "w") as f:
+            f.write(json.dumps(pods, indent=4))
+    except:
+        return
+
+
+def project():
+    source = '{}/projects'.format(source_url)
+
+    try:
+        projects = get(source)['projects']
+        with open("projects.json", "w") as f:
+            f.write(json.dumps(projects, indent=4))
+    except:
+        return
+
+    for p in projects:
+        source = '{}/projects/{}/cases'.format(source_url, p['name'])
+        print(p['name'])
+        print(source)
+        try:
+            cases = get(source)
+            with open("cases.json", "a+") as f:
+                f.write(json.dumps(cases))
+                f.write('\n')
+                f.close()
+        except:
+            print("useless data")
+
+
+if __name__ == '__main__':
+    pod()
+    project()
index 38a9733..a7439b6 100755 (executable)
@@ -8,13 +8,14 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-if [ "$#" -ne 1 ]; then
+if [ "$#" -ne 2 ]; then
     echo "Error: missing parameter! try again like this:"
     echo ""
-    echo "./launch_db.sh 192.168.115.2"
+    echo "./launch_db.sh 192.168.115.2 http://116.66.187.136:9999"
     echo ""
     echo "parameters:"
     echo "  db_host_ip: your localhost ip address "
+    echo "  base_url: your public url for website"
     echo ""
     exit 1
 fi
@@ -22,6 +23,8 @@ fi
 export mongodb_port=${mongodb_port:-"27017"}
 export testapi_port=${testapi_port:-"8000"}
 export db_host_ip=${db_host_ip:-"$1"}
+export base_url=${base_url:-"$2"}
+
 
 set -e
 
@@ -76,7 +79,7 @@ fi
 
 # run testapi container
 echo "Step3: run ${container_name} container."
-cmd="sudo docker run -itd -p ${testapi_port}:8000 --name ${container_name} -e mongodb_url=mongodb://${db_host_ip}:${mongodb_port}/ ${testapi_img}"
+cmd="sudo docker run -itd -p ${testapi_port}:8000 --name ${container_name} -e mongodb_url=mongodb://${db_host_ip}:${mongodb_port}/ -e base_url=${base_url} ${testapi_img}"
 echo $cmd
 ${cmd}