Merge "Bug 99: get_dhcp_lease.sh with support for LXD DHCP / fix in openvimd.cfg...
authortierno <alfonso.tiernosepulveda@telefonica.com>
Fri, 11 Nov 2016 13:30:00 +0000 (14:30 +0100)
committerGerrit Code Review <root@osm.etsi.org>
Fri, 11 Nov 2016 13:30:00 +0000 (14:30 +0100)
database_utils/init_vim_db.sh
database_utils/migrate_vim_db.sh
httpserver.py
openvimd.cfg
scripts/install-openvim.sh

index f025a9d..16f34ea 100755 (executable)
@@ -40,7 +40,7 @@ function usage(){
     echo -e "  If openvim_version is not provided it tries to get from openvimd.py using relative path"
     echo -e "  OPTIONS"
     echo -e "     -u USER  database user. '$DBUSER' by default. Prompts if DB access fails"
-    echo -e "     -p PASS  database password. 'No password' by default. Prompts if DB access fails"
+    echo -e "     -p PASS  database password. 'No password' or 'vimpw' by default. Prompts if DB access fails"
     echo -e "     -P PORT  database port. '$DBPORT' by default"
     echo -e "     -h HOST  database host. '$DBHOST' by default"
     echo -e "     -d NAME  database name. '$DBNAME' by default.  Prompts if DB access fails"
@@ -85,40 +85,58 @@ while getopts ":u:p:P:h:d:-:" o; do
 done
 shift $((OPTIND-1))
 
-#check and ask for database user password
-DBUSER_="-u$DBUSER"
-DBPASS_=""
-[ -n "$DBPASS" ] && DBPASS_="-p$DBPASS"
+#Creating temporary file
+TEMPFILE="$(mktemp -q --tmpdir "initmanodb.XXXXXX")"
+trap 'rm -f "$TEMPFILE"' EXIT
+chmod 0600 "$TEMPFILE"
+
+#if password is missing, before prompting for it try without password and with "manopw"
 DBHOST_="-h$DBHOST"
 DBPORT_="-P$DBPORT"
-while !  echo ";" | mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME >/dev/null 2>&1
+DEF_EXTRA_FILE_PARAM="--defaults-extra-file=$TEMPFILE"
+if [ -z "${DBPASS}" ]
+then
+    password_ok=""
+    echo -e "[client]\nuser='${DBUSER}'\npassword='vimpw'" > "$TEMPFILE"
+    mysql --defaults-extra-file="$TEMPFILE" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS="vimpw"
+    echo -e "[client]\nuser='${DBUSER}'\npassword=''" > "$TEMPFILE"
+    mysql --defaults-extra-file="$TEMPFILE" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS=""
+fi
+echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE"
+
+#check and ask for database user password
+while ! mysql "$DEF_EXTRA_FILE_PARAM" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1
 do
         [ -n "$logintry" ] &&  echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
         [ -z "$logintry" ] &&  echo -e "\nProvide database name and credentials"
         read -e -p "mysql database name($DBNAME): " KK
         [ -n "$KK" ] && DBNAME="$KK"
         read -e -p "mysql user($DBUSER): " KK
-        [ -n "$KK" ] && DBUSER="$KK" && DBUSER_="-u$DBUSER"
+        [ -n "$KK" ] && DBUSER="$KK"
         read -e -s -p "mysql password: " DBPASS
-        [ -n "$DBPASS" ] && DBPASS_="-p$DBPASS"
-        [ -z "$DBPASS" ] && DBPASS_=""
-        logintry="yes":
+        echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE"
+        logintry="yes"
         echo
 done
 
+DBCMD="mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME"
+DBUSER_="-u$DBUSER"
+DBPASS_="-p$DBPASS"
+
+
 echo "    loading ${DIRNAME}/vim_db_structure.sql"
-sed -e "s/vim_db/$DBNAME/" ${DIRNAME}/vim_db_structure.sql |  mysql  $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ 
+sed -e "s/vim_db/$DBNAME/" ${DIRNAME}/vim_db_structure.sql |  mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_
 
 echo "    migrage database version"
 ${DIRNAME}/migrate_vim_db.sh $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ -d$DBNAME $1
 
 echo  "    loading ${DIRNAME}/host_ranking.sql"
-mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_  $DBNAME < ${DIRNAME}/host_ranking.sql
+mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME < ${DIRNAME}/host_ranking.sql
 
 echo  "    loading ${DIRNAME}/of_ports_pci_correspondence.sql"
-mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_  $DBNAME < ${DIRNAME}/of_ports_pci_correspondence.sql
+mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME < ${DIRNAME}/of_ports_pci_correspondence.sql
 #mysql -h $HOST -P $PORT -u $MUSER -p$MPASS $MDB < ${DIRNAME}/of_ports_pci_correspondence_centos.sql
 
 echo  "    loading ${DIRNAME}/nets.sql"
-mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_  $DBNAME < ${DIRNAME}/nets.sql
+mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME < ${DIRNAME}/nets.sql
 
index 1d379ac..e008478 100755 (executable)
@@ -43,7 +43,7 @@ function usage(){
     echo -e "   if openvim_version is not provided it tries to get from openvimd.py using relative path"
     echo -e "  OPTIONS"
     echo -e "     -u USER  database user. '$DBUSER' by default. Prompts if DB access fails"
-    echo -e "     -p PASS  database password. 'No password' by default. Prompts if DB access fails"
+    echo -e "     -p PASS  database password. 'No password' or 'vimpw' by default. Prompts if DB access fails"
     echo -e "     -P PORT  database port. '$DBPORT' by default"
     echo -e "     -h HOST  database host. '$DBHOST' by default"
     echo -e "     -d NAME  database name. '$DBNAME' by default.  Prompts if DB access fails"
@@ -109,27 +109,41 @@ then
 fi
 OPENVIM_VER_NUM=`printf "%d%03d%03d" ${VERSION_1} ${VERSION_2} ${VERSION_3}`
 
-#check and ask for database user password
-DBUSER_="-u$DBUSER"
-[ -n "$DBPASS" ] && DBPASS_="-p$DBPASS"
+#Creating temporary file
+TEMPFILE="$(mktemp -q --tmpdir "migratemanodb.XXXXXX")"
+trap 'rm -f "$TEMPFILE"' EXIT
+chmod 0600 "$TEMPFILE"
+
+#if password is missing, before prompting for it try without password and with "manopw"
 DBHOST_="-h$DBHOST"
 DBPORT_="-P$DBPORT"
-while !  echo ";" | mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME >/dev/null 2>&1
+DEF_EXTRA_FILE_PARAM="--defaults-extra-file=$TEMPFILE"
+if [ -z "${DBPASS}" ]
+then
+    password_ok=""
+    echo -e "[client]\nuser='${DBUSER}'\npassword='vimpw'" > "$TEMPFILE"
+    mysql --defaults-extra-file="$TEMPFILE" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS="vimpw"
+    echo -e "[client]\nuser='${DBUSER}'\npassword=''" > "$TEMPFILE"
+    mysql --defaults-extra-file="$TEMPFILE" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1 && DBPASS=""
+fi
+echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE"
+
+#check and ask for database user password
+while ! mysql "$DEF_EXTRA_FILE_PARAM" $DBHOST_ $DBPORT_ $DBNAME -e "quit" >/dev/null 2>&1
 do
         [ -n "$logintry" ] &&  echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
         [ -z "$logintry" ] &&  echo -e "\nProvide database name and credentials"
         read -e -p "mysql database name($DBNAME): " KK
         [ -n "$KK" ] && DBNAME="$KK"
         read -e -p "mysql user($DBUSER): " KK
-        [ -n "$KK" ] && DBUSER="$KK" && DBUSER_="-u$DBUSER"
+        [ -n "$KK" ] && DBUSER="$KK"
         read -e -s -p "mysql password: " DBPASS
-        [ -n "$DBPASS" ] && DBPASS_="-p$DBPASS"
-        [ -z "$DBPASS" ] && DBPASS_=""
+        echo -e "[client]\nuser='${DBUSER}'\npassword='${DBPASS}'" > "$TEMPFILE"
         logintry="yes"
         echo
 done
 
-DBCMD="mysql $DBHOST_ $DBPORT_ $DBUSER_ $DBPASS_ $DBNAME"
+DBCMD="mysql $DEF_EXTRA_FILE_PARAM $DBHOST_ $DBPORT_ $DBNAME"
 #echo DBCMD $DBCMD
 
 #GET DATABASE VERSION
index 88b1f0a..870d680 100644 (file)
@@ -30,6 +30,7 @@ __author__="Alfonso Tierno"
 __date__ ="$10-jul-2014 12:07:15$"
 
 import bottle
+import urlparse
 import yaml
 import json
 import threading
@@ -451,6 +452,18 @@ def check_valid_uuid(uuid):
     except js_e.ValidationError:
         return False
 
+
+def is_url(url):
+    '''
+    Check if string value is a well-wormed url
+    :param url: string url
+    :return: True if is a valid url, False if is not well-formed
+    '''
+
+    parsed_url = urlparse.urlparse(url)
+    return parsed_url
+
+
 @bottle.error(400)
 @bottle.error(401) 
 @bottle.error(404) 
@@ -1091,6 +1104,8 @@ def http_post_images(tenant_id):
         image_file = http_content['image'].get('path',None)
         if os.path.exists(image_file):
             http_content['image']['checksum'] = md5(image_file)
+        elif is_url(image_file):
+            pass
         else:
             if not host_test_mode:
                 content = "Image file not found"
index 016ea89..2d1aabb 100644 (file)
@@ -56,7 +56,7 @@ http_port:       9080                # General port where openvim is listening (
 http_admin_port: 9085                # Admin port where openvim is listening (when missing, no administration server is launched)
 
 #database parameters
-db_host:   localhost                 # by default localhost
+db_host:   0.0.0.0                   # by default localhost
 db_user:   vim                       # DB user
 db_passwd: vimpw                     # DB password
 db_name:   vim_db                    # Name of the VIM DB
index 053b8a9..88a92dd 100755 (executable)
@@ -205,7 +205,7 @@ fi  #[[ -z "$NO_PACKAGES" ]]
 if [[ -n $QUIET_MODE ]]
 then
     echo -e "\nCheking database connection and ask for credentials"
-    while ! mysqladmin -s -u$DBUSER $DBPASSWD_PARAM ping
+    while ! mysqladmin -s -u$DBUSER $DBPASSWD_PARAM status >/dev/null
     do
         [ -n "$logintry" ] &&  echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
         [ -z "$logintry" ] &&  echo -e "\nProvide database credentials"
@@ -237,7 +237,7 @@ echo '
 #####                 DOWNLOAD SOURCE                       #####
 #################################################################'
 su $SUDO_USER -c 'git clone '"${GIT_URL}"' openvim'
-[[ -z $DEVELOP ]] && su $SUDO_USER -c 'cd openvim; git checkout tags/v1.0; cd ..'
+[[ -z $DEVELOP ]] && su $SUDO_USER -c 'git -C openvim checkout tags/v1.0.1'
 
 #Unncoment to use a concrete branch, if not main branch 
 #pushd openvim