| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 1 | #! /bin/bash |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | # |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 15 | |
| 16 | # set -eux |
| 17 | |
| David Garcia | 0db6e9f | 2021-10-05 16:13:08 +0200 | [diff] [blame] | 18 | LXD_VERSION=4.0 |
| David Garcia | d68e0b4 | 2021-06-28 16:50:42 +0200 | [diff] [blame] | 19 | JUJU_VERSION=2.9 |
| Guillermo Calvino | 2834fe7 | 2023-06-22 10:02:53 +0200 | [diff] [blame] | 20 | JUJU_AGENT_VERSION=2.9.43 |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 21 | K8S_CLOUD_NAME="k8s-cloud" |
| beierlm | 3749e31 | 2020-07-02 14:21:09 -0400 | [diff] [blame] | 22 | KUBECTL="microk8s.kubectl" |
| Patricia Reinoso | 0788ee1 | 2023-03-14 16:06:32 +0000 | [diff] [blame] | 23 | MICROK8S_VERSION=1.26 |
| Mark Beierl | b6d802a | 2022-09-20 13:10:38 -0400 | [diff] [blame] | 24 | OSMCLIENT_VERSION=12.0 |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 25 | IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 26 | PASSWORD_OVERLAY_FILE=~/.osm/password-overlay.yaml |
| beierlm | f2782c5 | 2020-11-05 17:04:05 -0500 | [diff] [blame] | 27 | PATH=/snap/bin:${PATH} |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 28 | OSM_DEVOPS="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. &> /dev/null && pwd )" |
| 29 | if [ -f ${OSM_DEVOPS}/common/all_funcs ] ; then |
| 30 | source ${OSM_DEVOPS}/common/all_funcs |
| 31 | else |
| 32 | function track(){ |
| 33 | true |
| 34 | } |
| 35 | function FATAL_TRACK(){ |
| 36 | exit 1 |
| 37 | } |
| 38 | fi |
| beierlm | f2782c5 | 2020-11-05 17:04:05 -0500 | [diff] [blame] | 39 | |
| David Garcia | ef349d9 | 2020-12-10 21:16:12 +0100 | [diff] [blame] | 40 | MODEL_NAME=osm |
| 41 | |
| David Garcia | 4a0db7c | 2022-02-21 11:48:11 +0100 | [diff] [blame] | 42 | OSM_BUNDLE=ch:osm |
| 43 | OSM_HA_BUNDLE=ch:osm-ha |
| aticig | 4eb45c9 | 2022-08-11 13:10:19 +0300 | [diff] [blame] | 44 | CHARMHUB_CHANNEL=12.0/stable |
| David Garcia | 4a0db7c | 2022-02-21 11:48:11 +0100 | [diff] [blame] | 45 | unset TAG |
| David Garcia | ab11f84 | 2020-12-16 17:25:15 +0100 | [diff] [blame] | 46 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 47 | function check_arguments(){ |
| 48 | while [ $# -gt 0 ] ; do |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 49 | case $1 in |
| 50 | --bundle) BUNDLE="$2" ;; |
| David Garcia | 4bd2bf0 | 2021-05-05 19:01:43 +0200 | [diff] [blame] | 51 | --overlay) OVERLAY="$2" ;; |
| Dominik Fleischmann | 7a97a4c | 2020-06-04 10:52:05 +0200 | [diff] [blame] | 52 | --k8s) KUBECFG="$2" ;; |
| 53 | --vca) CONTROLLER="$2" ;; |
| aticig | 5d19ac2 | 2022-05-06 13:46:22 +0300 | [diff] [blame] | 54 | --small-profile) INSTALL_NOLXD=y;; |
| Dominik Fleischmann | 7a97a4c | 2020-06-04 10:52:05 +0200 | [diff] [blame] | 55 | --lxd) LXD_CLOUD="$2" ;; |
| 56 | --lxd-cred) LXD_CREDENTIALS="$2" ;; |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 57 | --microstack) MICROSTACK=y ;; |
| David Garcia | ab11f84 | 2020-12-16 17:25:15 +0100 | [diff] [blame] | 58 | --ha) BUNDLE=$OSM_HA_BUNDLE ;; |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 59 | --tag) TAG="$2" ;; |
| beierlm | f2782c5 | 2020-11-05 17:04:05 -0500 | [diff] [blame] | 60 | --registry) REGISTRY_INFO="$2" ;; |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 61 | --only-vca) ONLY_VCA=y ;; |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 62 | esac |
| 63 | shift |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 64 | done |
| 65 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 66 | # echo $BUNDLE $KUBECONFIG $LXDENDPOINT |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 67 | } |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 68 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 69 | function install_snaps(){ |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 70 | if [ ! -v KUBECFG ]; then |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 71 | KUBEGRP="microk8s" |
| 72 | sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable || |
| 73 | FATAL_TRACK k8scluster "snap install microk8s ${MICROK8S_VERSION}/stable failed" |
| 74 | sudo usermod -a -G microk8s `whoami` |
| David Garcia | 9a59e3d | 2021-02-08 15:18:27 +0100 | [diff] [blame] | 75 | sudo cat /var/snap/microk8s/current/args/kube-apiserver | grep advertise-address || ( |
| David Garcia | 107010b | 2021-01-15 12:58:59 +0100 | [diff] [blame] | 76 | echo "--advertise-address $DEFAULT_IP" | sudo tee -a /var/snap/microk8s/current/args/kube-apiserver |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 77 | sg ${KUBEGRP} -c microk8s.stop |
| 78 | sg ${KUBEGRP} -c microk8s.start |
| David Garcia | 107010b | 2021-01-15 12:58:59 +0100 | [diff] [blame] | 79 | ) |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 80 | mkdir -p ~/.kube |
| 81 | sudo chown -f -R `whoami` ~/.kube |
| beierlm | f2782c5 | 2020-11-05 17:04:05 -0500 | [diff] [blame] | 82 | sg ${KUBEGRP} -c "microk8s status --wait-ready" |
| beierlm | df6de3d | 2020-12-16 08:46:40 -0500 | [diff] [blame] | 83 | KUBECONFIG=~/.osm/microk8s-config.yaml |
| David Garcia | 107010b | 2021-01-15 12:58:59 +0100 | [diff] [blame] | 84 | sg ${KUBEGRP} -c "microk8s config" | tee ${KUBECONFIG} |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 85 | track k8scluster k8scluster_ok |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 86 | else |
| 87 | KUBECTL="kubectl" |
| 88 | sudo snap install kubectl --classic |
| 89 | export KUBECONFIG=${KUBECFG} |
| 90 | KUBEGRP=$(id -g -n) |
| 91 | fi |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 92 | sudo snap install juju --classic --channel=$JUJU_VERSION/stable || |
| 93 | FATAL_TRACK juju "snap install juju ${JUJU_VERSION}/stable failed" |
| 94 | track juju juju_ok |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | function bootstrap_k8s_lxd(){ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 98 | [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 99 | [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca" |
| 100 | |
| 101 | if [ -v BOOTSTRAP_NEEDED ]; then |
| 102 | CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l) |
| 103 | if [ $CONTROLLER_PRESENT -ge 1 ]; then |
| 104 | cat << EOF |
| 105 | Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}". |
| 106 | You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it |
| 107 | using this command: |
| 108 | |
| 109 | juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME} |
| 110 | |
| 111 | Please retry the installation once this conflict has been resolved. |
| 112 | EOF |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 113 | FATAL_TRACK bootstrap_k8s "VCA already present" |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 114 | fi |
| beierlm | 9afb0ef | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 115 | else |
| 116 | CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l) |
| 117 | if [ $CONTROLLER_PRESENT -le 0 ]; then |
| 118 | cat << EOF |
| 119 | Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA |
| 120 | that exists, or remove the --vca ${CONTROLLER_NAME} option. |
| 121 | |
| 122 | Please retry the installation with one of the solutions applied. |
| 123 | EOF |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 124 | FATAL_TRACK bootstrap_k8s "Requested VCA not present" |
| beierlm | 9afb0ef | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 125 | fi |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 126 | fi |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 127 | |
| 128 | if [ -v KUBECFG ]; then |
| 129 | cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS |
| beierlm | 2634cd3 | 2020-09-15 16:00:34 -0400 | [diff] [blame] | 130 | [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \ |
| 131 | --config controller-service-type=loadbalancer \ |
| David Garcia | a137601 | 2020-10-19 15:42:42 +0200 | [diff] [blame] | 132 | --agent-version=$JUJU_AGENT_VERSION |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 133 | else |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 134 | sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb" |
| beierlm | 9afb0ef | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 135 | sg ${KUBEGRP} -c "microk8s.enable ingress" |
| Patricia Reinoso | 0788ee1 | 2023-03-14 16:06:32 +0000 | [diff] [blame] | 136 | sg ${KUBEGRP} -c "microk8s.enable hostpath-storage dns" |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 137 | TIME_TO_WAIT=30 |
| 138 | start_time="$(date -u +%s)" |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 139 | while true |
| 140 | do |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 141 | now="$(date -u +%s)" |
| 142 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| 143 | echo "Microk8s storage failed to enable" |
| 144 | sg ${KUBEGRP} -c "microk8s.status" |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 145 | FATAL_TRACK bootstrap_k8s "Microk8s storage failed to enable" |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 146 | fi |
| 147 | storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"` |
| 148 | if [[ $storage_status == "enabled" ]]; then |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 149 | break |
| 150 | fi |
| 151 | sleep 1 |
| 152 | done |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 153 | |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 154 | [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS |
| beierlm | 2634cd3 | 2020-09-15 16:00:34 -0400 | [diff] [blame] | 155 | [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \ |
| David Garcia | a137601 | 2020-10-19 15:42:42 +0200 | [diff] [blame] | 156 | "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \ |
| beierlm | 2634cd3 | 2020-09-15 16:00:34 -0400 | [diff] [blame] | 157 | && K8S_CLOUD_NAME=microk8s |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 158 | fi |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 159 | track bootstrap_k8s bootstrap_k8s_ok |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 160 | |
| aticig | 5d19ac2 | 2022-05-06 13:46:22 +0300 | [diff] [blame] | 161 | if [ ! -v INSTALL_NOLXD ]; then |
| 162 | if [ -v LXD_CLOUD ]; then |
| 163 | if [ ! -v LXD_CREDENTIALS ]; then |
| 164 | echo "The installer needs the LXD server certificate if the LXD is external" |
| 165 | FATAL_TRACK bootstrap_lxd "No LXD certificate supplied" |
| 166 | fi |
| 167 | else |
| 168 | LXDENDPOINT=$DEFAULT_IP |
| 169 | LXD_CLOUD=~/.osm/lxd-cloud.yaml |
| 170 | LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml |
| 171 | # Apply sysctl production values for optimal performance |
| 172 | sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf |
| 173 | sudo sysctl --system |
| 174 | # Install LXD snap |
| 175 | sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client |
| 176 | sudo snap install lxd --channel $LXD_VERSION/stable |
| 177 | # Configure LXD |
| 178 | sudo usermod -a -G lxd `whoami` |
| 179 | cat /usr/share/osm-devops/installers/lxd-preseed.conf | sed 's/^config: {}/config:\n core.https_address: '$LXDENDPOINT':8443/' | sg lxd -c "lxd init --preseed" |
| 180 | sg lxd -c "lxd waitready" |
| 181 | DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') |
| 182 | sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU" |
| 183 | sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 184 | |
| aticig | 5d19ac2 | 2022-05-06 13:46:22 +0300 | [diff] [blame] | 185 | cat << EOF > $LXD_CLOUD |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 186 | clouds: |
| 187 | lxd-cloud: |
| 188 | type: lxd |
| 189 | auth-types: [certificate] |
| 190 | endpoint: "https://$LXDENDPOINT:8443" |
| 191 | config: |
| 192 | ssl-hostname-verification: false |
| 193 | EOF |
| aticig | 5d19ac2 | 2022-05-06 13:46:22 +0300 | [diff] [blame] | 194 | openssl req -nodes -new -x509 -keyout ~/.osm/client.key -out ~/.osm/client.crt -days 365 -subj "/C=FR/ST=Nice/L=Nice/O=ETSI/OU=OSM/CN=osm.etsi.org" |
| aticig | 5d19ac2 | 2022-05-06 13:46:22 +0300 | [diff] [blame] | 195 | cat << EOF > $LXD_CREDENTIALS |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 196 | credentials: |
| 197 | lxd-cloud: |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 198 | lxd-cloud: |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 199 | auth-type: certificate |
| David Garcia | f82897c | 2022-06-01 13:01:43 +0200 | [diff] [blame] | 200 | server-cert: /var/snap/lxd/common/lxd/server.crt |
| 201 | client-cert: ~/.osm/client.crt |
| 202 | client-key: ~/.osm/client.key |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 203 | EOF |
| aticig | 5d19ac2 | 2022-05-06 13:46:22 +0300 | [diff] [blame] | 204 | lxc config trust add local: ~/.osm/client.crt |
| 205 | fi |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 206 | |
| aticig | 5d19ac2 | 2022-05-06 13:46:22 +0300 | [diff] [blame] | 207 | juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force |
| 208 | juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS |
| 209 | sg lxd -c "lxd waitready" |
| 210 | juju controller-config features=[k8s-operators] |
| 211 | track bootstrap_lxd bootstrap_lxd_ok |
| 212 | fi |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | function deploy_charmed_osm(){ |
| beierlm | f2782c5 | 2020-11-05 17:04:05 -0500 | [diff] [blame] | 216 | if [ -v REGISTRY_INFO ] ; then |
| 217 | registry_parts=(${REGISTRY_INFO//@/ }) |
| 218 | if [ ${#registry_parts[@]} -eq 1 ] ; then |
| 219 | # No credentials supplied |
| 220 | REGISTRY_USERNAME="" |
| 221 | REGISTRY_PASSWORD="" |
| 222 | REGISTRY_URL=${registry_parts[0]} |
| 223 | else |
| 224 | credentials=${registry_parts[0]} |
| 225 | credential_parts=(${credentials//:/ }) |
| 226 | REGISTRY_USERNAME=${credential_parts[0]} |
| 227 | REGISTRY_PASSWORD=${credential_parts[1]} |
| 228 | REGISTRY_URL=${registry_parts[1]} |
| 229 | fi |
| 230 | # Ensure the URL ends with a / |
| 231 | case $REGISTRY_URL in |
| 232 | */) ;; |
| 233 | *) REGISTRY_URL=${REGISTRY_URL}/ |
| 234 | esac |
| 235 | fi |
| 236 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 237 | echo "Creating OSM model" |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 238 | if [ -v KUBECFG ]; then |
| David Garcia | ef349d9 | 2020-12-10 21:16:12 +0100 | [diff] [blame] | 239 | juju add-model $MODEL_NAME $K8S_CLOUD_NAME |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 240 | else |
| David Garcia | ef349d9 | 2020-12-10 21:16:12 +0100 | [diff] [blame] | 241 | sg ${KUBEGRP} -c "juju add-model $MODEL_NAME $K8S_CLOUD_NAME" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 242 | fi |
| 243 | echo "Deploying OSM with charms" |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 244 | images_overlay="" |
| beierlm | f2782c5 | 2020-11-05 17:04:05 -0500 | [diff] [blame] | 245 | if [ -v REGISTRY_URL ]; then |
| 246 | [ ! -v TAG ] && TAG='latest' |
| 247 | fi |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 248 | [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE" |
| beierlm | f2782c5 | 2020-11-05 17:04:05 -0500 | [diff] [blame] | 249 | |
| David Garcia | 4bd2bf0 | 2021-05-05 19:01:43 +0200 | [diff] [blame] | 250 | if [ -v OVERLAY ]; then |
| 251 | extra_overlay="--overlay $OVERLAY" |
| 252 | fi |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 253 | echo "Creating Password Overlay" |
| 254 | |
| 255 | generate_password_overlay && secret_overlay="--overlay $PASSWORD_OVERLAY_FILE" |
| David Garcia | 4bd2bf0 | 2021-05-05 19:01:43 +0200 | [diff] [blame] | 256 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 257 | if [ -v BUNDLE ]; then |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 258 | juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay $secret_overlay |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 259 | else |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 260 | juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $OSM_BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay $extra_overlay $secret_overlay |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 261 | fi |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 262 | |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 263 | if [ ! -v KUBECFG ]; then |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 264 | API_SERVER=${DEFAULT_IP} |
| 265 | else |
| 266 | API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ") |
| 267 | proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')" |
| 268 | url="$(echo ${API_SERVER/$proto/})" |
| 269 | user="$(echo $url | grep @ | cut -d@ -f1)" |
| 270 | hostport="$(echo ${url/$user@/} | cut -d/ -f1)" |
| 271 | API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')" |
| 272 | fi |
| David Garcia | de5fc1d | 2020-09-02 11:40:12 +0200 | [diff] [blame] | 273 | # Expose OSM services |
| David Garcia | c395a45 | 2021-05-05 14:22:26 +0200 | [diff] [blame] | 274 | juju config -m $MODEL_NAME nbi site_url=https://nbi.${API_SERVER}.nip.io |
| 275 | juju config -m $MODEL_NAME ng-ui site_url=https://ui.${API_SERVER}.nip.io |
| 276 | juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io |
| 277 | juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io |
| David Garcia | ef349d9 | 2020-12-10 21:16:12 +0100 | [diff] [blame] | 278 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 279 | echo "Waiting for deployment to finish..." |
| 280 | check_osm_deployed |
| David Garcia | c537fa6 | 2021-11-09 08:45:49 +0100 | [diff] [blame] | 281 | grafana_leader=`juju status -m $MODEL_NAME grafana | grep "*" | cut -d "*" -f 1` |
| 282 | grafana_admin_password=`juju run -m $MODEL_NAME --unit $grafana_leader "echo \\$GF_SECURITY_ADMIN_PASSWORD"` |
| 283 | juju config -m $MODEL_NAME mon grafana_password=$grafana_admin_password |
| 284 | check_osm_deployed |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 285 | echo "OSM with charms deployed" |
| beierlm | 9afb0ef | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 286 | } |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 287 | |
| 288 | function check_osm_deployed() { |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 289 | TIME_TO_WAIT=600 |
| 290 | start_time="$(date -u +%s)" |
| David Garcia | 02a5eb9 | 2020-11-28 14:41:22 +0100 | [diff] [blame] | 291 | total_service_count=14 |
| beierlm | 7e54dfc | 2020-09-24 15:27:53 -0400 | [diff] [blame] | 292 | previous_count=0 |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 293 | while true |
| 294 | do |
| beierlm | 67a3447 | 2022-03-25 12:23:36 -0400 | [diff] [blame] | 295 | service_count=$(juju status --format json -m $MODEL_NAME | jq '.applications[]."application-status".current' | grep active | wc -l) |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 296 | echo "$service_count / $total_service_count services active" |
| 297 | if [ $service_count -eq $total_service_count ]; then |
| 298 | break |
| 299 | fi |
| beierlm | 7e54dfc | 2020-09-24 15:27:53 -0400 | [diff] [blame] | 300 | if [ $service_count -ne $previous_count ]; then |
| 301 | previous_count=$service_count |
| 302 | start_time="$(date -u +%s)" |
| 303 | fi |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 304 | now="$(date -u +%s)" |
| 305 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| 306 | echo "Timed out waiting for OSM services to become ready" |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 307 | FATAL_TRACK deploy_osm "Timed out waiting for services to become ready" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 308 | fi |
| 309 | sleep 10 |
| 310 | done |
| 311 | } |
| 312 | |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 313 | function generate_password_overlay() { |
| 314 | # prometheus |
| David Garcia | 8fa7807 | 2022-04-27 13:43:42 +0200 | [diff] [blame] | 315 | web_config_password=`openssl rand -hex 16` |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 316 | # keystone |
| David Garcia | 8fa7807 | 2022-04-27 13:43:42 +0200 | [diff] [blame] | 317 | keystone_db_password=`openssl rand -hex 16` |
| 318 | keystone_admin_password=`openssl rand -hex 16` |
| 319 | keystone_service_password=`openssl rand -hex 16` |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 320 | # mariadb |
| 321 | mariadb_password=`openssl rand -hex 16` |
| 322 | mariadb_root_password=`openssl rand -hex 16` |
| 323 | cat << EOF > /tmp/password-overlay.yaml |
| 324 | applications: |
| 325 | prometheus: |
| 326 | options: |
| 327 | web_config_password: $web_config_password |
| 328 | keystone: |
| 329 | options: |
| 330 | keystone-db-password: $keystone_db_password |
| 331 | admin-password: $keystone_admin_password |
| 332 | service-password: $keystone_service_password |
| 333 | mariadb: |
| 334 | options: |
| 335 | password: $mariadb_password |
| 336 | root_password: $mariadb_root_password |
| 337 | EOF |
| 338 | mv /tmp/password-overlay.yaml $PASSWORD_OVERLAY_FILE |
| 339 | } |
| 340 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 341 | function create_overlay() { |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 342 | sudo snap install jq |
| David Garcia | c8660ad | 2020-12-16 13:13:20 +0100 | [diff] [blame] | 343 | sudo snap install yq |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 344 | local HOME=/home/$USER |
| calvinosanc1 | 83ea27a | 2021-01-04 11:42:18 +0100 | [diff] [blame] | 345 | local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - ) |
| David Garcia | c753dc5 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 346 | local vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - ) |
| calvinosanc1 | 83ea27a | 2021-01-04 11:42:18 +0100 | [diff] [blame] | 347 | local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1) |
| 348 | local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2) |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 349 | local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\" |
| 350 | local vca_cloud="lxd-cloud" |
| 351 | # Get the VCA Certificate |
| calvinosanc1 | 83ea27a | 2021-01-04 11:42:18 +0100 | [diff] [blame] | 352 | local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n) |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 353 | |
| 354 | # Calculate the default route of this machine |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 355 | local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 356 | |
| 357 | # Generate a new overlay.yaml, overriding any existing one |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 358 | cat << EOF > /tmp/vca-overlay.yaml |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 359 | applications: |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 360 | lcm: |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 361 | options: |
| 362 | vca_user: $vca_user |
| David Garcia | c753dc5 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 363 | vca_secret: $vca_secret |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 364 | vca_host: $vca_host |
| 365 | vca_port: $vca_port |
| 366 | vca_pubkey: $vca_pubkey |
| 367 | vca_cacert: $vca_cacert |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 368 | vca_cloud: $vca_cloud |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 369 | vca_k8s_cloud: $K8S_CLOUD_NAME |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 370 | mon: |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 371 | options: |
| 372 | vca_user: $vca_user |
| David Garcia | c753dc5 | 2021-03-17 15:28:47 +0100 | [diff] [blame] | 373 | vca_secret: $vca_secret |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 374 | vca_host: $vca_host |
| 375 | vca_cacert: $vca_cacert |
| 376 | EOF |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 377 | mv /tmp/vca-overlay.yaml ~/.osm/ |
| 378 | OSM_VCA_HOST=$vca_host |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 379 | } |
| 380 | |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 381 | function generate_images_overlay(){ |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 382 | echo "applications:" > /tmp/images-overlay.yaml |
| beierlm | f2782c5 | 2020-11-05 17:04:05 -0500 | [diff] [blame] | 383 | |
| David Garcia | 53a09d8 | 2022-02-01 16:39:44 +0100 | [diff] [blame] | 384 | charms_with_resources="nbi lcm mon pol ng-ui ro pla" |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 385 | for charm in $charms_with_resources; do |
| 386 | cat << EOF > /tmp/${charm}_registry.yaml |
| 387 | registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG |
| beierlm | f2782c5 | 2020-11-05 17:04:05 -0500 | [diff] [blame] | 388 | EOF |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 389 | if [ ! -z "$REGISTRY_USERNAME" ] ; then |
| 390 | echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml |
| 391 | echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml |
| 392 | fi |
| beierlm | f2782c5 | 2020-11-05 17:04:05 -0500 | [diff] [blame] | 393 | |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 394 | cat << EOF >> /tmp/images-overlay.yaml |
| 395 | ${charm}: |
| David Garcia | ef349d9 | 2020-12-10 21:16:12 +0100 | [diff] [blame] | 396 | resources: |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 397 | image: /tmp/${charm}_registry.yaml |
| 398 | |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 399 | EOF |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 400 | done |
| David Garcia | 53a09d8 | 2022-02-01 16:39:44 +0100 | [diff] [blame] | 401 | ch_charms_with_resources="keystone" |
| 402 | for charm in $ch_charms_with_resources; do |
| 403 | cat << EOF > /tmp/${charm}_registry.yaml |
| 404 | registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG |
| 405 | EOF |
| 406 | if [ ! -z "$REGISTRY_USERNAME" ] ; then |
| 407 | echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml |
| 408 | echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml |
| 409 | fi |
| 410 | |
| 411 | cat << EOF >> /tmp/images-overlay.yaml |
| 412 | ${charm}: |
| 413 | resources: |
| 414 | ${charm}-image: /tmp/${charm}_registry.yaml |
| 415 | |
| 416 | EOF |
| 417 | done |
| David Garcia | 49379ce | 2021-02-24 13:48:22 +0100 | [diff] [blame] | 418 | |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 419 | mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE |
| 420 | } |
| 421 | |
| David Garcia | 107010b | 2021-01-15 12:58:59 +0100 | [diff] [blame] | 422 | function refresh_osmclient_snap() { |
| 423 | osmclient_snap_install_refresh refresh |
| 424 | } |
| 425 | |
| 426 | function install_osm_client_snap() { |
| 427 | osmclient_snap_install_refresh install |
| 428 | } |
| 429 | |
| 430 | function osmclient_snap_install_refresh() { |
| 431 | channel_preference="stable candidate beta edge" |
| 432 | for channel in $channel_preference; do |
| 433 | echo "Trying to install osmclient from channel $OSMCLIENT_VERSION/$channel" |
| 434 | sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break |
| 435 | done |
| 436 | } |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 437 | function install_osmclient() { |
| David Garcia | 107010b | 2021-01-15 12:58:59 +0100 | [diff] [blame] | 438 | snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 439 | } |
| 440 | |
| beierlm | df6de3d | 2020-12-16 08:46:40 -0500 | [diff] [blame] | 441 | function add_local_k8scluster() { |
| 442 | osm --all-projects vim-create \ |
| 443 | --name _system-osm-vim \ |
| 444 | --account_type dummy \ |
| 445 | --auth_url http://dummy \ |
| 446 | --user osm --password osm --tenant osm \ |
| 447 | --description "dummy" \ |
| 448 | --config '{management_network_name: mgmt}' |
| 449 | tmpfile=$(mktemp --tmpdir=${HOME}) |
| 450 | cp ${KUBECONFIG} ${tmpfile} |
| 451 | osm --all-projects k8scluster-add \ |
| 452 | --creds ${tmpfile} \ |
| 453 | --vim _system-osm-vim \ |
| 454 | --k8s-nets '{"net1": null}' \ |
| 455 | --version '1.19' \ |
| 456 | --description "OSM Internal Cluster" \ |
| 457 | _system-osm-k8s |
| 458 | rm -f ${tmpfile} |
| 459 | } |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 460 | |
| 461 | function install_microstack() { |
| beierlm | b403f06 | 2021-12-09 08:47:59 -0500 | [diff] [blame] | 462 | sudo snap install microstack --beta --devmode |
| 463 | |
| 464 | CHECK=$(microstack.openstack server list) |
| 465 | if [ $? -ne 0 ] ; then |
| 466 | if [[ $CHECK == *"not initialized"* ]]; then |
| 467 | echo "Setting MicroStack dashboard to listen to port 8080" |
| 468 | sudo snap set microstack config.network.ports.dashboard=8080 |
| 469 | echo "Initializing MicroStack. This can take several minutes" |
| 470 | sudo microstack.init --auto --control |
| 471 | fi |
| 472 | fi |
| 473 | |
| 474 | sudo snap alias microstack.openstack openstack |
| 475 | |
| 476 | echo "Updating default security group in MicroStack to allow all access" |
| 477 | |
| 478 | for i in $(microstack.openstack security group list | awk '/default/{ print $2 }'); do |
| 479 | for PROTO in icmp tcp udp ; do |
| 480 | echo " $PROTO ingress" |
| 481 | CHECK=$(microstack.openstack security group rule create $i --protocol $PROTO --remote-ip 0.0.0.0/0 2>&1) |
| 482 | if [ $? -ne 0 ] ; then |
| 483 | if [[ $CHECK != *"409"* ]]; then |
| 484 | echo "Error creating ingress rule for $PROTO" |
| 485 | echo $CHECK |
| 486 | fi |
| 487 | fi |
| 488 | done |
| 489 | done |
| 490 | |
| 491 | microstack.openstack network show osm-ext &>/dev/null |
| 492 | if [ $? -ne 0 ]; then |
| 493 | echo "Creating osm-ext network with router to bridge to MicroStack external network" |
| 494 | microstack.openstack network create --enable --no-share osm-ext |
| 495 | microstack.openstack subnet create osm-ext-subnet --network osm-ext --dns-nameserver 8.8.8.8 \ |
| 496 | --subnet-range 172.30.0.0/24 |
| 497 | microstack.openstack router create external-router |
| 498 | microstack.openstack router add subnet external-router osm-ext-subnet |
| 499 | microstack.openstack router set --external-gateway external external-router |
| 500 | fi |
| 501 | |
| 502 | microstack.openstack image list | grep ubuntu20.04 &> /dev/null |
| 503 | if [ $? -ne 0 ] ; then |
| 504 | echo "Fetching Ubuntu 20.04 image and upLoading to MicroStack" |
| 505 | wget -q -O- https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img \ |
| 506 | | microstack.openstack image create --public --container-format=bare \ |
| 507 | --disk-format=qcow2 ubuntu20.04 | grep status |
| 508 | fi |
| 509 | |
| 510 | if [ ! -f ~/.ssh/microstack ]; then |
| 511 | ssh-keygen -t rsa -N "" -f ~/.ssh/microstack |
| 512 | microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack |
| 513 | fi |
| 514 | |
| 515 | echo "Creating VIM microstack-site in OSM" |
| 516 | . /var/snap/microstack/common/etc/microstack.rc |
| 517 | |
| 518 | osm vim-create \ |
| 519 | --name microstack-site \ |
| 520 | --user "$OS_USERNAME" \ |
| 521 | --password "$OS_PASSWORD" \ |
| 522 | --auth_url "$OS_AUTH_URL" \ |
| 523 | --tenant "$OS_USERNAME" \ |
| 524 | --account_type openstack \ |
| 525 | --config='{use_floating_ip: True, |
| 526 | insecure: True, |
| 527 | keypair: microstack, |
| 528 | management_network_name: osm-ext}' |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 529 | } |
| 530 | |
| beierlm | 4aad47b | 2021-12-07 16:15:53 -0500 | [diff] [blame] | 531 | DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5; exit}'` |
| 532 | DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]; exit}'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 533 | |
| 534 | check_arguments $@ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 535 | mkdir -p ~/.osm |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 536 | install_snaps |
| 537 | bootstrap_k8s_lxd |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 538 | create_overlay |
| 539 | if [ -v ONLY_VCA ]; then |
| 540 | HOME=/home/$USER |
| 541 | vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.user - ) |
| 542 | vca_secret=$(cat $HOME/.local/share/juju/accounts.yaml | yq e .controllers.$CONTROLLER_NAME.password - ) |
| 543 | vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 1) |
| 544 | vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.api-endpoints[0] - | cut -d ":" -f 2) |
| 545 | vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\" |
| 546 | vca_cloud="lxd-cloud" |
| 547 | vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq e .controllers.$CONTROLLER_NAME.ca-cert - | base64 | tr -d \\n) |
| 548 | hostname=`cat /etc/hostname` |
| beierlm | df6de3d | 2020-12-16 08:46:40 -0500 | [diff] [blame] | 549 | |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 550 | echo "Use the following command to register the installed VCA to your OSM:" |
| David Garcia | d68e0b4 | 2021-06-28 16:50:42 +0200 | [diff] [blame] | 551 | 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" |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 552 | track deploy_osm deploy_vca_only_ok |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 553 | else |
| 554 | deploy_charmed_osm |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 555 | track deploy_osm deploy_osm_services_k8s_ok |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 556 | install_osmclient |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 557 | track osmclient osmclient_ok |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 558 | export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s/http.*\?:\/\///"):443 |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 559 | export OSM_PASSWORD=$keystone_admin_password |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 560 | sleep 10 |
| 561 | add_local_k8scluster |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 562 | track final_ops add_local_k8scluster_ok |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 563 | if [ -v MICROSTACK ]; then |
| 564 | install_microstack |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 565 | track final_ops install_microstack_ok |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 566 | fi |
| 567 | |
| 568 | echo "Your installation is now complete, follow these steps for configuring the osmclient:" |
| 569 | echo |
| 570 | echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP" |
| 571 | echo |
| 572 | echo "export OSM_HOSTNAME=$OSM_HOSTNAME" |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 573 | echo "export OSM_PASSWORD=$OSM_PASSWORD" |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 574 | echo |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 575 | echo "2. Add the previous commands to your .bashrc for other Shell sessions" |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 576 | echo |
| 577 | echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc" |
| aticig | 6eb3928 | 2022-02-24 00:34:52 +0300 | [diff] [blame] | 578 | echo "echo \"export OSM_PASSWORD=$OSM_PASSWORD\" >> ~/.bashrc" |
| 579 | echo |
| 580 | echo "3. Login OSM GUI by using admin password: $OSM_PASSWORD" |
| David Garcia | 1bc7102 | 2021-05-03 18:27:18 +0200 | [diff] [blame] | 581 | echo |
| 582 | echo "DONE" |
| beierlm | ce7b460 | 2022-04-13 08:19:40 -0400 | [diff] [blame] | 583 | track end |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 584 | fi |
| beierlm | a4a37f7 | 2020-06-26 12:55:01 -0400 | [diff] [blame] | 585 | |