[baremetal] Move salt master IP to PXE/admin
[fuel.git] / mcp / scripts / lib.sh
index b4d45dd..e44278e 100644 (file)
@@ -35,6 +35,17 @@ function get_base_image {
   wget -P "${image_dir}" -N "${base_image}"
 }
 
+function cleanup_uefi {
+  # Clean up Ubuntu boot entry if cfg01, kvm nodes online from previous deploy
+  local cmd_str="ssh ${SSH_OPTS} ${SSH_SALT}"
+  [ ! "$(hostname)" = 'cfg01' ] || cmd_str='eval'
+  ${cmd_str} "sudo salt -C 'kvm* or cmp*' cmd.run \
+    \"which efibootmgr > /dev/null 2>&1 && \
+    efibootmgr | grep -oP '(?<=Boot)[0-9]+(?=.*ubuntu)' | \
+    xargs -I{} efibootmgr --delete-bootnum --bootnum {}; \
+    rm -rf /boot/efi/*\"" || true
+}
+
 function cleanup_vms {
   # clean up existing nodes
   for node in $(virsh list --name | grep -P '\w{3}\d{2}'); do
@@ -52,6 +63,7 @@ function prepare_vms {
   local image_dir=$1; shift
   local vnodes=("$@")
 
+  cleanup_uefi
   cleanup_vms
   get_base_image "${base_image}" "${image_dir}"
   # shellcheck disable=SC2016
@@ -72,8 +84,7 @@ function create_networks {
   # create required networks, including constant "mcpcontrol"
   # FIXME(alav): since we renamed "pxe" to "mcpcontrol", we need to make sure
   # we delete the old "pxe" virtual network, or it would cause IP conflicts.
-  # FIXME(alav): The same applies for "fuel1" virsh network.
-  for net in "fuel1" "pxe" "mcpcontrol" "${vnode_networks[@]}"; do
+  for net in "pxe" "mcpcontrol" "${vnode_networks[@]}"; do
     if virsh net-info "${net}" >/dev/null 2>&1; then
       virsh net-destroy "${net}" || true
       virsh net-undefine "${net}"
@@ -105,8 +116,8 @@ function create_vms {
 
     # prepare network args
     net_args=" --network network=mcpcontrol,model=virtio"
-    if [ "${vnode_data[0]}" = "mas01" ]; then
-      # MaaS node's 3rd interface gets connected to PXE/Admin Bridge
+    if [ "${DEPLOY_TYPE:-}" = 'baremetal' ]; then
+      # 3rd interface gets connected to PXE/Admin Bridge (cfg01, mas01)
       vnode_networks[2]="${vnode_networks[0]}"
     fi
     for net in "${vnode_networks[@]:1}"; do
@@ -133,9 +144,9 @@ function update_mcpcontrol_network {
   # shellcheck disable=SC2155
   local amac=$(virsh domiflist mas01 2>&1| awk '/mcpcontrol/ {print $5; exit}')
   virsh net-update "mcpcontrol" add ip-dhcp-host \
-    "<host mac='${cmac}' name='cfg01' ip='${SALT_MASTER}'/>" --live
+    "<host mac='${cmac}' name='cfg01' ip='${SALT_MASTER}'/>" --live --config
   [ -z "${amac}" ] || virsh net-update "mcpcontrol" add ip-dhcp-host \
-    "<host mac='${amac}' name='mas01' ip='${MAAS_IP}'/>" --live
+    "<host mac='${amac}' name='mas01' ip='${MAAS_IP}'/>" --live --config
 }
 
 function start_vms {