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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 K8S_CLOUD_NAME
="k8s-cloud"
20 function check_arguments
(){
21 while [ $# -gt 0 ] ; do
23 --bundle) BUNDLE
="$2" ;;
24 --kubeconfig) KUBECFG
="$2" ;;
25 --controller) CONTROLLER
="$2" ;;
26 --lxd-cloud) LXD_CLOUD
="$2" ;;
27 --lxd-credentials) LXD_CREDENTIALS
="$2" ;;
28 --microstack) MICROSTACK
=y
33 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
35 function install_snaps
(){
36 sudo snap
install juju
--classic
37 [ ! -v KUBECFG
] && sudo snap
install microk8s
--classic && sudo usermod
-a -G microk8s ubuntu
&& mkdir
-p ~
/.kube
&& sudo chown
-f -R `whoami` ~
/.kube
40 function bootstrap_k8s_lxd
(){
41 [ -v CONTROLLER
] && ADD_K8S_OPTS
="--controller ${CONTROLLER}" && CONTROLLER_NAME
=$CONTROLLER
42 [ ! -v CONTROLLER
] && ADD_K8S_OPTS
="--client" && BOOTSTRAP_NEEDED
="yes" && CONTROLLER_NAME
="controller"
44 if [ -v KUBECFG
]; then
45 cat $KUBECFG | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
46 [ -v BOOTSTRAP_NEEDED
] && juju bootstrap
$K8S_CLOUD_NAME $CONTROLLER_NAME
48 sg microk8s
-c "microk8s.enable storage dns"
50 [ ! -v BOOTSTRAP_NEEDED
] && sg microk8s
-c "microk8s.config" | juju add-k8s
$K8S_CLOUD_NAME $ADD_K8S_OPTS
51 [ -v BOOTSTRAP_NEEDED
] && sg microk8s
-c "juju bootstrap microk8s $CONTROLLER_NAME" && K8S_CLOUD_NAME
=microk8s
54 if [ -v LXD_CLOUD
]; then
55 if [ ! -v LXD_CREDENTIALS
]; then
56 echo "The installer needs the LXD server certificate if the LXD is external"
60 LXDENDPOINT
=$DEFAULT_IP
61 LXD_CLOUD
=~
/.osm
/lxd-cloud.yaml
62 LXD_CREDENTIALS
=~
/.osm
/lxd-credentials.yaml
63 # Apply sysctl production values for optimal performance
64 sudo
cp /usr
/share
/osm-devops
/installers
/60-lxd-production.conf
/etc
/sysctl.d
/60-lxd-production.conf
67 sudo apt-get remove
--purge -y liblxc1 lxc-common lxcfs lxd lxd-client
69 sudo apt-get
install zfsutils-linux
-y
71 sudo usermod
-a -G lxd
`whoami`
72 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"
73 sg lxd
-c "lxd waitready"
74 DEFAULT_MTU
=$
(ip addr show
$DEFAULT_IF | perl
-ne 'if (/mtu\s(\d+)/) {print $1;}')
75 sg lxd
-c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
77 cat << EOF > $LXD_CLOUD
81 auth-types: [certificate]
82 endpoint: "https://$LXDENDPOINT:8443"
84 ssl-hostname-verification: false
86 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"
87 local server_cert
=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'`
88 local client_cert
=`cat ~/.osm/client.crt | sed 's/^/ /'`
89 local client_key
=`cat ~/.osm/client.key | sed 's/^/ /'`
91 cat << EOF > $LXD_CREDENTIALS
95 auth-type: certificate
103 lxc config trust add
local: ~
/.osm
/client.crt
106 juju add-cloud
-c $CONTROLLER_NAME lxd-cloud
$LXD_CLOUD --force
107 juju add-credential
-c $CONTROLLER_NAME lxd-cloud
-f $LXD_CREDENTIALS
108 sg lxd
-c "lxd waitready"
109 juju add-model
test lxd-cloud || true
112 function deploy_charmed_osm
(){
114 echo "Creating OSM model"
115 if [ -v KUBECFG
]; then
116 juju add-model osm
$K8S_CLOUD_NAME
118 sg microk8s
-c "juju add-model osm $K8S_CLOUD_NAME"
120 echo "Deploying OSM with charms"
122 if [ -v BUNDLE
]; then
123 juju deploy
$BUNDLE --overlay ~
/.osm
/vca-overlay.yaml
125 juju deploy osm
--overlay ~
/.osm
/vca-overlay.yaml
127 echo "Waiting for deployment to finish..."
128 check_osm_deployed
&> /dev
/null
129 echo "OSM with charms deployed"
130 sg microk8s
-c "microk8s.enable ingress"
131 juju config ui-k8s juju-external-hostname
=osm.
$DEFAULT_IP.xip.io
135 function check_osm_deployed
() {
138 pod_name
=`sg microk8s -c "microk8s.kubectl -n osm get pods | grep ui-k8s | grep -v operator" | awk '{print $1}'`
139 if [[ `sg microk8s -c "microk8s.kubectl -n osm wait pod $pod_name --for condition=Ready"` ]]; then
140 if [[ `sg microk8s -c "microk8s.kubectl -n osm wait pod lcm-k8s-0 --for condition=Ready"` ]]; then
148 function create_overlay
() {
150 sudo apt
install python3-pip
-y
151 python3
-m pip
install yq
152 PATH
=$PATH:$HOME/.local
/bin
# make yq command available
153 local HOME
=/home
/$USER
154 local vca_user
=$
(cat $HOME/.local
/share
/juju
/accounts.yaml | yq
--arg CONTROLLER_NAME
$CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
155 local vca_password
=$
(cat $HOME/.local
/share
/juju
/accounts.yaml | yq
--arg CONTROLLER_NAME
$CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password')
156 local vca_host
=$
(cat $HOME/.local
/share
/juju
/controllers.yaml | yq
--arg CONTROLLER_NAME
$CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints"][0]' | cut
-d ":" -f 1 | cut
-d "\"" -f 2)
157 local vca_port
=$
(cat $HOME/.local
/share
/juju
/controllers.yaml | yq
--arg CONTROLLER_NAME
$CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints"][0]' | cut
-d ":" -f 2 | cut
-d "\"" -f 1)
158 local vca_pubkey
=\"$
(cat $HOME/.local
/share
/juju
/ssh
/juju_id_rsa.pub
)\"
159 local vca_cloud
="lxd-cloud"
160 # Get the VCA Certificate
161 local vca_cacert
=$
(cat $HOME/.local
/share
/juju
/controllers.yaml | yq
--arg CONTROLLER_NAME
$CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["ca-cert"]' | base64 |
tr -d \\n
)
163 # Calculate the default route of this machine
164 local DEFAULT_IF
=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
165 local vca_apiproxy
=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
167 # Generate a new overlay.yaml, overriding any existing one
168 cat << EOF > /tmp/vca-overlay.yaml
173 vca_password: $vca_password
176 vca_pubkey: $vca_pubkey
177 vca_cacert: $vca_cacert
178 vca_apiproxy: $vca_apiproxy
179 vca_cloud: $vca_cloud
183 vca_password: $vca_password
185 vca_cacert: $vca_cacert
187 mv /tmp
/vca-overlay.yaml ~
/.osm
/
188 OSM_VCA_HOST
=$vca_host
191 function install_osmclient
() {
192 sudo snap
install osmclient
193 sudo snap
alias osmclient.osm osm
196 function create_iptables
() {
197 check_install_iptables_persistent
199 if ! sudo iptables
-t nat
-C PREROUTING
-p tcp
-m tcp
-d $DEFAULT_IP --dport 17070 -j DNAT
--to-destination $OSM_VCA_HOST; then
200 sudo iptables
-t nat
-A PREROUTING
-p tcp
-m tcp
-d $DEFAULT_IP --dport 17070 -j DNAT
--to-destination $OSM_VCA_HOST
201 sudo netfilter-persistent save
205 function check_install_iptables_persistent
(){
206 echo -e "\nChecking required packages: iptables-persistent"
207 if ! dpkg
-l iptables-persistent
&>/dev
/null
; then
208 echo -e " Not installed.\nInstalling iptables-persistent requires root privileges"
209 echo iptables-persistent iptables-persistent
/autosave_v4 boolean true | sudo debconf-set-selections
210 echo iptables-persistent iptables-persistent
/autosave_v6 boolean true | sudo debconf-set-selections
211 sudo apt-get
-yq install iptables-persistent
215 function install_microstack
() {
216 sudo snap
install microstack
--classic --beta
217 sudo microstack.init
--auto
218 wget https
://cloud-images.ubuntu.com
/releases
/16.04/release
/ubuntu-16.04
-server-cloudimg-amd64-disk1.img
-P ~
/.osm
/
219 microstack.openstack image create \
221 --disk-format qcow2 \
222 --container-format bare \
223 --file ~
/.osm
/ubuntu-16.04
-server-cloudimg-amd64-disk1.img \
225 ssh-keygen
-t rsa
-N "" -f ~
/.ssh
/microstack
226 microstack.openstack keypair create
--public-key ~
/.ssh
/microstack.pub microstack
227 export OSM_HOSTNAME
=`juju status --format yaml | yq r - applications.nbi-k8s.address`
228 osm vim-create
--name microstack-site \
230 --password keystone \
231 --auth_url http
://10.20.20.1:5000/v3 \
233 --account_type openstack \
234 --config='{security_groups: default,
237 user_domain_name: default,
238 region_name: microstack,
240 availability_zone: nova,
244 DEFAULT_IF
=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
245 DEFAULT_IP
=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
252 [ ! -v CONTROLLER
] && create_iptables
254 if [ -v MICROSTACK
]; then