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.
15 function check_arguments
(){
16 while [ $# -gt 0 ] ; do
18 --bundle) BUNDLE
="$2" ;;
19 --kubeconfig) KUBECFG
="$2" ;;
20 --lxd-endpoint) LXDENDPOINT
="$2" ;;
21 --lxd-cert) LXDCERT
="$2" ;;
22 --microstack) MICROSTACK
=y
27 echo $BUNDLE $KUBECONFIG $LXDENDPOINT
29 function install_snaps
(){
30 sudo snap
install juju
--classic
31 if [ -z "$KUBECFG" ]; then sudo snap
install microk8s
--classic; fi
34 function bootstrap_k8s_lxd
(){
35 if [ -n "$KUBECFG" ]; then
36 echo "Using specified K8s"
37 cat $KUBECFG | juju add-k8s k8s-cluster
--client
38 juju bootstrap k8s-cluster controller
40 sudo microk8s.
enable storage dns
41 sudo usermod
-a -G microk8s ubuntu
42 sg microk8s
-c "juju bootstrap microk8s controller"
45 if [ -n "$LXDENDPOINT" ]; then
46 if [ -n "$LXDCERT" ]; then
48 local server_cert
=`cat $LXDCERT | sed 's/^/ /'`
50 echo "The installer needs the LXD server certificate if the LXD is external"
54 LXDENDPOINT
=$DEFAULT_IP
55 lxd init
--auto --network-address $LXDENDPOINT
56 lxc network
set lxdbr0 ipv6.address none
58 local server_cert
=`cat /var/lib/lxd/server.crt | sed 's/^/ /'`
61 sudo
cat << EOF > ~/.osm/lxd-cloud.yaml
65 auth-types: [certificate]
66 endpoint: "https://$LXDENDPOINT:8443"
68 ssl-hostname-verification: false
70 openssl req
-nodes -new -x509 -keyout ~
/.osm
/private.key
-out ~
/.osm
/publickey.crt
-days 365 -subj "/C=FR/ST=Nice/L=Nice/O=ETSI/OU=OSM/CN=osm.etsi.org"
73 local client_cert
=`cat ~/.osm/publickey.crt | sed 's/^/ /'`
74 local client_key
=`cat ~/.osm/private.key | sed 's/^/ /'`
76 sudo
cat << EOF > ~/.osm/lxd-credentials.yaml
80 auth-type: certificate
89 lxc config trust add
local: ~
/.osm
/publickey.crt
90 juju add-cloud
-c controller lxd-cloud ~
/.osm
/lxd-cloud.yaml
--force
91 juju add-credential
-c controller lxd-cloud
-f ~
/.osm
/lxd-credentials.yaml
92 juju add-model
test lxd-cloud
96 function deploy_charmed_osm
(){
98 echo "Creating OSM model"
99 if [ -n "$KUBECFG" ]; then
100 juju add-model osm-on-k8s k8s-cluster
102 sg microk8s
-c "juju add-model osm-on-k8s microk8s"
104 echo "Deploying OSM with charms"
106 if [ -n "$BUNDLE" ]; then
107 juju deploy
$BUNDLE --overlay ~
/.osm
/vca-overlay.yaml
109 juju deploy osm
--overlay ~
/.osm
/vca-overlay.yaml
111 echo "Waiting for deployment to finish..."
112 check_osm_deployed
&> /dev
/null
113 echo "OSM with charms deployed"
114 sudo microk8s.
enable ingress
115 juju config ui-k8s juju-external-hostname
=osm.
$DEFAULT_IP.xip.io
119 function check_osm_deployed
() {
122 pod_name
=`sg microk8s -c "microk8s.kubectl -n osm-on-k8s get pods | grep ui-k8s | grep -v operator" | awk '{print $1}'
125 if [[ `sg microk8s -c "microk8s.kubectl -n osm-on-k8s wait pod $pod_name --for condition=Ready"` ]]; then
126 if [[ `sg microk8s -c "microk8s.kubectl -n osm-on-k8s wait pod lcm-k8s-0 --for condition=Ready"` ]]; then
134 function create_overlay
() {
137 local YQ
="$SNAP/bin/yq"
138 local HOME
=/home
/$USER
139 local vca_user
=$
(cat $HOME/.local
/share
/juju
/accounts.yaml | yq r
- controllers.controller.user
)
140 local vca_password
=$
(cat $HOME/.local
/share
/juju
/accounts.yaml | yq r
- controllers.controller.password
)
141 local vca_host
=$
(cat $HOME/.local
/share
/juju
/controllers.yaml | yq r
- controllers.controller.api-endpoints
[0] | cut
-d ":" -f 1)
142 local vca_port
=$
(cat $HOME/.local
/share
/juju
/controllers.yaml | yq r
- controllers.controller.api-endpoints
[0] | cut
-d ":" -f 2)
143 local vca_pubkey
=\"$
(cat $HOME/.local
/share
/juju
/ssh
/juju_id_rsa.pub
)\"
144 local vca_cloud
="lxd-cloud"
145 # Get the VCA Certificate
146 local vca_cacert
=$
(cat $HOME/.local
/share
/juju
/controllers.yaml | yq r
- controllers.controller.ca-cert | base64 |
tr -d \\n
)
148 # Calculate the default route of this machine
149 local DEFAULT_IF
=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
150 local vca_apiproxy
=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
152 # Generate a new overlay.yaml, overriding any existing one
153 sudo
cat << EOF > /tmp/vca-overlay.yaml
158 vca_password: $vca_password
161 vca_pubkey: $vca_pubkey
162 vca_cacert: $vca_cacert
163 vca_apiproxy: $vca_apiproxy
164 vca_cloud: $vca_cloud
168 vca_password: $vca_password
170 vca_cacert: $vca_cacert
172 sudo
cp /tmp
/vca-overlay.yaml ~
/.osm
/
173 OSM_VCA_HOST
=$vca_host
176 function install_osmclient
() {
177 sudo snap
install osmclient
178 sudo snap
alias osmclient.osm osm
181 function create_iptables
() {
182 check_install_iptables_persistent
184 if ! sudo iptables
-t nat
-C PREROUTING
-p tcp
-m tcp
-d $DEFAULT_IP --dport 17070 -j DNAT
--to-destination $OSM_VCA_HOST; then
185 sudo iptables
-t nat
-A PREROUTING
-p tcp
-m tcp
-d $DEFAULT_IP --dport 17070 -j DNAT
--to-destination $OSM_VCA_HOST
186 sudo netfilter-persistent save
190 function check_install_iptables_persistent
(){
191 echo -e "\nChecking required packages: iptables-persistent"
192 if ! dpkg
-l iptables-persistent
&>/dev
/null
; then
193 echo -e " Not installed.\nInstalling iptables-persistent requires root privileges"
194 echo iptables-persistent iptables-persistent
/autosave_v4 boolean true | sudo debconf-set-selections
195 echo iptables-persistent iptables-persistent
/autosave_v6 boolean true | sudo debconf-set-selections
196 sudo apt-get
-yq install iptables-persistent
200 function install_microstack
() {
201 sudo snap
install microstack
--classic --beta
202 sudo microstack.init
--auto
203 wget https
://cloud-images.ubuntu.com
/releases
/16.04/release
/ubuntu-16.04
-server-cloudimg-amd64-disk1.img
-P ~
/.osm
/
204 microstack.openstack image create \
206 --disk-format qcow2 \
207 --container-format bare \
208 --file ~
/.osm
/ubuntu-16.04
-server-cloudimg-amd64-disk1.img \
210 ssh-keygen
-t rsa
-N "" -f ~
/.ssh
/microstack
211 microstack.openstack keypair create
--public-key ~
/.ssh
/microstack.pub microstack
212 export OSM_HOSTNAME
=`juju status --format yaml | yq r - applications.nbi-k8s.address`
213 osm vim-create
--name microstack-site \
215 --password keystone \
216 --auth_url http
://10.20.20.1:5000/v3 \
218 --account_type openstack \
219 --config='{security_groups: default,
222 user_domain_name: default,
223 region_name: microstack,
225 availability_zone: nova,
229 DEFAULT_IF
=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
230 DEFAULT_IP
=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
239 if [ -n "$MICROSTACK" ]; then