- echo -e " -y: do not prompt for confirmation, assumes yes"
- echo -e " -h / --help: print this help"
-}
-
-#Uninstall OSM: remove containers
-function uninstall(){
- echo -e "\nUninstalling OSM"
- if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
- $OSM_DEVOPS/jenkins/host/clean_container RO
- $OSM_DEVOPS/jenkins/host/clean_container VCA
- $OSM_DEVOPS/jenkins/host/clean_container MON
- $OSM_DEVOPS/jenkins/host/clean_container SO
- #$OSM_DEVOPS/jenkins/host/clean_container UI
- else
- lxc stop RO && lxc delete RO
- lxc stop VCA && lxc delete VCA
- lxc stop MON && lxc delete MON
- lxc stop SO-ub && lxc delete SO-ub
- fi
- echo -e "\nDeleting imported lxd images if they exist"
- lxc image show osm-ro &>/dev/null && lxc image delete osm-ro
- lxc image show osm-vca &>/dev/null && lxc image delete osm-vca
- lxc image show osm-soui &>/dev/null && lxc image delete osm-soui
- return 0
-}
-
-function remove_stack() {
- stack=$1
- if sg docker -c "docker stack ps ${stack}" ; then
- echo -e "\nRemoving stack ${stack}" && sg docker -c "docker stack rm ${stack}"
- COUNTER=0
- result=1
- while [ ${COUNTER} -lt 30 ]; do
- result=$(sg docker -c "docker stack ps ${stack}" | wc -l)
- #echo "Dockers running: $result"
- if [ "${result}" == "0" ]; then
- break
- fi
- let COUNTER=COUNTER+1
- sleep 1
- done
- if [ "${result}" == "0" ]; then
- echo "All dockers of the stack ${stack} were removed"
- else
- FATAL "Some dockers of the stack ${stack} could not be removed. Could not clean it."
- fi
- sleep 5
- fi
-}
-
-#Uninstall lightweight OSM: remove dockers
-function uninstall_lightweight() {
- if [ -n "$INSTALL_ONLY" ]; then
- if [ -n "$INSTALL_ELK" ]; then
- echo -e "\nUninstalling OSM ELK stack"
- remove_stack osm_elk
- sudo rm -rf /etc/osm/docker/osm_elk
- fi
- if [ -n "$INSTALL_PERFMON" ]; then
- echo -e "\nUninstalling OSM Performance Monitoring stack"
- remove_stack osm_metrics
- sg docker -c "docker image rm osm/kafka-exporter"
- sudo rm -rf /etc/osm/docker/osm_metrics
- fi
- else
- echo -e "\nUninstalling OSM"
- remove_stack osm
- remove_stack osm_elk
- remove_stack osm_metrics
- echo "Now osm docker images and volumes will be deleted"
- newgrp docker << EONG
- docker image rm osm/ro
- docker image rm osm/lcm
- docker image rm osm/light-ui
- docker image rm osm/nbi
- docker image rm osm/mon
- docker image rm osm/pm
- docker image rm osm/kafka-exporter
- docker volume rm osm_mon_db
- docker volume rm osm_mongo_db
- docker volume rm osm_osm_packages
- docker volume rm osm_ro_db
-EONG
- echo "Removing /etc/osm and /var/log/osm files"
- sudo rm -rf /etc/osm
- sudo rm -rf /var/log/osm
- fi
- echo "Some docker images will be kept in case they are used by other docker stacks"
- echo "To remove them, just run 'docker image prune' in a terminal"
- return 0
-}
-
-#Configure NAT rules, based on the current IP addresses of containers
-function nat(){
- echo -e "\nChecking required packages: iptables-persistent"
- dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \
- sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent
- echo -e "\nConfiguring NAT rules"
- echo -e " Required root privileges"
- sudo $OSM_DEVOPS/installers/nat_osm
-}
-
-function FATAL(){
- echo "FATAL error: Cannot install OSM due to \"$1\""
- exit 1
-}
-
-#Update RO, SO and UI:
-function update(){
- echo -e "\nUpdating components"
-
- echo -e " Updating RO"
- CONTAINER="RO"
- MDG="RO"
- INSTALL_FOLDER="/opt/openmano"
- echo -e " Fetching the repo"
- lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
- BRANCH=""
- BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
- [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
- CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
- CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
- echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
- # COMMIT_ID either was previously set with -b option, or is an empty string
- CHECKOUT_ID=$COMMIT_ID
- [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
- [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
- if [[ $CHECKOUT_ID == "tags/"* ]]; then
- REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
- else
- REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
- fi
- echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
- if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
- echo " Nothing to be done."
- else
- echo " Update required."
- lxc exec $CONTAINER -- service osm-ro stop
- lxc exec $CONTAINER -- git -C /opt/openmano stash
- lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase
- lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID
- lxc exec $CONTAINER -- git -C /opt/openmano stash pop
- lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh
- lxc exec $CONTAINER -- service osm-ro start
- fi
- echo
-
- echo -e " Updating SO and UI"
- CONTAINER="SO-ub"
- MDG="SO"
- INSTALL_FOLDER="" # To be filled in
- echo -e " Fetching the repo"
- lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
- BRANCH=""
- BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
- [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
- CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
- CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
- echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
- # COMMIT_ID either was previously set with -b option, or is an empty string
- CHECKOUT_ID=$COMMIT_ID
- [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
- [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
- if [[ $CHECKOUT_ID == "tags/"* ]]; then
- REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
- else
- REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
- fi
- echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
- if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
- echo " Nothing to be done."
- else
- echo " Update required."
- # Instructions to be added
- # lxc exec SO-ub -- ...
- fi
- echo
- echo -e "Updating MON Container"
- CONTAINER="MON"
- MDG="MON"
- INSTALL_FOLDER="/root/MON"
- echo -e " Fetching the repo"
- lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
- BRANCH=""
- BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
- [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
- CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
- CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
- echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)"
- # COMMIT_ID either was previously set with -b option, or is an empty string
- CHECKOUT_ID=$COMMIT_ID
- [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
- [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
- if [[ $CHECKOUT_ID == "tags/"* ]]; then
- REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
- else
- REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
- fi
- echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
- if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
- echo " Nothing to be done."
- else
- echo " Update required."
- fi
- echo
-}
-
-function so_is_up() {
- if [ -n "$1" ]; then
- SO_IP=$1
- else
- SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'`
- fi
- time=0
- step=5
- timelength=300
- while [ $time -le $timelength ]
- do
- if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \
- -H 'accept: application/vnd.yang.data+json' \
- -H 'authorization: Basic YWRtaW46YWRtaW4=' \
- -H 'cache-control: no-cache' 2> /dev/null | jq '.[].components.component_info[] | select(.component_name=="RW.Restconf")' 2>/dev/null | grep "RUNNING" | wc -l` -eq 1 ]]
- then
- echo "RW.Restconf running....SO is up"
- return 0
- fi
-
- sleep $step
- echo -n "."
- time=$((time+step))
- done
-
- FATAL "OSM Failed to startup. SO failed to startup"
-}
-
-function vca_is_up() {
- if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then
- echo "VCA is up and running"
- return 0
- fi
-
- FATAL "OSM Failed to startup. VCA failed to startup"
-}
-
-function mon_is_up() {
- if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
- echo "MON is up and running"
- return 0
- fi
-
- FATAL "OSM Failed to startup. MON failed to startup"
-}
-
-function ro_is_up() {
- if [ -n "$1" ]; then
- RO_IP=$1
- else
- RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'`
- fi
- time=0
- step=2
- timelength=20
- while [ $time -le $timelength ]; do
- if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
- echo "RO is up and running"
- return 0
+ echo -e " --charmed: Deploy and operate OSM with Charms on k8s"
+ echo -e " [--bundle <bundle path>]: Specify with which bundle to deploy OSM with charms (--charmed option)"
+ echo -e " [--k8s <kubeconfig path>]: Specify with which kubernetes to deploy OSM with charms (--charmed option)"
+ echo -e " [--vca <name>]: Specifies the name of the controller to use - The controller must be already bootstrapped (--charmed option)"
+ echo -e " [--small-profile]: Do not install and configure LXD which aims to use only K8s Clouds (--charmed option)"
+ echo -e " [--lxd <yaml path>]: Takes a YAML file as a parameter with the LXD Cloud information (--charmed option)"
+ echo -e " [--lxd-cred <yaml path>]: Takes a YAML file as a parameter with the LXD Credentials information (--charmed option)"
+ echo -e " [--microstack]: Installs microstack as a vim. (--charmed option)"
+ echo -e " [--overlay]: Add an overlay to override some defaults of the default bundle (--charmed option)"
+ echo -e " [--ha]: Installs High Availability bundle. (--charmed option)"
+ echo -e " [--tag]: Docker image tag. (--charmed option)"
+ echo -e " [--registry]: Docker registry with optional credentials as user:pass@hostname:port (--charmed option)"
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+# takes a juju/accounts.yaml file and returns the password specific
+# for a controller. I wrote this using only bash tools to minimize
+# additions of other packages
+function parse_juju_password {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ password_file="${HOME}/.local/share/juju/accounts.yaml"
+ local controller_name=$1
+ local s='[[:space:]]*' w='[a-zA-Z0-9_-]*' fs=$(echo @|tr @ '\034')
+ sed -ne "s|^\($s\):|\1|" \
+ -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
+ -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $password_file |
+ awk -F$fs -v controller=$controller_name '{
+ indent = length($1)/2;
+ vname[indent] = $2;
+ for (i in vname) {if (i > indent) {delete vname[i]}}
+ if (length($3) > 0) {
+ vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
+ if (match(vn,controller) && match($2,"password")) {
+ printf("%s",$3);
+ }
+ }
+ }'
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function set_vca_variables() {
+ OSM_VCA_CLOUDNAME="lxd-cloud"
+ [ -n "$OSM_VCA_HOST" ] && OSM_VCA_CLOUDNAME="localhost"
+ if [ -z "$OSM_VCA_HOST" ]; then
+ [ -z "$CONTROLLER_NAME" ] && OSM_VCA_HOST=`sg lxd -c "juju show-controller $OSM_NAMESPACE"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
+ [ -n "$CONTROLLER_NAME" ] && OSM_VCA_HOST=`juju show-controller $CONTROLLER_NAME |grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
+ [ -z "$OSM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
+ fi
+ if [ -z "$OSM_VCA_SECRET" ]; then
+ [ -z "$CONTROLLER_NAME" ] && OSM_VCA_SECRET=$(parse_juju_password $OSM_NAMESPACE)
+ [ -n "$CONTROLLER_NAME" ] && OSM_VCA_SECRET=$(parse_juju_password $CONTROLLER_NAME)
+ [ -z "$OSM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
+ fi
+ if [ -z "$OSM_VCA_PUBKEY" ]; then
+ OSM_VCA_PUBKEY=$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)
+ [ -z "$OSM_VCA_PUBKEY" ] && FATAL "Cannot obtain juju public key"
+ fi
+ if [ -z "$OSM_VCA_CACERT" ]; then
+ [ -z "$CONTROLLER_NAME" ] && OSM_VCA_CACERT=$(juju controllers --format json | jq -r --arg controller $OSM_NAMESPACE '.controllers[$controller]["ca-cert"]' | base64 | tr -d \\n)
+ [ -n "$CONTROLLER_NAME" ] && OSM_VCA_CACERT=$(juju controllers --format json | jq -r --arg controller $CONTROLLER_NAME '.controllers[$controller]["ca-cert"]' | base64 | tr -d \\n)
+ [ -z "$OSM_VCA_CACERT" ] && FATAL "Cannot obtain juju CA certificate"
+ fi
+}
+
+function generate_secret() {
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
+ head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32
+ [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
+}
+
+function check_packages() {
+ NEEDED_PACKAGES="$1"
+ echo -e "Checking required packages: ${NEEDED_PACKAGES}"
+ for PACKAGE in ${NEEDED_PACKAGES} ; do
+ dpkg -L ${PACKAGE}
+ if [ $? -ne 0 ]; then
+ echo -e "Package ${PACKAGE} is not installed."
+ echo -e "Updating apt-cache ..."
+ sudo apt-get update
+ echo -e "Installing ${PACKAGE} ..."
+ sudo apt-get install -y ${PACKAGE} || FATAL "failed to install ${PACKAGE}"