Update of Packer builder for Vagrant and various clouds
[osm/devops.git] / packer / old_releases / scripts / vimemu.sh
1 #!/bin/sh
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
15 mkdir -p /etc/systemd/system/scripts
16 cat > /etc/systemd/system/scripts/osm-vimemu-startup.sh <<-'EOF'
17 #!/bin/sh
18
19 export OSM_HOSTNAME=127.0.0.1
20 export OSM_SOL005=True
21
22 echo "Waiting for OSM startup"
23 while true; do
24 # wait for startup of osm
25 RC=$(osm vim-list)
26 if [ "$?" -eq 0 ]; then
27 break
28 fi
29 sleep 2
30 done
31 echo "OSM is up"
32 sleep 10
33 export VIMEMU_HOSTNAME=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu)
34 osm vim-create --name vim-emulator --user username --password password --auth_url http://$VIMEMU_HOSTNAME:6001/v2.0 --tenant tenantName --account_type openstack
35 osm vnfd-create /home/vagrant/vim-emu/examples/vnfs/ping.tar.gz
36 osm vnfd-create /home/vagrant/vim-emu/examples/vnfs/pong.tar.gz
37 osm nsd-create /home/vagrant/vim-emu/examples/services/pingpong_nsd.tar.gz
38 osm ns-create --nsd_name pingpong --ns_name test --vim_account vim-emulator
39
40 echo "VIM emulator created"
41 systemctl disable osm-vimemu-setup.service
42 EOF
43 chmod +x /etc/systemd/system/scripts/osm-vimemu-startup.sh
44
45 cat > /etc/systemd/system/osm-vimemu-setup.service <<-'EOF'
46 [Unit]
47 Description=OSM VIM emulator setup
48
49 [Service]
50 Type=oneshot
51 ExecStart=/etc/systemd/system/scripts/osm-vimemu-startup.sh
52 RemainAfterExit=yes
53 TimeoutSec=120
54
55 # Output needs to appear in instance console output
56 StandardOutput=journal+console
57
58 [Install]
59 WantedBy=multi-user.target
60 EOF
61
62 #systemctl enable osm-vimemu-setup.service