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