summaryrefslogtreecommitdiffstats
path: root/ci/deploy.sh
blob: ae01cedd3ce822256aa615951f2973e96b032981 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash

# Deploy script to install provisioning server for OPNFV Apex
# author: Dan Radez (dradez@redhat.com)
# author: Tim Rozet (trozet@redhat.com)
#
# Based on RDO Manager http://www.rdoproject.org
#
# Pre-requisties:
#  - Supports 3 or 4 network interface configuration
#  - Target system must be RPM based
#  - Provisioned nodes expected to have following order of network connections (note: not all have to exist, but order is maintained):
#    eth0- admin network
#    eth1- private network (+storage network in 3 NIC config)
#    eth2- public network
#    eth3- storage network
#  - script assumes /24 subnet mask

set -e

##VARIABLES
declare -i CNT
declare UNDERCLOUD

##FUNCTIONS

##verify vm exists, an has a dhcp lease assigned to it
##params: none 
function setup_instack_vm {
  if ! virsh list | grep instack > /dev/null; then
      #virsh vol-create default instack.qcow2.xml
      virsh define instack.xml

      #Copy instack machine
      cp instack.qcow2 /var/lib/libvirt/images
      restorecon /var/lib/libvirt/images/instack.qcow2

      sleep 1
      virsh start instack
  else
      echo "Found Instack VM, using existing VM"
  fi
  
  sleep 3 # let DHCP happen

  CNT=10
  echo -n "Waiting for instack's dhcp address"
  while ! virsh net-dhcp-leases default | grep instack > /dev/null && [ $CNT -gt 0 ]; do
      echo -n "."
      sleep 3
      CNT=CNT-1
  done

  # get the instack VM IP
  UNDERCLOUD=$(virsh net-dhcp-leases default | grep instack | awk '{print $5}' | awk -F '/' '{print $1}')

  CNT=10
  echo -en "\rValidating instack VM connectivity"
  while ! ping -c 1 $UNDERCLOUD > /dev/null && [ $CNT -gt 0 ]; do
      echo -n "."
      sleep 3
      CNT=CNT-1
  done
  CNT=10
  while ! ssh -T -o "StrictHostKeyChecking no" root@$UNDERCLOUD "echo ''" 1>&2> /dev/null && [ $CNT -gt 0 ]; do
      echo -n "."
      sleep 3
      CNT=CNT-1
  done

  # extra space to overwrite the previous connectivity output
  echo -e "\rInstack VM has IP $UNDERCLOUD                                    "

  #ssh -T -o "StrictHostKeyChecking no" root@$UNDERCLOUD "systemctl stop openstack-nova-compute.service"
  ssh -T -o "StrictHostKeyChecking no" root@$UNDERCLOUD "ip a a 192.0.2.1/24 dev eth1"
}

##Copy over the glance images and instack json file
##params: none 
function copy_materials {

  scp stack/deploy-ramdisk-ironic.initramfs stack@$UNDERCLOUD:
  scp stack/deploy-ramdisk-ironic.kernel stack@$UNDERCLOUD:
  scp stack/discovery-ramdisk.initramfs stack@$UNDERCLOUD:
  scp stack/discovery-ramdisk.kernel stack@$UNDERCLOUD:
  scp stack/fedora-user.qcow2 stack@$UNDERCLOUD:
  scp stack/overcloud-full.initrd stack@$UNDERCLOUD:
  scp stack/overcloud-full.qcow2 stack@$UNDERCLOUD:
  scp stack/overcloud-full.vmlinuz stack@$UNDERCLOUD:

  scp instackenv.json stack@$UNDERCLOUD:
}

