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
-}
-
function deprovision_compute_node {
name="$1"
if kubectl get baremetalhost $name -n metal3 &>/dev/null; then
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 {
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
done
}
-function configure_ironic_offline {
- if [ ! -d $CONTAINER_IMAGES_DIR ] && [ ! -d $BUILD_DIR ]; then
- exit 1
- fi
-
- for image in ironic-inspector-image ironic-image \
- baremetal-operator socat; do
- if [ ! -f "$CONTAINER_IMAGES_DIR/$image" ]; then
- exit 1
- fi
- done
-
- if [ ! -f "$BUILD_DIR/ironic-python-agent.initramfs"] && [ ! -f \
- "$BUILD_DIR/ironic-python-agent.kernel" ] && [ ! -f
- "$BUILD_DIR/$BM_IMAGE" ]; then
- exit 1
- fi
-
- docker load --input $CONTAINER_IMAGES_DIR/baremetal-operator.tar
- docker load --input $CONTAINER_IMAGES_DIR/socat.tar
-
- mkdir -p "$IRONIC_DATA_DIR/html/images"
-
- cp $BUILD_DIR/ironic-python-agent.initramfs $IRONIC_DATA_DIR/html/images/
- cp $BUILD_DIR/ironic-python-agent.kernel $IRONIC_DATA_DIR/html/images/
- cp $BUILD_DIR/$BM_IMAGE $IRONIC_DATA_DIR/html/images/
- md5sum $BUILD_DIR/$BM_IMAGE | awk '{print $1}' > $BUILD_DIR/${BM_IMAGE}.md5sum
-}
-
function configure_ironic {
- if [ "$1" == "offline" ]; then
- configure_ironic_offline
- return
- fi
-
for name in ironic ironic-inspector dnsmasq httpd mariadb ipa-downloader; do
sudo docker ps | \
grep -w "$name$" && sudo docker kill "$name"
}
function configure {
- configure_ironic $1
+ configure_ironic
configure_ironic_bridge
configure_ironic_interfaces
}
-if [ "$#" -eq 0 ]; then
- configure online
-elif [ "$1" == "-o" ]; then
- configure offline
-else
- exit 1
-fi
+configure
+++ /dev/null
-#!/usr/bin/env bash
-set -eux -o pipefail
-shopt -s extglob
-
-source $(dirname $PWD)/../lib/common.sh
-source $(dirname $PWD)/../lib/logging.sh
-
-if [[ $EUID -ne 0 ]]; then
- echo "This script must be run as root"
- exit 1
-fi
-
-if [[ $(lsb_release -d | cut -f2) != $UBUNTU_BIONIC ]]; then
- echo "Currently Ubuntu 18.04.2 LTS is only supported"
- exit 1
-fi
-
-function download_essential_packages {
- apt-get update
- for package in crudini curl dnsmasq figlet golang nmap patch psmisc \
- python3-pip python3-requests python3-setuptools vim wget; do
- apt-get -d install $package -y
- done
- update-alternatives --install /usr/bin/python python /usr/bin/python3 1
- update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
-}
-
-function download_container_images {
- check_docker
- pushd $CONTAINER_IMAGES_DIR
- #docker images for Kubernetes
- for images in kube-apiserver kube-controller-manager kube-scheduler kube-proxy; do
- docker pull k8s.gcr.io/$images:v1.15.0;
- docker save --output $images.tar k8s.gcr.io/$images;
- done
-
- docker pull k8s.gcr.io/pause:3.1
- docker save --output pause.tar k8s.gcr.io/pause
-
- docker pull k8s.gcr.io/etcd:3.3.10
- docker save --output etcd.tar k8s.gcr.io/etcd
-
- docker pull k8s.gcr.io/coredns:1.3.1
- docker save --output coredns.tar k8s.gcr.io/coredns
-
- popd
-}
-
-function download_build_packages {
- check_curl
- pushd $BUILD_DIR
- if [ ! -f ironic-python-agent.initramfs ]; then
- curl --insecure --compressed \
- -L https://images.rdoproject.org/train/rdo_trunk/current-tripleo/ironic-python-agent.tar | tar -xf -
- fi
-
- if [[ "$BM_IMAGE_URL" && "$BM_IMAGE" ]]; then
- curl -o ${BM_IMAGE} --insecure --compressed -O -L ${BM_IMAGE_URL}
- md5sum ${BM_IMAGE} | awk '{print $1}' > ${BM_IMAGE}.md5sum
- fi
-
- if [ ! -d baremetal-operator ]; then
- git clone https://github.com/metal3-io/baremetal-operator.git
- pushd ./baremetal-operator
- git checkout -b icn_baremetal_operator 11ea02ab5cab8b3ab14972ae7c0e70206bba00b5
- popd
- fi
-
- if [ ! -d ironic-inspector-image ]; then
- git clone https://github.com/metal3-io/ironic-inspector-image.git
- pushd ./ironic-inspector-image
- git checkout -b icn_ironic_inspector_image 25431bd5b7fc87c6f3cfb8b0431fe66b86bbab0e
- popd
- fi
-
- if [ ! -d ironic-image ]; then
- git clone https://github.com/metal3-io/ironic-image.git
- pushd ./ironic-image
- git checkout -b icn_ironic_image 329eb4542f0d8d0f0e9cf0d7e550e33b07efe7fb
- popd
- fi
-}
-
-function check_pip {
- if ! which pip ; then
- apt-get install python3-pip -y
- fi
- update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
-}
-
-function check_curl {
- if ! which curl ; then
- apt-get install curl -y
- fi
-}
-
-function check_apt_tools {
- if ! which add-apt-repository ; then
- apt-get install software-properties-common -y
- fi
-}
-
-function download_ironic_packages {
- for package in jq nodejs python3-ironicclient \
- python3-ironic-inspector-client python3-lxml python3-netaddr \
- python3-openstackclient unzip genisoimage; do
- apt-get -d install $package -y
- done
-
- check_pip
- pip download lolcat yq -d $PIP_CACHE_DIR
-}
-
-function check_docker {
- if which docker ; then
- return
- fi
-
- apt-get remove -y docker \
- docker-engine \
- docker.io \
- containerd \
- runc \
- docker-ce
- apt-get update
- for package in apt-transport-https ca-certificates gnupg-agent \
- software-properties-common; do
- apt-get -d install $package -y
- done
-
- check_curl
- check_apt_tools
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- add-apt-repository \
- "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
- $(lsb_release -cs) \
- stable"
- apt-get update
- apt-get install docker-ce=19.03.15~3-0~ubuntu-bionic -y
-}
-
-function download_docker_packages {
- apt-get remove -y docker \
- docker-engine \
- docker.io \
- containerd \
- runc \
- docker-ce
- apt-get update
- for package in apt-transport-https ca-certificates gnupg-agent \
- software-properties-common; do
- apt-get -d install $package -y
- done
-
- check_curl
- check_apt_tools
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- add-apt-repository \
- "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
- $(lsb_release -cs) \
- stable"
- apt-get update
- apt-get -d install docker-ce=19.03.15~3-0~ubuntu-bionic -y
-}
-
-function download_kubernetes_packages {
- curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
- bash -c 'cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
-deb https://apt.kubernetes.io/ kubernetes-xenial main
-EOF'
- apt-get update
- apt-get install -d kubelet=1.15.0-00 kubeadm=1.15.0-00 kubectl=1.15.0-00 -y
-}
-
-function clean_apt_cache {
- pushd /var/cache/apt/archives
-
- if [ $(ls -1q . | wc -l ) -ge 3 ]; then
- $(rm !("lock"|"partial"))
- fi
- popd
-
-}
-
-function mv_apt_cache {
- pushd /var/cache/apt/archives
-
- if [ $(ls -1q . | wc -l ) -gt 2 ]; then
- $(mv !("lock"|"partial") $LOCAL_APT_REPO)
- fi
- popd
-}
-
-function check_dir {
- if [ ! -d $1 ]; then
- mkdir -p $1
- fi
-}
-
-function clean_dir {
- pushd $1
-
- if [ $(ls -1q . | wc -l ) -ne 0 ]; then
- $(rm -r ./*)
- fi
- popd
-}
-
-clean_apt_cache
-check_dir $LOCAL_APT_REPO
-clean_dir $LOCAL_APT_REPO
-check_dir $PIP_CACHE_DIR
-clean_dir $PIP_CACHE_DIR
-check_dir $BUILD_DIR
-clean_dir $BUILD_DIR
-check_dir $CONTAINER_IMAGES_DIR
-clean_dir $CONTAINER_IMAGES_DIR
-download_essential_packages
-download_ironic_packages
-download_docker_packages
-download_kubernetes_packages
-download_build_packages
-download_container_images
-mv_apt_cache