3 # Read configuration files
4 NEXUS_REPO=$(cat /opt/config/nexus_repo.txt)
5 ARTIFACTS_VERSION=$(cat /opt/config/artifacts_version.txt)
6 DNS_IP_ADDR=$(cat /opt/config/dns_ip_addr.txt)
7 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
8 OPENSTACK_API_KEY=$(cat /opt/config/openstack_api_key.txt)
9 GERRIT_BRANCH=$(cat /opt/config/gerrit_branch.txt)
10 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
11 CODE_REPO=$(cat /opt/config/remote_repo.txt)
13 # Add host name to /etc/host to avoid warnings in openstack images
14 if [[ $CLOUD_ENV != "rackspace" ]]
16 echo 127.0.0.1 $(hostname) >> /etc/hosts
18 # Allow remote login as root
19 mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
20 cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
23 # Set private IP in /etc/network/interfaces manually in the presence of public interface
24 # Some VM images don't add the private interface automatically, we have to do it during the component installation
25 if [[ $CLOUD_ENV == "openstack_nofloat" ]]
27 LOCAL_IP=$(cat /opt/config/local_ip_addr.txt)
28 CIDR=$(cat /opt/config/oam_network_cidr.txt)
29 BITMASK=$(echo $CIDR | cut -d"/" -f2)
31 # Compute the netmask based on the network cidr
32 if [[ $BITMASK == "8" ]]
35 elif [[ $BITMASK == "16" ]]
38 elif [[ $BITMASK == "24" ]]
43 echo "auto eth1" >> /etc/network/interfaces
44 echo "iface eth1 inet static" >> /etc/network/interfaces
45 echo " address $LOCAL_IP" >> /etc/network/interfaces
46 echo " netmask $NETMASK" >> /etc/network/interfaces
47 echo " mtu $MTU" >> /etc/network/interfaces
51 # Download dependencies
52 add-apt-repository -y ppa:openjdk-r/ppa
54 apt-get install -y apt-transport-https ca-certificates wget openjdk-8-jdk git ntp ntpdate make
56 # Download scripts from Nexus
57 curl -k $NEXUS_REPO/org.onap.demo/boot/$ARTIFACTS_VERSION/mso_vm_init.sh -o /opt/mso_vm_init.sh
58 curl -k $NEXUS_REPO/org.onap.demo/boot/$ARTIFACTS_VERSION/mso_serv.sh -o /opt/mso_serv.sh
59 chmod +x /opt/mso_vm_init.sh
60 chmod +x /opt/mso_serv.sh
61 mv /opt/mso_serv.sh /etc/init.d
62 update-rc.d mso_serv.sh defaults
64 # Download and install docker-engine and docker-compose
65 echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
67 apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
68 apt-get install -y --allow-unauthenticated docker-engine
71 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
72 chmod +x /opt/docker/docker-compose
74 # Set the MTU size of docker containers to the minimum MTU size supported by vNICs. OpenStack deployments may need to know the external DNS IP
76 if [ -s /opt/config/dns_ip_addr.txt ]
78 DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/dns_ip_addr.txt) "
80 if [ -s /opt/config/external_dns.txt ]
82 DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/external_dns.txt) "
84 echo "DOCKER_OPTS=\"$DNS_FLAG--mtu=$MTU\"" >> /etc/default/docker
86 cp /lib/systemd/system/docker.service /etc/systemd/system
87 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
88 service docker restart
90 # DNS IP address configuration
91 echo "nameserver "$DNS_IP_ADDR >> /etc/resolvconf/resolv.conf.d/head
94 # Clone Gerrit repository
96 git clone -b $GERRIT_BRANCH --single-branch $CODE_REPO test_lab
97 MSO_ENCRYPTION_KEY=$(cat /opt/test_lab/encryption.key)
98 echo -n "$OPENSTACK_API_KEY" | openssl aes-128-ecb -e -K $MSO_ENCRYPTION_KEY -nosalt | xxd -c 256 -p > /opt/config/api_key.txt
100 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
101 if [[ $CLOUD_ENV != "rackspace" ]]
103 sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
104 grub-mkconfig -o /boot/grub/grub.cfg
105 sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
106 sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
107 echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
108 echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
112 # Run docker containers. For openstack Ubuntu 16.04 images this will run as a service after the VM has restarted