##Seed the undercloud openstack installation
##preping it for deployment and launch the deploy
##params: none 
function undercloud_prep_overcloud_deploy {
  ssh -T -o "StrictHostKeyChecking no" stack@$UNDERCLOUD <<EOI
source stackrc
echo "Configuring undercloud and discovering nodes"
openstack overcloud image upload
openstack baremetal import --json instackenv.json
openstack baremetal configure boot
openstack baremetal introspection bulk start
openstack flavor create --id auto --ram 4096 --disk 40 --vcpus 1 baremetal
openstack flavor set --property "cpu_arch"="x86_64" --property "capabilities:boot_option"="local" baremetal
neutron subnet-update $(neutron subnet-list | grep -v id | grep -v \\-\\- | awk {'print $2'}) --dns-nameserver 8.8.8.8
openstack overcloud deploy --plan overcloud
EOI

}

display_usage() {
  echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
  echo -e "\n${green}Make sure you have the latest kernel installed before running this script! (yum update kernel +reboot)${reset}\n"
  echo -e "\nUsage:\n$0 [arguments] \n"
  echo -e "\n   -no_parse : No variable parsing into config. Flag. \n"
  echo -e "\n   -base_config : Full path of settings file to parse. Optional.  Will provide a new base settings file rather than the default.  Example:  -base_config /opt/myinventory.yml \n"
  echo -e "\n   -virtual : Node virtualization instead of baremetal. Flag. \n"
  echo -e "\n   -enable_virtual_dhcp : Run dhcp server instead of using static IPs.  Use this with -virtual only. \n"
  echo -e "\n   -static_ip_range : static IP range to define when using virtual and when dhcp is not being used (default), must at least a 20 IP block.  Format: '192.168.1.1,192.168.1.20' \n"
  echo -e "\n   -ping_site : site to use to verify IP connectivity from the VM when -virtual is used.  Format: -ping_site www.blah.com \n"
  echo -e "\n   -floating_ip_count : number of IP address from the public range to be used for floating IP. Default is 20.\n"
}

##translates the command line paramaters into variables
##params: $@ the entire command line is passed
##usage: parse_cmd_line() "$@"
parse_cmdline() {
  if [[ ( $1 == "--help") ||  $1 == "-h" ]]; then
    display_usage
    exit 0
  fi

  echo -e "\n\n${blue}This script is used to deploy the Apex Installer and Provision OPNFV Target System${reset}\n\n"
  echo "Use -h to display help"
  sleep 2

  while [ "`echo $1 | cut -c1`" = "-" ]
  do
    echo $1
    case "$1" in
        -base_config)
                base_config=$2
                shift 2
            ;;
        -no_parse)
                no_parse="TRUE"
                shift 1
            ;;
        -virtual)
                virtual="TRUE"
                shift 1
            ;;
        -enable_virtual_dhcp)
                enable_virtual_dhcp="TRUE"
                shift 1
            ;;
        -static_ip_range)
                static_ip_range=$2
                shift 2
            ;;
        -ping_site)
                ping_site=$2
                shift 2
            ;;
        -floating_ip_count)
                floating_ip_count=$2
                shift 2
            ;;
        *)
                display_usage
                exit 1
            ;;
    esac
  done

  if [ ! -z "$enable_virtual_dhcp" ] && [ ! -z "$static_ip_range" ]; then
    echo -e "\n\n${red}ERROR: Incorrect Usage.  Static IP range cannot be set when using DHCP!.  Exiting${reset}\n\n"
    exit 1
  fi

  if [ -z "$virtual" ]; then
    if [ ! -z "$enable_virtual_dhcp" ]; then
      echo -e "\n\n${red}ERROR: Incorrect Usage.  enable_virtual_dhcp can only be set when using -virtual!.  Exiting${reset}\n\n"
      exit 1
    elif [ ! -z "$static_ip_range" ]; then
      echo -e "\n\n${red}ERROR: Incorrect Usage.  static_ip_range can only be set when using -virtual!.  Exiting${reset}\n\n"
      exit 1
    fi
  fi

  if [ -z "$floating_ip_count" ]; then
    floating_ip_count=20
  fi
}

##END FUNCTIONS

main() {
  parse_cmdline "$@"
  setup_instack_vm
  copy_materials
  undercloud_prep_overcloud_deploy
}

main "$@"