4 LIBDIR="$(dirname "$(dirname "$(dirname "$PWD")")")"
8 BM_OPERATOR="${BM_OPERATOR:-https://github.com/metal3-io/baremetal-operator.git}"
10 source $LIBDIR/env/lib/common.sh
12 if [[ $EUID -ne 0 ]]; then
13 echo "This script must be run as root"
17 function get_default_inteface_ipaddress() {
19 local _default_interface=$(awk '$2 == 00000000 { print $1 }' /proc/net/route)
20 local _ipv4address=$(ip addr show dev $_default_interface | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
21 eval $_ip="'$_ipv4address'"
25 #ssh key for compute node to communicate back to bootstrap server
26 mkdir -p $BUILD_DIR/ssh_key
27 ssh-keygen -C "compute.icn.akraino.lfedge.org" -f $BUILD_DIR/ssh_key/id_rsa
28 cat $BUILD_DIR/ssh_key/id_rsa.pub >> $HOME/.ssh/authorized_keys
32 _SSH_LOCAL_KEY=$(cat $BUILD_DIR/ssh_key/id_rsa)
35 - path: /opt/ssh_id_rsa
43 provision_compute_node() {
44 IMAGE_URL=http://172.22.0.1/images/${BM_IMAGE}
45 IMAGE_CHECKSUM=http://172.22.0.1/images/${BM_IMAGE}.md5sum
47 if [ ! -d $GOPATH/src/github.com/metal3-io/baremetal-operator ]; then
48 go get github.com/metal3-io/baremetal-operator
51 go run $GOPATH/src/github.com/metal3-io/baremetal-operator/cmd/make-bm-worker/main.go \
52 -address "ipmi://$COMPUTE_IPMI_ADDRESS" \
53 -user "$COMPUTE_IPMI_USER" \
54 -password "$COMPUTE_IPMI_PASSWORD" \
55 "$COMPUTE_NODE_NAME" > $COMPUTE_NODE_NAME-bm-node.yaml
57 printf " image:" >> $COMPUTE_NODE_NAME-bm-node.yaml
58 printf "\n url: ""%s" "$IMAGE_URL" >> $COMPUTE_NODE_NAME-bm-node.yaml
59 printf "\n checksum: ""%s" "$IMAGE_CHECKSUM" >> $COMPUTE_NODE_NAME-bm-node.yaml
60 printf "\n userData:" >> $COMPUTE_NODE_NAME-bm-node.yaml
61 printf "\n name: ""%s" "$COMPUTE_NODE_NAME""-user-data" >> $COMPUTE_NODE_NAME-bm-node.yaml
62 printf "\n namespace: metal3\n" >> $COMPUTE_NODE_NAME-bm-node.yaml
63 kubectl apply -f $COMPUTE_NODE_NAME-bm-node.yaml
66 deprovision_compute_node() {
67 kubectl patch baremetalhost $COMPUTE_NODE_NAME -n metal3 --type merge \
68 -p '{"spec":{"image":{"url":"","checksum":""}}}'
71 set_compute_ssh_config() {
72 get_default_inteface_ipaddress default_addr
74 - path: /root/.ssh/config
78 Host bootstrapmachine $default_addr
79 HostName $default_addr
80 IdentityFile /opt/ssh_id_rsa
82 - path: /etc/apt/sources.list
86 deb [trusted=yes] ssh://$USER@$default_addr:$LOCAL_APT_REPO ./
91 printf "#cloud-config\n" > userdata.yaml
92 if [ -n "$COMPUTE_NODE_PASSWORD" ]; then
93 printf "password: ""%s" "$COMPUTE_NODE_PASSWORD" >> userdata.yaml
94 printf "\nchpasswd: {expire: False}\n" >> userdata.yaml
95 printf "ssh_pwauth: True\n" >> userdata.yaml
98 if [ -n "$COMPUTE_NODE_FQDN" ]; then
99 printf "fqdn: ""%s" "$COMPUTE_NODE_FQDN" >> userdata.yaml
100 printf "\n" >> userdata.yaml
103 printf "ssh_authorized_keys:\n - " >> userdata.yaml
105 if [ -f $HOME/.ssh/id_rsa.pub ]; then
106 yes y | ssh-keygen -t rsa -N "" -f $HOME/.ssh/id_rsa
109 cat $HOME/.ssh/id_rsa.pub >> userdata.yaml
110 printf "\n" >> userdata.yaml
113 apply_userdata_credential() {
114 cat <<EOF > ./$COMPUTE_NODE_NAME-user-data.yaml
117 userData: $(base64 -w 0 userdata.yaml)
120 name: $COMPUTE_NODE_NAME-user-data
124 kubectl apply -n metal3 -f $COMPUTE_NODE_NAME-user-data.yaml
127 launch_baremetal_operator() {
128 if [ ! -d $GOPATH/src/github.com/metal3-io/baremetal-operator ]; then
129 go get github.com/metal3-io/baremetal-operator
132 pushd $GOPATH/src/github.com/metal3-io/baremetal-operator
138 if [ "$1" == "launch" ]; then
139 launch_baremetal_operator
143 if [ "$1" == "deprovision" ]; then
144 deprovision_compute_node
148 if [ "$1" == "provision" ]; then
150 apply_userdata_credential
151 provision_compute_node
156 echo "Usage: metal3.sh"
157 echo "launch - Launch the metal3 operator"
158 echo "provision - provision baremetal node as specified in common.sh"
159 echo "deprovision - deprovision baremetal node as specified in common.sh"
162 #Following code is tested for the offline mode
163 #Will be intergrated for the offline mode for ICNi v.0.1.0 beta
167 #set_compute_ssh_config