3 LIBDIR="$(dirname "$(dirname "$(dirname "$PWD")")")"
7 BM_OPERATOR="${BM_OPERATOR:-https://github.com/metal3-io/baremetal-operator.git}"
9 source $LIBDIR/env/lib/common.sh
11 if [[ $EUID -ne 0 ]]; then
12 echo "This script must be run as root"
16 function get_default_inteface_ipaddress {
18 local _default_interface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
19 local _ipv4address=$(ip addr show dev $_default_interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
20 eval $_ip="'$_ipv4address'"
24 #ssh key for compute node to communicate back to bootstrap server
25 mkdir -p $BUILD_DIR/ssh_key
26 ssh-keygen -C "compute.icn.akraino.lfedge.org" -f $BUILD_DIR/ssh_key/id_rsa
27 cat $BUILD_DIR/ssh_key/id_rsa.pub >> $HOME/.ssh/authorized_keys
31 _SSH_LOCAL_KEY=$(cat $BUILD_DIR/ssh_key/id_rsa)
34 - path: /opt/ssh_id_rsa
42 provision_compute_node() {
43 IMAGE_URL=http://172.22.0.1/images/${BM_IMAGE}
44 IMAGE_CHECKSUM=http://172.22.0.1/images/${BM_IMAGE}.md5sum
46 if [ ! -d $GOPATH/src/github.com/metal3-io/baremetal-operator ]; then
47 go get github.com/metal3-io/baremetal-operator
50 go run $GOPATH/src/github.com/metal3-io/baremetal-operator/cmd/make-bm-worker/main.go \
51 -address "ipmi://$COMPUTE_IPMI_ADDRESS" \
52 -user "$COMPUTE_IPMI_USER" \
53 -password "$COMPUTE_IPMI_PASSWORD" \
54 "$COMPUTE_NODE_NAME" > $COMPUTE_NODE_NAME-bm-node.yaml
56 printf " image:" >> $COMPUTE_NODE_NAME-bm-node.yaml
57 printf "\n url: ""%s" "$IMAGE_URL" >> $COMPUTE_NODE_NAME-bm-node.yaml
58 printf "\n checksum: ""%s" "$IMAGE_CHECKSUM" >> $COMPUTE_NODE_NAME-bm-node.yaml
59 printf "\n userData:" >> $COMPUTE_NODE_NAME-bm-node.yaml
60 printf "\n name: ""%s" "$COMPUTE_NODE_NAME""-user-data" >> $COMPUTE_NODE_NAME-bm-node.yaml
61 printf "\n namespace: metal3\n" >> $COMPUTE_NODE_NAME-bm-node.yaml
62 kubectl apply -f $COMPUTE_NODE_NAME-bm-node.yaml -n metal3
65 deprovision_compute_node() {
66 kubectl patch baremetalhost $COMPUTE_NODE_NAME -n metal3 --type merge \
67 -p '{"spec":{"image":{"url":"","checksum":""}}}'
70 set_compute_ssh_config() {
71 get_default_inteface_ipaddress default_addr
73 - path: /root/.ssh/config
77 Host bootstrapmachine $default_addr
78 HostName $default_addr
79 IdentityFile /opt/ssh_id_rsa
81 - path: /etc/apt/sources.list
85 deb [trusted=yes] ssh://$USER@$default_addr:$LOCAL_APT_REPO ./
90 printf "#cloud-config\n" > userdata.yaml
91 if [ -n "$COMPUTE_NODE_PASSWORD" ]; then
92 printf "password: ""%s" "$COMPUTE_NODE_PASSWORD" >> userdata.yaml
93 printf "\nchpasswd: {expire: False}\n" >> userdata.yaml
94 printf "ssh_pwauth: True\n" >> userdata.yaml
97 if [ -n "$COMPUTE_NODE_FQDN" ]; then
98 printf "fqdn: ""%s" "$COMPUTE_NODE_FQDN" >> userdata.yaml
99 printf "\n" >> userdata.yaml
101 printf "disable_root: false\n" >> userdata.yaml
102 printf "ssh_authorized_keys:\n - " >> userdata.yaml
104 if [ ! -f $HOME/.ssh/id_rsa.pub ]; then
105 yes y | ssh-keygen -t rsa -N "" -f $HOME/.ssh/id_rsa
108 cat $HOME/.ssh/id_rsa.pub >> userdata.yaml
109 printf "\n" >> userdata.yaml
112 apply_userdata_credential() {
113 cat <<EOF > ./$COMPUTE_NODE_NAME-user-data.yaml
116 userData: $(base64 -w 0 userdata.yaml)
119 name: $COMPUTE_NODE_NAME-user-data
123 kubectl apply -n metal3 -f $COMPUTE_NODE_NAME-user-data.yaml
126 launch_baremetal_operator() {
127 if [ ! -d $GOPATH/src/github.com/metal3-io/baremetal-operator ]; then
128 go get github.com/metal3-io/baremetal-operator
131 pushd $GOPATH/src/github.com/metal3-io/baremetal-operator
137 if [ "$1" == "launch" ]; then
138 launch_baremetal_operator
142 if [ "$1" == "deprovision" ]; then
143 deprovision_compute_node
147 if [ "$1" == "provision" ]; then
149 apply_userdata_credential
150 provision_compute_node
155 echo "Usage: metal3.sh"
156 echo "launch - Launch the metal3 operator"
157 echo "provision - provision baremetal node as specified in common.sh"
158 echo "deprovision - deprovision baremetal node as specified in common.sh"
161 #Following code is tested for the offline mode
162 #Will be intergrated for the offline mode for ICNi v.0.1.0 beta
166 #set_compute_ssh_config