Upgrade ironic and baremetal-operator components
[icn.git] / deploy / metal3 / scripts / 01_metal3.sh
index bd7be78..8d0fc1b 100755 (executable)
@@ -12,50 +12,8 @@ if [[ $EUID -ne 0 ]]; then
     exit 1
 fi
 
-IMAGE_URL=http://172.22.0.1/images/${BM_IMAGE}
-IMAGE_CHECKSUM=http://172.22.0.1/images/${BM_IMAGE}.md5sum
-
-function clone_repos {
-    mkdir -p "${M3PATH}"
-    if [[ -d ${BMOPATH} && "${FORCE_REPO_UPDATE}" == "true" ]]; then
-      rm -rf "${BMOPATH}"
-    fi
-    if [ ! -d "${BMOPATH}" ] ; then
-        pushd "${M3PATH}"
-        git clone "${BMOREPO}"
-        popd
-    fi
-    pushd "${BMOPATH}"
-    git checkout "${BMOBRANCH}"
-    git pull -r || true
-    popd
-}
-
-function get_default_interface_ipaddress {
-    local _ip=$1
-    local _default_interface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
-    local _ipv4address=$(ip addr show dev $_default_interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
-    eval $_ip="'$_ipv4address'"
-}
-
-function create_ssh_key {
-    #ssh key for compute node to communicate back to bootstrap server
-    mkdir -p $BUILD_DIR/ssh_key
-    ssh-keygen -C "compute.icn.akraino.lfedge.org" -f $BUILD_DIR/ssh_key/id_rsa
-    cat $BUILD_DIR/ssh_key/id_rsa.pub >> $HOME/.ssh/authorized_keys
-}
-
-function set_compute_key {
-    _SSH_LOCAL_KEY=$(cat $BUILD_DIR/ssh_key/id_rsa)
-    cat << EOF
-write_files:
-- path: /opt/ssh_id_rsa
-    owner: root:root
-    permissions: '0600'
-    content: |
-    $_SSH_LOCAL_KEY
-EOF
-}
+IMAGE_URL=http://172.22.0.1:6180/images/${BM_IMAGE}
+IMAGE_CHECKSUM=http://172.22.0.1:6180/images/${BM_IMAGE}.md5sum
 
 function deprovision_compute_node {
     name="$1"
@@ -65,25 +23,6 @@ function deprovision_compute_node {
     fi
 }
 
-function set_compute_ssh_config {
-    get_default_interface_ipaddress default_addr
-    cat << EOF
-- path: /root/.ssh/config
-    owner: root:root
-    permissions: '0600'
-    content: |
-    Host bootstrapmachine $default_addr
-    HostName $default_addr
-    IdentityFile /opt/ssh_id_rsa
-    User $USER
-- path: /etc/apt/sources.list
-    owner: root:root
-    permissions: '0665'
-    content: |
-    deb [trusted=yes] ssh://$USER@$default_addr:$LOCAL_APT_REPO ./
-EOF
-}
-
 # documentation for the values below may be found at
 # https://cloudinit.readthedocs.io/en/latest/topics/modules.html
 function create_userdata {
@@ -139,25 +78,6 @@ create_networkdata() {
     node_networkdata $name > $name-networkdata.json
 }
 
-function launch_baremetal_operator {
-    docker pull $IRONIC_BAREMETAL_IMAGE
-    kubectl apply -f bmo/namespace/namespace.yaml
-    kubectl apply -f bmo/rbac/service_account.yaml -n metal3
-    kubectl apply -f bmo/rbac/role.yaml -n metal3
-    kubectl apply -f bmo/rbac/role_binding.yaml
-    kubectl apply -f bmo/crds/metal3.io_baremetalhosts_crd.yaml
-    kubectl apply -f bmo/operator/no_ironic/operator.yaml -n metal3
-}
-
-function remove_baremetal_operator {
-    kubectl delete -f bmo/operator/no_ironic/operator.yaml -n metal3
-    kubectl delete -f bmo/crds/metal3.io_baremetalhosts_crd.yaml
-    kubectl delete -f bmo/rbac/role_binding.yaml
-    kubectl delete -f bmo/rbac/role.yaml -n metal3
-    kubectl delete -f bmo/rbac/service_account.yaml -n metal3
-    kubectl delete -f bmo/namespace/namespace.yaml
-}
-
 function cloud_init_scripts {
     # set_dhcp_indentifier.sh:
     #   The IP address assigned to the provisioning NIC will change
@@ -224,16 +144,19 @@ EOF
 }
 
 function make_bm_hosts {
-    while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do
+    kubectl create namespace metal3 --dry-run=client -o yaml | kubectl apply -f -
+    while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do
         create_userdata $name $os_username $os_password
         apply_userdata_credential $name
         create_networkdata $name
         apply_networkdata_credential $name
 
-        GO111MODULE=auto go run $GOPATH/src/github.com/metal3-io/baremetal-operator/cmd/make-bm-worker/main.go \
+        GOPATH=$GOPATH:$(echo ${BMOPATH} | cut -d/ -f-2) GO111MODULE=auto \
+             go run ${BMOPATH}/cmd/make-bm-worker/main.go \
            -address "ipmi://$ipmi_address" \
            -password "$ipmi_password" \
            -user "$ipmi_username" \
+           -boot-mac "$boot_mac" \
            "$name" > $name-bm-node.yaml
 
         printf "  image:" >> $name-bm-node.yaml
@@ -263,13 +186,13 @@ function configure_nodes {
 }
 
 function remove_bm_hosts {
-    while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do
+    while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do
         deprovision_compute_node $name
     done
 }
 
 function cleanup {
-    while IFS=',' read -r name ipmi_username ipmi_password ipmi_address os_username os_password os_image_name; do
+    while IFS=',' read -r name ipmi_username ipmi_password ipmi_address boot_mac os_username os_password os_image_name; do
         kubectl delete --ignore-not-found=true bmh $name -n metal3
         kubectl delete --ignore-not-found=true secrets $name-bmc-secret -n metal3
         kubectl delete --ignore-not-found=true secrets $name-user-data -n metal3
@@ -302,12 +225,6 @@ function deprovision_all_hosts {
     list_nodes | remove_bm_hosts
 }
 
-if [ "$1" == "launch" ]; then
-    clone_repos
-    launch_baremetal_operator
-    exit 0
-fi
-
 if [ "$1" == "deprovision" ]; then
     configure_nodes
     deprovision_all_hosts
@@ -326,22 +243,8 @@ if [ "$1" == "clean" ]; then
     exit 0
 fi
 
-if [ "$1" == "remove" ]; then
-    remove_baremetal_operator
-    exit 0
-fi
-
 echo "Usage: metal3.sh"
-echo "launch      - Launch the metal3 operator"
 echo "provision   - provision baremetal node as specified in common.sh"
 echo "deprovision - deprovision baremetal node as specified in common.sh"
 echo "clean       - clean all the bmh resources"
-echo "remove      - remove baremetal operator"
 exit 1
-
-#Following code is tested for the offline mode
-#Will be intergrated for the offline mode for ICNi v.0.1.0 beta
-#create_ssh_key
-#create_userdata
-#set_compute_key
-#set_compute_ssh_config