/usr/bin/maas-enlist is in maas-enlist 0.4+bzr38-0ubuntu3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | #!/bin/sh
#
# maas-enlist: MAAS Enlistment Tool
#
# Copyright (C) 2012 Canonical Ltd.
#
# Authors: Andres Rodriguez <andres.rodriguez@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
get_mac_addresses() {
macs=`ip addr | egrep 'link/ether' | cut -d' ' -f6`
for i in $macs;
do
if [ -z "$mac_address" ]; then
mac_address="$i";
else
mac_address="$mac_address,$i"
fi
done
echo "$mac_address"
}
get_mac_address_by_interface() {
iface="$1"
mac=`ip addr sh "$iface" | egrep -m1 'link/ether' | cut -d' ' -f6`
echo "$mac"
}
get_mac_address_parms() {
local args="" input_string="$1"
OIFS=$IFS; IFS=","; set -- $input_string; IFS=$OIFS
for i in "$@";
do
args="${args}&mac_addresses=${i}"
#mac_address="$mac_address""&mac_addresses=""${i}";
done
echo "${args# }"
}
get_host_architecture() {
if grep "flags" /proc/cpuinfo | grep -qs "\ lm\ "; then
# if /proc/cpuinfo Flags has 'lm', it is x86_64
arch="amd64"
else
arch=`archdetect | cut -d'/' -f1`
fi
echo "$arch"
}
get_host_subarchitecture() {
local arch=$1
case $arch in
i386|amd64)
# Skip the call to archdetect as that's what
# get_host_architecture does
echo generic
;;
*)
archdetect | cut -d'/' -f2
;;
esac
}
get_server_name() {
local servername="$1";
_RET=${servername#*://};
_RET=${_RET%%/*};
echo "$_RET";
}
enlist_node() {
serverurl="${1}"
mac="${2}"
arch="${3}"
subarch="${4}"
hostname="${5}"
power_type="${6}"
power_params="${7}"
local macparms=""
macparms=$(get_mac_address_parms "$mac")
local params="op=new"
params="${params}&autodetect_nodegroup=1"
params="${params}&hostname=${hostname}"
params="${params}&architecture=${arch}"
params="${params}&subarchitecture=${subarch}"
params="${params}&after_commissioning_action=0"
params="${params}&power_type=${power_type}"
params="${params}&power_parameters=${power_params}"
params="${params}${macparms}"
wget -q -O/dev/null \
"${serverurl}" \
--post-data="$params"
}
Error () {
echo "ERROR: $1"
exit 1
}
Usage() {
cat <<EOF
Usage: ${0##*/} [ options ]
node enlistment into the MAAS server
options:
-s | --serverurl resolvable MAAS server API URL (maas.local if not specified)
-n | --hostname hostname of the node to register
-i | --interface interface address to register (obtains MAC address)
-a | --arch architecture of the node to register
-t | --power-type power type (ipmi, virsh, ether_wake)
-p | --power-params power parameters (In JSON format, between single quotes)
e.g. --power-params '{"power_address":"192.168.1.10"}'
--subarch subarchitecture of the node to register
Example:
- ${0##*/} --serverurl 127.0.0.1 --interface eth0
EOF
}
bad_Usage() { Usage 1>&2; [ $# -eq 0 ] || Error "$@"; exit 1; }
short_opts="hs:n:i:a:t:p:"
long_opts="help,serverurl:,hostname:,interface:,arch:,subarch:,power-type:,power-params:"
getopt_out=$(getopt --name "${0##*/}" \
--options "${short_opts}" --long "${long_opts}" -- "$@") &&
eval set -- "${getopt_out}" ||
bad_Usage
while [ $# -ne 0 ]; do
cur=${1}; next=${2};
case "$cur" in
-h|--help) Usage ; exit 0;;
-s|--serverurl) serverurl=${2}; shift;;
-n|--hostname) hostname=${2}; shift;;
-i|--interface) iface=${2}; shift;;
-a|--arch) arch=${2}; shift;;
--subarch) subarch=${2}; shift;;
-t|--power-type) power_type=${2}; shift;;
-p|--power-params) power_parameters=${2}; shift;;
--) shift; break;;
esac
shift;
done
## check arguments here
#[ $# -eq 0 ] && bad_Usage
# If no interface is specified. obtain the MAC from all interfaces
if [ -z "$iface" ]; then
mac_addrs=$(get_mac_addresses)
else
mac_addrs=$(get_mac_address_by_interface "$iface")
fi
protocol=
servername=$(get_server_name "$serverurl")
if echo "$serverurl" | egrep -q '^[a-z]+://' ; then
protocol=`echo "$serverurl" | sed 's#^\([a-z]\+\)://.*#\\1#'`
else
protocol="http"
fi
if [ "$protocol" != "http" ] && [ "$protocol" != "https" ]; then
Error "Invalid protocol '$protocol'"
fi
if [ -z "$servername" ]; then
serverurl="maas.local"
servername="$serverurl"
fi
if echo "$serverurl" | egrep -q '(^[a-z]+://|^)[a-z0-9\.]+($|/$)'; then
api_url="MAAS/api/1.0/nodes/"
else
api_url=`echo $serverurl | sed 's#^\(\|[a-z]\+://\)[a-zA-Z0-9\.]\+\(\|\:[0-9]\+\)/##'`
fi
#TODO: Auto-detect hostname?
if [ -z "$hostname" ]; then
continue
#Error "No hostname has been provided"
fi
if [ -z "$arch" ]; then
arch=$(get_host_architecture)
fi
if [ -z "$subarch" ]; then
subarch=$(get_host_subarchitecture $arch)
fi
if [ -n "$power_type" ]; then
case $power_type in
ipmi) continue ;;
virsh) continue ;;
etherwake) continue ;;
moonshot) continue ;;
*) Error "Invalid power type: [$power_type]"
esac
fi
enlist_node "$protocol://$servername/$api_url" "${mac_addrs}" "$arch" "$subarch" "$hostname" "$power_type" "$power_parameters"
|