Add migration tool to assist with R5 to R6
[icn.git] / deploy / metal3 / scripts / 01_metal3.sh
index add2a29..0b0d564 100755 (executable)
@@ -21,59 +21,11 @@ function deprovision_compute_node {
     fi
 }
 
-function create_userdata {
-    name="$1"
-    username="$2"
-    password="$3"
-    COMPUTE_NODE_FQDN="$name.akraino.icn.org"
-
-    # validate that the user isn't expecting the deprecated
-    # COMPUTE_NODE_PASSWORD to be used
-    if [ "$password" != "${COMPUTE_NODE_PASSWORD:-$password}" ]; then
-        cat <<EOF
-COMPUTE_NODE_PASSWORD "$COMPUTE_NODE_PASSWORD" not equal to nodes.json $name password "$password".
-Unset COMPUTE_NODE_PASSWORD and retry.
-EOF
-        exit 1
-    fi
-
-    printf "    userData:\n" >>${SCRIPTDIR}/machines-values.yaml
-    if [ -n "$username" ]; then
-       printf "      name: ${username}\n" >>${SCRIPTDIR}/machines-values.yaml
-    fi
-    if [ -n "$password" ]; then
-        passwd=$(mkpasswd --method=SHA-512 --rounds 4096 "$password")
-        printf "      hashedPassword: ${passwd}\n" >>${SCRIPTDIR}/machines-values.yaml
-    fi
-
-    if [ -n "$COMPUTE_NODE_FQDN" ]; then
-        printf "      fqdn: ${COMPUTE_NODE_FQDN}\n" >>${SCRIPTDIR}/machines-values.yaml
-    fi
-
-    if [ ! -f $HOME/.ssh/id_rsa.pub ]; then
-        yes y | ssh-keygen -t rsa -N "" -f $HOME/.ssh/id_rsa
-    fi
-
-    printf "      sshAuthorizedKey: $(cat $HOME/.ssh/id_rsa.pub)\n" >>${SCRIPTDIR}/machines-values.yaml
-}
-
-create_networkdata() {
-    name="$1"
-    node_networkdata $name >>${SCRIPTDIR}/machines-values.yaml
-}
-
 function make_bm_hosts {
     while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do
-        printf "  ${name}:\n" >>${SCRIPTDIR}/machines-values.yaml
-        printf "    bmcUsername: ${ipmi_username}\n" >>${SCRIPTDIR}/machines-values.yaml
-        printf "    bmcPassword: ${ipmi_password}\n" >>${SCRIPTDIR}/machines-values.yaml
-        printf "    bmcAddress: ipmi://${ipmi_address}\n" >>${SCRIPTDIR}/machines-values.yaml
-       if [[ ! -z ${boot_mac} ]]; then
-            printf "    bootMACAddress: ${boot_mac}\n" >>${SCRIPTDIR}/machines-values.yaml
-       fi
-        printf "    imageName: ${BM_IMAGE}\n" >>${SCRIPTDIR}/machines-values.yaml
-        create_userdata $name $os_username $os_password
-        create_networkdata $name
+       node_machine_values >${SCRIPTDIR}/${name}-values.yaml
+       helm -n metal3 install ${name} ${SCRIPTDIR}/../../machine --create-namespace -f ${SCRIPTDIR}/${name}-values.yaml
+
     done
 }
 
@@ -83,8 +35,8 @@ function configure_nodes {
     fi
 
     #make sure nodes.json file in /opt/ironic/ are configured
-    if [ ! -f $IRONIC_DATA_DIR/nodes.json ]; then
-        cp ${SCRIPTDIR}/nodes.json.sample $IRONIC_DATA_DIR/nodes.json
+    if [ ! -f $NODES_FILE ]; then
+        cp ${SCRIPTDIR}/nodes.json.sample $NODES_FILE
     fi
 }
 
@@ -94,18 +46,22 @@ function deprovision_bm_hosts {
     done
 }
 
+function clean_bm_hosts {
+    while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do
+       helm -n metal3 uninstall ${name}
+       rm -rf ${SCRIPTDIR}/${name}-values.yaml
+    done
+}
+
 function clean_all {
-    helm -n metal3 uninstall machines
-    rm -f ${SCRIPTDIR}/machines-values.yaml
-    if [ -f $IRONIC_DATA_DIR/nodes.json ]; then
-        rm -rf $IRONIC_DATA_DIR/nodes.json
+    list_nodes | clean_bm_hosts
+    if [ -f $NODES_FILE ]; then
+        rm -rf $NODES_FILE
     fi
 }
 
 function apply_bm_hosts {
-    printf "machines:\n" >${SCRIPTDIR}/machines-values.yaml
     list_nodes | make_bm_hosts
-    helm -n metal3 install machines ${SCRIPTDIR}/../../machines --create-namespace -f ${SCRIPTDIR}/machines-values.yaml
 }
 
 function deprovision_all_hosts {