Update of Packer builder for Vagrant and various clouds

Change-Id: I71d3a6fb21ce2b3c54993072f42749a5869fae96
Signed-off-by: ramonsalguer <javier.ramon@telefonica.com>
diff --git a/packer/old_releases/scripts/cleanup.sh b/packer/old_releases/scripts/cleanup.sh
new file mode 100644
index 0000000..c51b077
--- /dev/null
+++ b/packer/old_releases/scripts/cleanup.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+apt autoremove
+apt update
+
+rm -f /home/vagrant/*.sh
+
+wget --no-check-certificate https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub -O /home/vagrant/.ssh/authorized_keys
+chmod 0600 /home/vagrant/.ssh/authorized_keys
+chown -R vagrant:vagrant /home/vagrant/.ssh
+
+dd if=/dev/zero of=/EMPTY bs=1M
+rm -f /EMPTY
+sync
diff --git a/packer/old_releases/scripts/get-install-osm.sh b/packer/old_releases/scripts/get-install-osm.sh
new file mode 100644
index 0000000..6c8cfbc
--- /dev/null
+++ b/packer/old_releases/scripts/get-install-osm.sh
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+export PATH=$PATH:/snap/bin
+echo "PATH=$PATH"
+juju status
+
+wget https://osm-download.etsi.org/ftp/osm-5.0-five/install_osm.sh
+chmod +x install_osm.sh
+./install_osm.sh --nolxd --nojuju -y
+
+cat >> ~/.bashrc <<-EOF
+export OSM_HOSTNAME=127.0.0.1
+export OSM_SOL005=True
+
+EOF
diff --git a/packer/old_releases/scripts/install_packages.sh b/packer/old_releases/scripts/install_packages.sh
new file mode 100644
index 0000000..2846f71
--- /dev/null
+++ b/packer/old_releases/scripts/install_packages.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+sudo apt -y update && apt-get -y upgrade
+sudo apt -y install git wget curl vim snapd lxd software-properties-common
+sudo apt-get install -y apt-transport-https ca-certificates
+curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
+sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
+sudo apt-get -qq update
+sudo apt-get install -y docker-ce
+sudo groupadd -f docker
+sudo usermod -aG docker $USER
diff --git a/packer/old_releases/scripts/juju-setup.sh b/packer/old_releases/scripts/juju-setup.sh
new file mode 100644
index 0000000..bc415b6
--- /dev/null
+++ b/packer/old_releases/scripts/juju-setup.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+sudo snap install juju --classic
+/snap/bin/juju bootstrap --bootstrap-series=xenial localhost osm
diff --git a/packer/old_releases/scripts/lxd-bridge b/packer/old_releases/scripts/lxd-bridge
new file mode 100644
index 0000000..0826da7
--- /dev/null
+++ b/packer/old_releases/scripts/lxd-bridge
@@ -0,0 +1,66 @@
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+# WARNING: This file is generated by a debconf template!
+# It is recommended to update it by using "dpkg-reconfigure -p medium lxd"
+
+# Whether to setup a new bridge or use an existing one
+USE_LXD_BRIDGE="true"
+
+# Bridge name
+# This is still used even if USE_LXD_BRIDGE is set to false
+# set to an empty value to fully disable
+LXD_BRIDGE="lxdbr0"
+
+# Update the "default" LXD profile
+UPDATE_PROFILE="true"
+
+# Path to an extra dnsmasq configuration file
+LXD_CONFILE=""
+
+# DNS domain for the bridge
+LXD_DOMAIN="lxd"
+
+# IPv4
+## IPv4 address (e.g. 10.0.8.1)
+LXD_IPV4_ADDR="10.49.16.1"
+
+## IPv4 netmask (e.g. 255.255.255.0)
+LXD_IPV4_NETMASK="255.255.255.0"
+
+## IPv4 network (e.g. 10.0.8.0/24)
+LXD_IPV4_NETWORK="10.49.16.1/24"
+
+## IPv4 DHCP range (e.g. 10.0.8.2,10.0.8.254)
+LXD_IPV4_DHCP_RANGE="10.49.16.2,10.49.16.254"
+
+## IPv4 DHCP number of hosts (e.g. 250)
+LXD_IPV4_DHCP_MAX="252"
+
+## NAT IPv4 traffic
+LXD_IPV4_NAT="true"
+
+# IPv6
+## IPv6 address (e.g. 2001:470:b368:4242::1)
+LXD_IPV6_ADDR=""
+
+## IPv6 CIDR mask (e.g. 64)
+LXD_IPV6_MASK=""
+
+## IPv6 network (e.g. 2001:470:b368:4242::/64)
+LXD_IPV6_NETWORK=""
+
+## NAT IPv6 traffic
+LXD_IPV6_NAT="false"
+
+# Run a minimal HTTP PROXY server
+LXD_IPV6_PROXY="false"
diff --git a/packer/old_releases/scripts/lxd-setup.sh b/packer/old_releases/scripts/lxd-setup.sh
new file mode 100644
index 0000000..03d23a7
--- /dev/null
+++ b/packer/old_releases/scripts/lxd-setup.sh
@@ -0,0 +1,22 @@
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+sudo lxd init --auto --storage-backend zfs --storage-pool lxdpool --storage-create-loop 20
+
+sudo systemctl stop lxd-bridge
+sudo systemctl --system daemon-reload
+
+sudo cp -f /tmp/lxd-bridge /etc/default/lxd-bridge
+sudo systemctl enable lxd-bridge
+sudo systemctl start lxd-bridge
+
+sudo usermod -a -G lxd $(whoami) 
diff --git a/packer/old_releases/scripts/setup.sh b/packer/old_releases/scripts/setup.sh
new file mode 100644
index 0000000..abcff29
--- /dev/null
+++ b/packer/old_releases/scripts/setup.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+echo "vagrant        ALL=(ALL)       NOPASSWD: ALL" >> /etc/sudoers
+sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers
+echo 'APT::Periodic::Enable "0";' >> /etc/apt/apt.conf.d/10periodic
diff --git a/packer/old_releases/scripts/vimemu.sh b/packer/old_releases/scripts/vimemu.sh
new file mode 100644
index 0000000..d7a044e
--- /dev/null
+++ b/packer/old_releases/scripts/vimemu.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+mkdir -p /etc/systemd/system/scripts
+cat > /etc/systemd/system/scripts/osm-vimemu-startup.sh <<-'EOF'
+#!/bin/sh
+
+export OSM_HOSTNAME=127.0.0.1
+export OSM_SOL005=True
+
+echo "Waiting for OSM startup"
+while true; do
+    # wait for startup of osm
+    RC=$(osm vim-list)
+    if [ "$?" -eq 0 ]; then
+        break
+    fi
+    sleep 2
+done
+echo "OSM is up"
+sleep 10
+export VIMEMU_HOSTNAME=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
+osm vim-create --name vim-emulator --user username --password password --auth_url http://$VIMEMU_HOSTNAME:6001/v2.0 --tenant tenantName --account_type openstack
+osm vnfd-create /home/vagrant/vim-emu/examples/vnfs/ping.tar.gz
+osm vnfd-create /home/vagrant/vim-emu/examples/vnfs/pong.tar.gz
+osm nsd-create /home/vagrant/vim-emu/examples/services/pingpong_nsd.tar.gz
+osm ns-create --nsd_name pingpong --ns_name test --vim_account vim-emulator
+
+echo "VIM emulator created"
+systemctl disable osm-vimemu-setup.service
+EOF
+chmod +x /etc/systemd/system/scripts/osm-vimemu-startup.sh
+
+cat > /etc/systemd/system/osm-vimemu-setup.service <<-'EOF'
+[Unit]
+Description=OSM VIM emulator setup
+
+[Service]
+Type=oneshot
+ExecStart=/etc/systemd/system/scripts/osm-vimemu-startup.sh
+RemainAfterExit=yes
+TimeoutSec=120
+
+# Output needs to appear in instance console output
+StandardOutput=journal+console
+
+[Install]
+WantedBy=multi-user.target
+EOF
+
+#systemctl enable osm-vimemu-setup.service