summaryrefslogtreecommitdiffstats
path: root/server/ipxe
diff options
context:
space:
mode:
authorJannik Schönartz2019-03-25 06:43:55 +0100
committerJannik Schönartz2019-03-25 06:43:55 +0100
commit752d9c18bb531544f28bdbfd00b5eb922e07d3d8 (patch)
tree5c4773c2556b0a3aa928574c7ef63a996113c22d /server/ipxe
parenteslint fix (diff)
downloadbas-752d9c18bb531544f28bdbfd00b5eb922e07d3d8.tar.gz
bas-752d9c18bb531544f28bdbfd00b5eb922e07d3d8.tar.xz
bas-752d9c18bb531544f28bdbfd00b5eb922e07d3d8.zip
[external-backends/idoit] Add server rack segmentation & add multiple ip support
Diffstat (limited to 'server/ipxe')
-rwxr-xr-xserver/ipxe/bash_scripts/addServer.sh158
-rwxr-xr-xserver/ipxe/bash_scripts/grepSystemInfoRework.sh2
-rw-r--r--server/ipxe/registration.ipxe2
3 files changed, 148 insertions, 14 deletions
diff --git a/server/ipxe/bash_scripts/addServer.sh b/server/ipxe/bash_scripts/addServer.sh
index ad6e3aa..69088bf 100755
--- a/server/ipxe/bash_scripts/addServer.sh
+++ b/server/ipxe/bash_scripts/addServer.sh
@@ -1,21 +1,90 @@
#!/bin/bash
-json_data()
-{
- cat << EOF
+
+
+# We mostly do not care about the return value in function local variable
+# assignments. So we can write the declaration and assignment in one line.
+
+
+
+die() {
+ echo -e "$*" 1>&2
+ exit 1
+}
+
+
+
+usage() {
+ local file="$(basename "$0")"
+
+ die "$file {-r|--rack}=<rack>" \
+ "{-s|--slot}=<slot>" \
+ "[{-b|--bay}=<bay>]" \
+ "[{-i|--interface=<vlan_interface>}]" \
+ "[--rack-height=<height_in_u>]"
+}
+
+
+
+parse_mgmt() {
+ local host="$1"; shift
+
+ local dev="$(ipmitool lan print 1)"
+ cat <<END
+ {
+ "ip": "$(awk '/IP Address\s+:/ {print $4}' <<<"$dev")",
+ "mac": "$(awk '/MAC Address\s+:/ {print $4}' <<<"$dev")",
+ "hostname": "$host.rz.privat"
+ }
+END
+}
+
+
+
+parse_ips() {
+ local host="$1"; shift
+ local if="$1"; shift
+
+ # Requires `moreutils` to be installed, but easier to parse and less error
+ # prone.
+ local ip_frag="$(ifdata -pa "$if" | cut -d. -f3-)"
+ local mac="$(ifdata -ph "$if")"
+ cat <<END
+ {
+ "ip": "10.19.$ip_frag",
+ "mac": "$mac",
+ "hostname": "$host.bwcloud.privat"
+ },
+ {
+ "ip": "10.16.$ip_frag",
+ "mac": "$mac",
+ "hostname": "$host.nemo.privat"
+ }
+END
+}
+
+
+
+json_data() {
+ local pos=$(( rack_height - slot + 1 ))
+ local hostname="$(hostname -s)"
+
+ cat << EOF
{
"client": {
- "parents": [709403],
+ "parents": [$rack],
"type": "SERVER",
+ "name": "$hostname",
"uuid": "$(dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr '[a-z]' '[A-Z]')",
- "network": {
- "mac": "$(ip addr show | grep -Eo -m 1 'ether\s.*\sbrd' | awk '{print $2}')",
- "ip": "$(hostname -I | awk '{print $1}')"
- },
+ "networks": [
+$(parse_mgmt "$hostname"),
+$(parse_ips "$hostname" "$interface")
+ ],
"location": {
"option": "Horizontal",
- "insertion": "Back",
- "pos": 46
+ "insertion": "Front and backside",
+ "slot": $pos,
+ "bay": 1
},
"formfactor": {
"formfactor": "19\"",
@@ -27,5 +96,70 @@ json_data()
EOF
}
-curl -d "$(json_data)" -H "Content-Type: application/json" -X POST --insecure https://bas.intra.uni-freiburg.de/api/registration
-# curl --data "$(json_data)" -H "Content-Type: application/json" -X POST --insecure https://bas.stfu-kthx.net:8888/api/registration \ No newline at end of file
+
+
+args=$(
+ getopt -o b:i:r:s:h \
+ -l bay:,interface:,rack:,rack-height:,slot:,help \
+ -n "$0" \
+ -- \
+ "$@"
+) || usage
+eval set -- "$args"
+
+
+
+bay=0
+interface=boot0.259
+slot=
+rack=
+rack_height=47
+while true; do
+ case "$1" in
+ -b|--bay)
+ bay="$2"
+ echo "Note: This is currently a no-op."
+ echo "Bays need to be implemented first!"
+ shift 2
+ ;;
+ -d|--interface)
+ interface="$2"
+ shift 2
+ ;;
+ -r|--rack)
+ rack="$2"
+ shift 2
+ ;;
+ --rack-height)
+ rack_height="$2";
+ shift 2
+ ;;
+ -s|--slot)
+ slot="$2"
+ shift 2
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -h|--help|*)
+ usage
+ ;;
+ esac
+done
+[[ -z $slot || -z $rack ]] && usage
+
+
+
+case "$rack" in
+ 36|n36|r3s6) rack=19034 ;;
+ 47|n47|r4s7) rack=19045 ;;
+ *) die "Error: unknown rack!" ;;
+esac
+
+(( slot > 47 || slot < 1 )) && die "Error: Slot not in valid range!"
+
+
+
+# json_data
+curl -d "$(json_data)" -H "Content-Type: application/json" -X POST --insecure https://bas.intra.uni-freiburg.de/api/registration/clients
diff --git a/server/ipxe/bash_scripts/grepSystemInfoRework.sh b/server/ipxe/bash_scripts/grepSystemInfoRework.sh
index bdc59b8..ad553fa 100755
--- a/server/ipxe/bash_scripts/grepSystemInfoRework.sh
+++ b/server/ipxe/bash_scripts/grepSystemInfoRework.sh
@@ -168,4 +168,4 @@ EOF
# curl --data "state=6" --insecure https://bas.stfu-kthx.net:8888/api/registrations/$UUID/state
# curl -d "name=Client_$UUID&sys_manufacturer=$MANUFACTURER&sys_model=$MODEL&sys_serial=$SERIAL&cpu_model=$CPU_MODEL&cpu_manufacturer=$CPU_MANUFACTURER&cpu_type=$CPU_TYPE&cpu_cores=$CPU_CORES&cpu_frequency=$CPU_FREQUENCY&ram_size=$RAM_SIZE&ram_manufacturer=$RAM_MANUFACTURER&ram_type=$RAM_TYPE&ram_isecc=$RAM_ISECC&ram_formfactor=$RAM_FORMFACTOR&drives=${DRIVES[*]}" -H "Content-Type: application/x-www-form-urlencoded" -X POST --insecure https://bas.intra.uni-freiburg.de/api/registration/$UUID/update
#echo $(json_data)
-curl -d "$(json_data)" -H "Content-Type: application/json" -X POST --insecure https://bas.intra.uni-freiburg.de/api/registration/$UUID \ No newline at end of file
+curl -d "$(json_data)" -H "Content-Type: application/json" -X POST --insecure https://bas.intra.uni-freiburg.de/api/registration/clients/$UUID \ No newline at end of file
diff --git a/server/ipxe/registration.ipxe b/server/ipxe/registration.ipxe
index 40d6a2a..53f4b01 100644
--- a/server/ipxe/registration.ipxe
+++ b/server/ipxe/registration.ipxe
@@ -27,7 +27,7 @@ goto start
:automatic
params
param ipxe true
-param client { "type": "CLIENT", "uuid": "${uuid}", "purpose": "Pool PC", "network": { "ip": "${net0/ip}", "mac": "${net0/mac}" } }
+param client { "type": "CLIENT", "uuid": "${uuid}", "purpose": "Pool PC", "networks": [{ "ip": "${net0/ip}", "mac": "${net0/mac}" }] }
chain https://bas.intra.uni-freiburg.de/api/registration##params
:key