OSMCLIENT_VERSION=10.0
IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
PATH=/snap/bin:${PATH}
+OSM_DEVOPS="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. &> /dev/null && pwd )"
+if [ -f ${OSM_DEVOPS}/common/all_funcs ] ; then
+ source ${OSM_DEVOPS}/common/all_funcs
+else
+ function track(){
+ true
+ }
+ function FATAL_TRACK(){
+ exit 1
+ }
+fi
MODEL_NAME=osm
function install_snaps(){
if [ ! -v KUBECFG ]; then
KUBEGRP="microk8s"
- sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable
+ sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable ||
+ FATAL_TRACK k8scluster "snap install microk8s ${MICROK8S_VERSION}/stable failed"
sudo usermod -a -G microk8s `whoami`
sudo cat /var/snap/microk8s/current/args/kube-apiserver | grep advertise-address || (
echo "--advertise-address $DEFAULT_IP" | sudo tee -a /var/snap/microk8s/current/args/kube-apiserver
sg ${KUBEGRP} -c "microk8s status --wait-ready"
KUBECONFIG=~/.osm/microk8s-config.yaml
sg ${KUBEGRP} -c "microk8s config" | tee ${KUBECONFIG}
+ track k8scluster k8scluster_ok
else
KUBECTL="kubectl"
sudo snap install kubectl --classic
export KUBECONFIG=${KUBECFG}
KUBEGRP=$(id -g -n)
fi
- sudo snap install juju --classic --channel=$JUJU_VERSION/stable
+ sudo snap install juju --classic --channel=$JUJU_VERSION/stable ||
+ FATAL_TRACK juju "snap install juju ${JUJU_VERSION}/stable failed"
+ track juju juju_ok
}
function bootstrap_k8s_lxd(){
Please retry the installation once this conflict has been resolved.
EOF
- exit 1
+ FATAL_TRACK bootstrap_k8s "VCA already present"
fi
else
CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
Please retry the installation with one of the solutions applied.
EOF
- exit 1
+ FATAL_TRACK bootstrap_k8s "Requested VCA not present"
fi
fi
if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
echo "Microk8s storage failed to enable"
sg ${KUBEGRP} -c "microk8s.status"
- exit 1
+ FATAL_TRACK bootstrap_k8s "Microk8s storage failed to enable"
fi
storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
if [[ $storage_status == "enabled" ]]; then
"juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
&& K8S_CLOUD_NAME=microk8s
fi
+ track bootstrap_k8s bootstrap_k8s_ok
if [ -v LXD_CLOUD ]; then
if [ ! -v LXD_CREDENTIALS ]; then
echo "The installer needs the LXD server certificate if the LXD is external"
- exit 1
+ FATAL_TRACK bootstrap_lxd "No LXD certificate supplied"
fi
else
LXDENDPOINT=$DEFAULT_IP
juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
sg lxd -c "lxd waitready"
juju controller-config features=[k8s-operators]
-}
-
-function wait_for_port(){
- SERVICE=$1
- INDEX=$2
- TIME_TO_WAIT=30
- start_time="$(date -u +%s)"
- while true
- do
- now="$(date -u +%s)"
- if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
- echo "Failed to expose external ${SERVICE} interface port"
- exit 1
- fi
-
- if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
- break
- fi
- sleep 1
- done
+ track bootstrap_lxd bootstrap_lxd_ok
}
function deploy_charmed_osm(){
now="$(date -u +%s)"
if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
echo "Timed out waiting for OSM services to become ready"
- exit 1
+ FATAL_TRACK deploy_osm "Timed out waiting for services to become ready"
fi
sleep 10
done
}
function install_microstack() {
- sudo snap install microstack --classic --beta
- sudo microstack.init --auto
- wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
- microstack.openstack image create \
- --public \
- --disk-format qcow2 \
- --container-format bare \
- --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
- ubuntu1604
- ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
- microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
- export OSM_HOSTNAME=`juju status -m $MODEL_NAME --format json | jq -rc '.applications."nbi".address'`
- osm vim-create --name microstack-site \
- --user admin \
- --password keystone \
- --auth_url http://10.20.20.1:5000/v3 \
- --tenant admin \
- --account_type openstack \
- --config='{security_groups: default,
- keypair: microstack,
- project_name: admin,
- user_domain_name: default,
- region_name: microstack,
- insecure: True,
- availability_zone: nova,
- version: 3}'
+ sudo snap install microstack --beta --devmode
+
+ CHECK=$(microstack.openstack server list)
+ if [ $? -ne 0 ] ; then
+ if [[ $CHECK == *"not initialized"* ]]; then
+ echo "Setting MicroStack dashboard to listen to port 8080"
+ sudo snap set microstack config.network.ports.dashboard=8080
+ echo "Initializing MicroStack. This can take several minutes"
+ sudo microstack.init --auto --control
+ fi
+ fi
+
+ sudo snap alias microstack.openstack openstack
+
+ echo "Updating default security group in MicroStack to allow all access"
+
+ for i in $(microstack.openstack security group list | awk '/default/{ print $2 }'); do
+ for PROTO in icmp tcp udp ; do
+ echo " $PROTO ingress"
+ CHECK=$(microstack.openstack security group rule create $i --protocol $PROTO --remote-ip 0.0.0.0/0 2>&1)
+ if [ $? -ne 0 ] ; then
+ if [[ $CHECK != *"409"* ]]; then
+ echo "Error creating ingress rule for $PROTO"
+ echo $CHECK
+ fi
+ fi
+ done
+ done
+
+ microstack.openstack network show osm-ext &>/dev/null
+ if [ $? -ne 0 ]; then
+ echo "Creating osm-ext network with router to bridge to MicroStack external network"
+ microstack.openstack network create --enable --no-share osm-ext
+ microstack.openstack subnet create osm-ext-subnet --network osm-ext --dns-nameserver 8.8.8.8 \
+ --subnet-range 172.30.0.0/24
+ microstack.openstack router create external-router
+ microstack.openstack router add subnet external-router osm-ext-subnet
+ microstack.openstack router set --external-gateway external external-router
+ fi
+
+ microstack.openstack image list | grep ubuntu20.04 &> /dev/null
+ if [ $? -ne 0 ] ; then
+ echo "Fetching Ubuntu 20.04 image and upLoading to MicroStack"
+ wget -q -O- https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img \
+ | microstack.openstack image create --public --container-format=bare \
+ --disk-format=qcow2 ubuntu20.04 | grep status
+ fi
+
+ if [ ! -f ~/.ssh/microstack ]; then
+ ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
+ microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
+ fi
+
+ echo "Creating VIM microstack-site in OSM"
+ . /var/snap/microstack/common/etc/microstack.rc
+
+ osm vim-create \
+ --name microstack-site \
+ --user "$OS_USERNAME" \
+ --password "$OS_PASSWORD" \
+ --auth_url "$OS_AUTH_URL" \
+ --tenant "$OS_USERNAME" \
+ --account_type openstack \
+ --config='{use_floating_ip: True,
+ insecure: True,
+ keypair: microstack,
+ management_network_name: osm-ext}'
}
DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
echo "Use the following command to register the installed VCA to your OSM:"
echo -e " osm vca-add --endpoints $vca_host:$vca_port \\\n --user $vca_user \\\n --secret $vca_secret \\\n --cacert $vca_cacert \\\n --lxd-cloud lxd-cloud \\\n --lxd-credentials lxd-cloud \\\n --k8s-cloud microk8s \\\n --k8s-credentials microk8s\\\n $hostname-vca"
+ track deploy_osm deploy_vca_only_ok
else
deploy_charmed_osm
+ track deploy_osm deploy_osm_services_k8s_ok
install_osmclient
+ track osmclient osmclient_ok
export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s/http.*\?:\/\///"):443
sleep 10
add_local_k8scluster
+ track final_ops add_local_k8scluster_ok
if [ -v MICROSTACK ]; then
install_microstack
+ track final_ops install_microstack_ok
fi
echo "Your installation is now complete, follow these steps for configuring the osmclient:"
echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
echo
echo "DONE"
+ track end
fi