Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 1 | # -*- mode: ruby -*- |
| 2 | # -*- coding: utf-8 -*- |
| 3 | |
| 4 | host_ip = "192.168.121.1" |
| 5 | operator_key = "${HOME}/.ssh/onap-key" |
| 6 | vagrant_user = "vagrant" |
| 7 | vagrant_password = "vagrant" |
| 8 | synced_folder_main = "/vagrant" |
| 9 | synced_folder_config = "#{synced_folder_main}/config" |
Pawel Wieczorek | 55c0c9d | 2019-11-29 15:23:43 +0100 | [diff] [blame] | 10 | synced_folder_tools_config = "#{synced_folder_main}/tools/config" |
Pawel Wieczorek | df0edea | 2019-11-29 16:18:36 +0100 | [diff] [blame] | 11 | os_config = "#{synced_folder_config}/local.conf" |
Pawel Wieczorek | 0d01b78 | 2019-12-09 16:20:45 +0100 | [diff] [blame] | 12 | os_env = "#{synced_folder_config}/dot_env" |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 13 | cluster_yml = "cluster.yml" |
| 14 | apt_prefs_dir = "/etc/apt/apt.conf.d" |
| 15 | apt_prefs = "95silent-approval" |
| 16 | |
Pawel Wieczorek | 3cb7821 | 2019-12-09 16:00:47 +0100 | [diff] [blame] | 17 | vm_memory = 1 * 1024 |
Pawel Wieczorek | 73862e4 | 2020-01-24 11:58:07 +0100 | [diff] [blame] | 18 | vm_memory_os = 4 * 1024 |
| 19 | vm_memory_onap = 20 * 1024 |
Pawel Wieczorek | 3cb7821 | 2019-12-09 16:00:47 +0100 | [diff] [blame] | 20 | vm_cpu = 1 |
Pawel Wieczorek | 73862e4 | 2020-01-24 11:58:07 +0100 | [diff] [blame] | 21 | vm_cpus = 4 |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 22 | vm_box = "generic/ubuntu1804" |
Pawel Wieczorek | 3fbeaf0 | 2020-01-24 17:52:23 +0100 | [diff] [blame] | 23 | vm_disk = 32 |
| 24 | vm_disk_onap = 64 |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 25 | |
Pawel Wieczorek | 3fbeaf0 | 2020-01-24 17:52:23 +0100 | [diff] [blame] | 26 | operation = { |
| 27 | name: 'operator', |
| 28 | hostname: 'operator', |
| 29 | ip: '172.17.4.254', |
| 30 | cpus: vm_cpu, |
| 31 | memory: vm_memory, |
| 32 | disk: vm_disk |
| 33 | } |
| 34 | devstack = { |
| 35 | name: 'devstack', |
| 36 | hostname: 'devstack', |
| 37 | ip: '172.17.4.200', |
| 38 | cpus: vm_cpu, |
| 39 | memory: vm_memory_os, |
| 40 | disk: vm_disk |
| 41 | } |
| 42 | control = { |
| 43 | name: 'control', |
| 44 | hostname: 'control', |
| 45 | ip: '172.17.4.100', |
| 46 | cpus: vm_cpu, |
| 47 | memory: vm_memory, |
| 48 | disk: vm_disk |
| 49 | } |
| 50 | worker = { |
| 51 | name: 'worker', |
| 52 | hostname: 'worker', |
| 53 | ip: '172.17.4.101', |
| 54 | cpus: vm_cpus, |
| 55 | memory: vm_memory_onap, |
| 56 | disk: vm_disk_onap |
| 57 | } |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 58 | |
Pawel Wieczorek | 3cb7821 | 2019-12-09 16:00:47 +0100 | [diff] [blame] | 59 | cluster = [] << control << worker |
Pawel Wieczorek | df0edea | 2019-11-29 16:18:36 +0100 | [diff] [blame] | 60 | all = cluster.dup << operation << devstack |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 61 | |
Pawel Wieczorek | 0d01b78 | 2019-12-09 16:20:45 +0100 | [diff] [blame] | 62 | operation_post_msg = "Run: \"vagrant provision #{operation[:name]} --provision-with=rke_up,setup_kubectl,setup_helm_cluster,setup_helm_repo,deploy_onap\" to complete ONAP deployment" |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 63 | |
| 64 | $replace_dns = <<-SCRIPT |
| 65 | HOST_IP="$1" |
| 66 | rm -f /etc/resolv.conf # drop its dynamic management by systemd-resolved |
| 67 | echo nameserver "$HOST_IP" | tee /etc/resolv.conf |
| 68 | SCRIPT |
| 69 | |
Pawel Wieczorek | df0edea | 2019-11-29 16:18:36 +0100 | [diff] [blame] | 70 | $enable_ipv6 = <<-SCRIPT |
| 71 | sed -i'' 's/net.ipv6.conf.all.disable_ipv6.*$/net.ipv6.conf.all.disable_ipv6 = 0/' /etc/sysctl.conf |
| 72 | sysctl -p |
| 73 | SCRIPT |
| 74 | |
| 75 | $setup_devstack = <<-SCRIPT |
| 76 | CONFIG="$1" |
| 77 | git clone https://opendev.org/openstack/devstack |
| 78 | cd devstack |
| 79 | cp "$CONFIG" . |
| 80 | ./stack.sh |
| 81 | SCRIPT |
| 82 | |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 83 | $add_to_docker_group = <<-SCRIPT |
| 84 | USER="$1" |
| 85 | echo "Adding ${USER} to 'docker' group" |
| 86 | usermod -aG docker "$USER" |
| 87 | SCRIPT |
| 88 | |
| 89 | $setup_debconf = <<-SCRIPT |
| 90 | echo "Setting debconf frontend to noninteractive" |
| 91 | sed -i'.orig' '/^Config:/a Frontend: noninteractive' /etc/debconf.conf |
| 92 | SCRIPT |
| 93 | |
| 94 | $install_sshpass = <<-SCRIPT |
| 95 | apt-get update |
| 96 | echo "Installing 'sshpass'" |
| 97 | apt-get install sshpass |
| 98 | SCRIPT |
| 99 | |
Pawel Wieczorek | 0664ac4 | 2019-12-09 16:16:48 +0100 | [diff] [blame] | 100 | $install_make = <<-SCRIPT |
| 101 | apt-get update |
| 102 | echo "Installing 'make'" |
| 103 | apt-get install make |
| 104 | SCRIPT |
| 105 | |
Pawel Wieczorek | 3fbeaf0 | 2020-01-24 17:52:23 +0100 | [diff] [blame] | 106 | $resize_disk = <<-SCRIPT |
| 107 | DEV=${1:-sda} |
| 108 | PART=${2:-3} |
| 109 | echo ", +" | sfdisk -N "$PART" "/dev/$DEV" --no-reread |
| 110 | partprobe |
| 111 | resize2fs "/dev/${DEV}${PART}" |
| 112 | SCRIPT |
| 113 | |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 114 | $generate_key = <<-SCRIPT |
| 115 | KEY_FILE="$1" |
| 116 | echo "Generating SSH key (${KEY_FILE})" |
| 117 | ssh-keygen -q -b 4096 -t rsa -f "$KEY_FILE" -N "" |
| 118 | SCRIPT |
| 119 | |
| 120 | $deploy_key = <<-SCRIPT |
| 121 | KEY="$1" |
| 122 | USER="$2" |
| 123 | PASS="$PASSWORD" |
| 124 | IPS="$3" |
| 125 | echo "Deploying ${KEY} for ${USER}" |
| 126 | for ip in $IPS; do |
| 127 | echo "on ${ip}" |
| 128 | sshpass -p "$PASS" ssh-copy-id -o StrictHostKeyChecking=no -i "$KEY" "${USER}@${ip}" |
| 129 | done |
| 130 | SCRIPT |
| 131 | |
| 132 | $link_dotfiles = <<-SCRIPT |
| 133 | SYNC_DIR="$1" |
| 134 | for rc in ${SYNC_DIR}/dot_*; do |
| 135 | src="$rc" |
| 136 | dst="${HOME}/.${rc##*dot_}" |
| 137 | echo "Symlinking ${src} to ${dst}" |
| 138 | ln -sf "$src" "$dst" |
| 139 | done |
| 140 | SCRIPT |
| 141 | |
| 142 | $link_file = <<-SCRIPT |
| 143 | SYNC_DIR="$1" |
| 144 | FILE="$2" |
| 145 | src="${SYNC_DIR}/${FILE}" |
| 146 | dst="$3" |
| 147 | echo "Symlinking ${src} to ${dst}" |
| 148 | ln -sf "$src" "$dst" |
| 149 | SCRIPT |
| 150 | |
| 151 | $rke_up = "rke up" |
Pawel Wieczorek | 3364980 | 2020-01-27 17:32:20 +0100 | [diff] [blame] | 152 | $rke_down = "rke remove --force || true" # best effort |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 153 | |
Pawel Wieczorek | f1176da | 2019-12-05 13:45:45 +0100 | [diff] [blame] | 154 | $get_oom = <<-SCRIPT |
| 155 | BRANCH="${1:-5.0.1-ONAP}" |
Pawel Wieczorek | dc298f1 | 2020-01-23 17:55:17 +0100 | [diff] [blame] | 156 | REPO="${2:-https://git.onap.org/oom}" |
| 157 | git clone -b "$BRANCH" "$REPO" --recurse-submodules |
Pawel Wieczorek | f1176da | 2019-12-05 13:45:45 +0100 | [diff] [blame] | 158 | SCRIPT |
| 159 | |
Pawel Wieczorek | 6efe941 | 2020-01-07 15:28:55 +0100 | [diff] [blame] | 160 | $get_helm_plugins = "mkdir -p ${HOME}/.helm && cp -R ${HOME}/oom/kubernetes/helm/plugins/ ${HOME}/.helm" |
Pawel Wieczorek | f1176da | 2019-12-05 13:45:45 +0100 | [diff] [blame] | 161 | |
Pawel Wieczorek | 0664ac4 | 2019-12-09 16:16:48 +0100 | [diff] [blame] | 162 | $setup_helm_cluster = <<-SCRIPT |
| 163 | export KUBECONFIG="${HOME}/.kube/config.onap" |
| 164 | kubectl config use-context onap |
| 165 | kubectl -n kube-system create serviceaccount tiller |
| 166 | kubectl create clusterrolebinding tiller --clusterrole=cluster-admin --serviceaccount=kube-system:tiller |
| 167 | helm init --service-account tiller |
| 168 | kubectl -n kube-system rollout status deploy/tiller-deploy |
| 169 | SCRIPT |
| 170 | |
| 171 | # FIXME: replace sleep command with helm repo readiness probe |
| 172 | $setup_helm_repo = <<-SCRIPT |
| 173 | helm serve & |
| 174 | sleep 3 |
| 175 | helm repo add local http://127.0.0.1:8879 |
| 176 | make -C ${HOME}/oom/kubernetes all |
| 177 | make -C ${HOME}/oom/kubernetes onap |
| 178 | SCRIPT |
| 179 | |
Pawel Wieczorek | 0d01b78 | 2019-12-09 16:20:45 +0100 | [diff] [blame] | 180 | $deploy_onap = <<-SCRIPT |
Pawel Wieczorek | dc298f1 | 2020-01-23 17:55:17 +0100 | [diff] [blame] | 181 | OVERRIDE="${1:-${HOME}/oom/kubernetes/onap/resources/environments/minimal-onap.yaml}" |
| 182 | |
| 183 | ENV="${2:-#{os_env}}" |
Pawel Wieczorek | 0d01b78 | 2019-12-09 16:20:45 +0100 | [diff] [blame] | 184 | export $(cat "$ENV" | xargs) |
| 185 | |
| 186 | encrypt () { |
| 187 | KEY="${HOME}/oom/kubernetes/so/resources/config/mso/encryption.key" |
| 188 | echo -n "$1" \ |
| 189 | | openssl aes-128-ecb -e -K `cat "$KEY"` -nosalt \ |
| 190 | | xxd -c 256 -p |
| 191 | } |
| 192 | |
| 193 | export OPENSTACK_ENCRYPTED_PASSWORD="$(encrypt $OPENSTACK_PASSWORD)" |
| 194 | |
| 195 | export KUBECONFIG="${HOME}/.kube/config.onap" |
| 196 | |
Pawel Wieczorek | 0d01b78 | 2019-12-09 16:20:45 +0100 | [diff] [blame] | 197 | helm deploy minimal local/onap --namespace onap -f "$OVERRIDE" --verbose --timeout 900 |
| 198 | SCRIPT |
| 199 | |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 200 | Vagrant.configure('2') do |config| |
| 201 | all.each do |machine| |
| 202 | config.vm.define machine[:name] do |config| |
| 203 | config.vm.box = vm_box |
| 204 | config.vm.hostname = machine[:hostname] |
| 205 | |
| 206 | config.vm.provider :virtualbox do |v| |
| 207 | v.name = machine[:name] |
Pawel Wieczorek | 3cb7821 | 2019-12-09 16:00:47 +0100 | [diff] [blame] | 208 | v.memory = machine[:memory] |
| 209 | v.cpus = machine[:cpus] |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 210 | end |
| 211 | |
| 212 | config.vm.provider :libvirt do |v| |
Pawel Wieczorek | 3cb7821 | 2019-12-09 16:00:47 +0100 | [diff] [blame] | 213 | v.memory = machine[:memory] |
| 214 | v.cpus = machine[:cpus] |
Pawel Wieczorek | 3fbeaf0 | 2020-01-24 17:52:23 +0100 | [diff] [blame] | 215 | v.machine_virtual_size = machine[:disk] # set at VM creation |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 216 | end |
| 217 | |
| 218 | config.vm.network :private_network, ip: machine[:ip] |
| 219 | config.vm.provision "replace_dns", type: :shell, run: "always", inline: $replace_dns, args: host_ip |
| 220 | |
Pawel Wieczorek | df0edea | 2019-11-29 16:18:36 +0100 | [diff] [blame] | 221 | if machine[:name] == 'devstack' |
| 222 | config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: "Vagrantfile" |
| 223 | |
| 224 | config.vm.provision "enable_ipv6", type: :shell, run: "always", inline: $enable_ipv6 |
| 225 | config.vm.provision "setup_devstack", type: :shell, privileged: false, inline: $setup_devstack, args: os_config |
| 226 | end |
| 227 | |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 228 | if machine[:name] == 'control' |
Pawel Wieczorek | 55c0c9d | 2019-11-29 15:23:43 +0100 | [diff] [blame] | 229 | config.vm.provision "customize_control", type: :shell, path: "tools/imported/openstack-k8s-controlnode.sh" |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 230 | config.vm.provision "fix_groups_control", type: :shell, inline: $add_to_docker_group, args: vagrant_user |
| 231 | end |
| 232 | |
| 233 | if machine[:name] == 'worker' |
Pawel Wieczorek | 55c0c9d | 2019-11-29 15:23:43 +0100 | [diff] [blame] | 234 | config.vm.provision "customize_worker", type: :shell, path: "tools/imported/openstack-k8s-workernode.sh" |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 235 | config.vm.provision "fix_group_worker", type: :shell, inline: $add_to_docker_group, args: vagrant_user |
Pawel Wieczorek | 3fbeaf0 | 2020-01-24 17:52:23 +0100 | [diff] [blame] | 236 | config.vm.provision "resize_disk", type: :shell, inline: $resize_disk |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 237 | end |
| 238 | |
| 239 | if machine[:name] == 'operator' |
Pawel Wieczorek | ba88f29 | 2020-01-27 17:34:05 +0100 | [diff] [blame] | 240 | config.vm.synced_folder ".", synced_folder_main, type: "rsync", rsync__exclude: ["Vagrantfile", "operator"] |
Pawel Wieczorek | dc298f1 | 2020-01-23 17:55:17 +0100 | [diff] [blame] | 241 | config.vm.synced_folder "~/.ssh", "/home/#{vagrant_user}/.ssh", type: "rsync", rsync__exclude: "authorized_keys" |
Pawel Wieczorek | b0accc3 | 2020-01-16 16:21:02 +0100 | [diff] [blame] | 242 | config.vm.synced_folder "./operator", "/home/#{vagrant_user}", type: "sshfs", reverse: true, sshfs_opts_append: "-o nonempty" |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 243 | |
| 244 | config.vm.provision "setup_debconf", type: :shell, inline: $setup_debconf |
| 245 | config.vm.provision "link_apt_prefs", type: :shell, run: "always" do |s| |
| 246 | s.inline = $link_file |
Pawel Wieczorek | 55c0c9d | 2019-11-29 15:23:43 +0100 | [diff] [blame] | 247 | s.args = [synced_folder_tools_config, apt_prefs, apt_prefs_dir] |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 248 | end |
| 249 | config.vm.provision "link_dotfiles_root", type: :shell, run: "always" do |s| |
| 250 | s.inline = $link_dotfiles |
Pawel Wieczorek | 55c0c9d | 2019-11-29 15:23:43 +0100 | [diff] [blame] | 251 | s.args = synced_folder_tools_config |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 252 | end |
| 253 | config.vm.provision "link_dotfiles_user", type: :shell, run: "always" do |s| |
| 254 | s.privileged = false |
| 255 | s.inline = $link_dotfiles |
Pawel Wieczorek | 55c0c9d | 2019-11-29 15:23:43 +0100 | [diff] [blame] | 256 | s.args = synced_folder_tools_config |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 257 | end |
| 258 | |
| 259 | config.vm.provision "install_sshpass", type: :shell, inline: $install_sshpass |
| 260 | config.vm.provision "generate_key", type: :shell, privileged: false, inline: $generate_key, args: operator_key |
| 261 | |
| 262 | ips = "" |
| 263 | cluster.each { |node| ips << node[:ip] << " " } |
| 264 | config.vm.provision "deploy_key", type: :shell do |s| |
| 265 | s.privileged = false |
| 266 | s.inline = $deploy_key |
| 267 | s.args = [operator_key, vagrant_user, ips] |
| 268 | s.env = {'PASSWORD': vagrant_password} |
| 269 | end |
| 270 | |
Pawel Wieczorek | 55c0c9d | 2019-11-29 15:23:43 +0100 | [diff] [blame] | 271 | config.vm.provision "get_rke", type: :shell, path: "tools/get_rke.sh" |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 272 | config.vm.provision "link_cluster_yml", type: :shell, run: "always" do |s| |
| 273 | s.privileged = false |
| 274 | s.inline = $link_file |
Pawel Wieczorek | 55c0c9d | 2019-11-29 15:23:43 +0100 | [diff] [blame] | 275 | s.args = [synced_folder_config, cluster_yml, "$HOME"] |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 276 | end |
| 277 | |
| 278 | config.vm.post_up_message = operation_post_msg |
| 279 | config.vm.provision "rke_up", type: :shell, run: "never", privileged: false, inline: $rke_up |
| 280 | config.trigger.before :destroy do |trigger| |
| 281 | trigger.warn = "Removing cluster" |
| 282 | trigger.run_remote = {privileged: false, inline: $rke_down} |
| 283 | end |
| 284 | |
Pawel Wieczorek | 55c0c9d | 2019-11-29 15:23:43 +0100 | [diff] [blame] | 285 | config.vm.provision "get_kubectl", type: :shell, path: "tools/get_kubectl.sh" |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 286 | config.vm.provision "setup_kubectl", type: :shell, run: "never" do |s| |
| 287 | s.privileged = false |
Pawel Wieczorek | 55c0c9d | 2019-11-29 15:23:43 +0100 | [diff] [blame] | 288 | s.path = "tools/setup_kubectl.sh" |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 289 | end |
Pawel Wieczorek | f1176da | 2019-12-05 13:45:45 +0100 | [diff] [blame] | 290 | config.vm.provision "get_helm", type: :shell, path: "tools/get_helm.sh" |
Pawel Wieczorek | dc298f1 | 2020-01-23 17:55:17 +0100 | [diff] [blame] | 291 | config.vm.provision "get_oom", type: :shell do |s| |
| 292 | s.privileged = false |
| 293 | s.inline = $get_oom |
| 294 | end |
Pawel Wieczorek | f1176da | 2019-12-05 13:45:45 +0100 | [diff] [blame] | 295 | config.vm.provision "get_helm_plugins", type: :shell, privileged: false, inline: $get_helm_plugins |
Pawel Wieczorek | 0664ac4 | 2019-12-09 16:16:48 +0100 | [diff] [blame] | 296 | config.vm.provision "install_make", type: :shell, inline: $install_make |
| 297 | config.vm.provision "setup_helm_cluster", type: :shell, run: "never", privileged: false, inline: $setup_helm_cluster |
| 298 | config.vm.provision "setup_helm_repo", type: :shell, run: "never", privileged: false, inline: $setup_helm_repo |
Pawel Wieczorek | 0d01b78 | 2019-12-09 16:20:45 +0100 | [diff] [blame] | 299 | config.vm.provision "deploy_onap", type: :shell, run: "never" do |s| |
| 300 | s.privileged = false |
| 301 | s.inline = $deploy_onap |
Pawel Wieczorek | 0d01b78 | 2019-12-09 16:20:45 +0100 | [diff] [blame] | 302 | end |
Pawel Wieczorek | 216bd6a | 2019-11-29 15:15:51 +0100 | [diff] [blame] | 303 | end |
| 304 | end |
| 305 | end |
| 306 | end |