Rollcall: bare-metal commissioning server, agent, image build, lab and CI
Go server (API, embedded web UI, CLI) backed by PostgreSQL with AES-GCM sealed BMC secrets; Debian live commissioning agent and live-build recipe; Proxmox lab with pve-vbmc virtual BMCs; Gitea workflows for CI, releases and deployment; project website. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
commit
d9ae89b295
33 files changed
+3248
No files matched your search
@@ -0,0 +1,86 @@
|
||||
#cloud-config
|
||||
hostname: pxe-server
|
||||
fqdn: pxe-server.mynodes.xyz
|
||||
manage_etc_hosts: true
|
||||
users:
|
||||
- name: ilker
|
||||
sudo: ALL=(ALL) NOPASSWD:ALL
|
||||
shell: /bin/bash
|
||||
lock_passwd: true
|
||||
ssh_authorized_keys:
|
||||
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDSAJ4owXlJreHP3sa4HstasxA5pk1ZAPi6vnzOpA5R1 ilker@t440s
|
||||
package_update: true
|
||||
packages:
|
||||
- qemu-guest-agent
|
||||
- dnsmasq
|
||||
- pxelinux
|
||||
- syslinux-common
|
||||
- syslinux-efi
|
||||
- nftables
|
||||
- curl
|
||||
write_files:
|
||||
- path: /etc/dnsmasq.d/pxe.conf
|
||||
content: |
|
||||
# PXE/DHCP for SDN vnet pxenet (10.213.77.0/24). Only bound to the pxenet leg.
|
||||
interface=__PXEIF__
|
||||
bind-interfaces
|
||||
domain-needed
|
||||
bogus-priv
|
||||
domain=pxe.local
|
||||
local=/pxe.local/
|
||||
expand-hosts
|
||||
dhcp-range=10.213.77.100,10.213.77.200,255.255.255.0,12h
|
||||
dhcp-option=option:router,10.213.77.1
|
||||
dhcp-option=option:dns-server,10.213.77.1
|
||||
dhcp-authoritative
|
||||
enable-tftp
|
||||
tftp-root=/srv/tftp
|
||||
dhcp-match=set:efi64,option:client-arch,7
|
||||
dhcp-match=set:efi64,option:client-arch,9
|
||||
dhcp-match=set:bios,option:client-arch,0
|
||||
dhcp-boot=tag:bios,pxelinux.0
|
||||
dhcp-boot=tag:efi64,efi64/syslinux.efi
|
||||
log-dhcp
|
||||
- path: /srv/tftp/pxelinux.cfg/default
|
||||
content: |
|
||||
DEFAULT menu.c32
|
||||
PROMPT 0
|
||||
TIMEOUT 300
|
||||
MENU TITLE pxe-server (10.213.77.1) - PXE menu
|
||||
|
||||
LABEL netbootxyz
|
||||
MENU LABEL netboot.xyz (internet gerekir, NAT uzerinden)
|
||||
KERNEL netboot.xyz.lkrn
|
||||
|
||||
LABEL local
|
||||
MENU LABEL Yerel diskten boot
|
||||
LOCALBOOT 0
|
||||
- path: /etc/nftables.conf
|
||||
permissions: '0755'
|
||||
content: |
|
||||
#!/usr/sbin/nft -f
|
||||
flush ruleset
|
||||
table ip nat {
|
||||
chain postrouting {
|
||||
type nat hook postrouting priority 100;
|
||||
oifname "__EXTIF__" ip saddr 10.213.77.0/24 masquerade
|
||||
}
|
||||
}
|
||||
- path: /etc/sysctl.d/99-pxe-forward.conf
|
||||
content: |
|
||||
net.ipv4.ip_forward=1
|
||||
runcmd:
|
||||
- sysctl --system
|
||||
- PXEIF=$(ip -o -4 addr show | awk '/10\.213\.77\.1\//{print $2}'); sed -i "s/__PXEIF__/$PXEIF/" /etc/dnsmasq.d/pxe.conf
|
||||
- EXTIF=$(ip -o -4 route show default | awk '{print $5; exit}'); sed -i "s/__EXTIF__/$EXTIF/" /etc/nftables.conf
|
||||
- mkdir -p /srv/tftp/efi64
|
||||
- cp /usr/lib/PXELINUX/pxelinux.0 /srv/tftp/
|
||||
- cp /usr/lib/syslinux/modules/bios/ldlinux.c32 /usr/lib/syslinux/modules/bios/menu.c32 /usr/lib/syslinux/modules/bios/libutil.c32 /usr/lib/syslinux/modules/bios/libcom32.c32 /srv/tftp/
|
||||
- cp /usr/lib/SYSLINUX.EFI/efi64/syslinux.efi /srv/tftp/efi64/
|
||||
- cp /usr/lib/syslinux/modules/efi64/ldlinux.e64 /usr/lib/syslinux/modules/efi64/menu.c32 /usr/lib/syslinux/modules/efi64/libutil.c32 /usr/lib/syslinux/modules/efi64/libcom32.c32 /srv/tftp/efi64/
|
||||
- ln -sfn ../pxelinux.cfg /srv/tftp/efi64/pxelinux.cfg
|
||||
- curl -fsSL --retry 3 -o /srv/tftp/netboot.xyz.lkrn https://boot.netboot.xyz/ipxe/netboot.xyz.lkrn || true
|
||||
- systemctl enable --now nftables
|
||||
- systemctl enable --now qemu-guest-agent
|
||||
- systemctl restart dnsmasq
|
||||
- systemctl enable dnsmasq
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"api": "https://10.0.0.10:8006",
|
||||
"node": "pve1",
|
||||
"token": "root@pam!vbmc=<TOKEN-SECRET>",
|
||||
"verify_tls": false,
|
||||
"user": "admin",
|
||||
"password": "password",
|
||||
"bmcs": [
|
||||
{"vmid": 211, "address": "10.213.77.11", "port": 623},
|
||||
{"vmid": 212, "address": "10.213.77.12", "port": 623}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
# Run on pxe-server as root from the directory containing these files.
|
||||
# Expects /etc/pve-vbmc/config.json to exist already (see config.example.json).
|
||||
set -eu
|
||||
cd "$(dirname "$0")"
|
||||
getent passwd pve-vbmc >/dev/null || useradd --system --no-create-home --shell /usr/sbin/nologin --user-group pve-vbmc
|
||||
install -m 0755 pve_vbmc.py /usr/local/bin/pve_vbmc.py
|
||||
install -m 0755 pve-vbmc-addrs.sh /usr/local/bin/pve-vbmc-addrs.sh
|
||||
install -m 0644 pve-vbmc@.service pve-vbmc-addrs.service /etc/systemd/system/
|
||||
chgrp pve-vbmc /etc/pve-vbmc/config.json && chmod 0640 /etc/pve-vbmc/config.json
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now pve-vbmc-addrs.service
|
||||
for v in $(python3 -c 'import json;print(" ".join(str(b["vmid"]) for b in json.load(open("/etc/pve-vbmc/config.json"))["bmcs"]))'); do
|
||||
systemctl enable --now "pve-vbmc@$v.service"
|
||||
done
|
||||
systemctl --no-pager --type=service | grep pve-vbmc
|
||||
@@ -0,0 +1,13 @@
|
||||
[Unit]
|
||||
Description=pve-vbmc: add one BMC IP alias per VM on the pxenet interface
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/local/bin/pve-vbmc-addrs.sh add
|
||||
ExecStop=/usr/local/bin/pve-vbmc-addrs.sh del
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Adds/removes the BMC listen addresses from /etc/pve-vbmc/config.json
|
||||
# as secondary IPs on the interface that carries the PXE subnet.
|
||||
set -eu
|
||||
CONF=/etc/pve-vbmc/config.json
|
||||
PXE_IF=$(ip -o -4 addr show | awk '/10\.213\.77\.1\//{print $2; exit}')
|
||||
[ -n "$PXE_IF" ] || { echo "pxenet interface not found" >&2; exit 1; }
|
||||
for a in $(python3 -c 'import json;print(" ".join(b["address"] for b in json.load(open("'"$CONF"'"))["bmcs"]))'); do
|
||||
case "$1" in
|
||||
add) ip -4 addr replace "$a/24" dev "$PXE_IF" label "$PXE_IF:bmc" ;;
|
||||
del) ip -4 addr del "$a/24" dev "$PXE_IF" 2>/dev/null || true ;;
|
||||
esac
|
||||
done
|
||||
@@ -0,0 +1,21 @@
|
||||
[Unit]
|
||||
Description=pve-vbmc virtual BMC for Proxmox VM %i
|
||||
After=network-online.target pve-vbmc-addrs.service
|
||||
Wants=network-online.target
|
||||
Requires=pve-vbmc-addrs.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/pve_vbmc.py --config /etc/pve-vbmc/config.json --vmid %i
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
User=pve-vbmc
|
||||
Group=pve-vbmc
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
PrivateTmp=yes
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,160 @@
|
||||
#!/usr/bin/env python3
|
||||
"""pve-vbmc: minimal virtual BMC (IPMI-over-LAN) for Proxmox VE VMs.
|
||||
|
||||
One process serves one VM. It speaks IPMI 2.0 LAN via pyghmi and translates
|
||||
chassis power / boot-device commands into Proxmox API calls.
|
||||
|
||||
Supported ipmitool commands:
|
||||
power status|on|off|soft|cycle|reset
|
||||
chassis bootdev pxe|disk|cdrom|none
|
||||
chassis status, mc info, mc guid
|
||||
"""
|
||||
import argparse
|
||||
import ipaddress
|
||||
import json
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
|
||||
import requests
|
||||
import urllib3
|
||||
from pyghmi.ipmi.bmc import Bmc
|
||||
|
||||
log = logging.getLogger("pve-vbmc")
|
||||
|
||||
|
||||
class PveBmc(Bmc):
|
||||
def __init__(self, cfg, entry):
|
||||
self.api = cfg["api"].rstrip("/")
|
||||
self.node = cfg["node"]
|
||||
self.vmid = int(entry["vmid"])
|
||||
self.http = requests.Session()
|
||||
self.http.headers["Authorization"] = "PVEAPIToken=" + cfg["token"]
|
||||
self.http.verify = cfg.get("verify_tls", False)
|
||||
if not self.http.verify:
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
self.bootdev = "default"
|
||||
self.guid = uuid.uuid5(uuid.NAMESPACE_DNS, f"pve-vbmc-{self.node}-{self.vmid}")
|
||||
|
||||
addr = ipaddress.ip_address(entry["address"])
|
||||
listen = f"::ffff:{addr}" if addr.version == 4 else str(addr)
|
||||
authdata = {entry.get("user", cfg.get("user", "admin")):
|
||||
entry.get("password", cfg.get("password", "password"))}
|
||||
super().__init__(authdata, port=int(entry.get("port", 623)), address=listen)
|
||||
log.info("BMC for VM %s listening on %s:%s", self.vmid, addr, entry.get("port", 623))
|
||||
|
||||
# --- Proxmox API helpers -------------------------------------------------
|
||||
def _url(self, path):
|
||||
return f"{self.api}/api2/json/nodes/{self.node}/qemu/{self.vmid}/{path}"
|
||||
|
||||
def _get(self, path):
|
||||
r = self.http.get(self._url(path), timeout=10)
|
||||
r.raise_for_status()
|
||||
return r.json()["data"]
|
||||
|
||||
def _post(self, path, **data):
|
||||
r = self.http.post(self._url(path), data=data, timeout=30)
|
||||
r.raise_for_status()
|
||||
return r.json()["data"]
|
||||
|
||||
def _put(self, path, **data):
|
||||
r = self.http.put(self._url(path), data=data, timeout=30)
|
||||
r.raise_for_status()
|
||||
return r.json()["data"]
|
||||
|
||||
def _wait_task(self, upid, timeout=60):
|
||||
url = f"{self.api}/api2/json/nodes/{self.node}/tasks/{upid}/status"
|
||||
for _ in range(timeout * 2):
|
||||
r = self.http.get(url, timeout=10)
|
||||
r.raise_for_status()
|
||||
if r.json()["data"]["status"] == "stopped":
|
||||
return r.json()["data"].get("exitstatus")
|
||||
time.sleep(0.5)
|
||||
return "timeout"
|
||||
|
||||
# --- pyghmi Bmc interface -------------------------------------------------
|
||||
def get_system_guid(self):
|
||||
return self.guid
|
||||
|
||||
def get_power_state(self):
|
||||
return "on" if self._get("status/current")["status"] == "running" else "off"
|
||||
|
||||
def is_active(self):
|
||||
return self.get_power_state() == "on"
|
||||
|
||||
def power_on(self):
|
||||
if self.get_power_state() == "off":
|
||||
log.info("VM %s: power on", self.vmid)
|
||||
self._post("status/start")
|
||||
|
||||
def power_off(self):
|
||||
if self.get_power_state() == "on":
|
||||
log.info("VM %s: power off (hard)", self.vmid)
|
||||
self._post("status/stop")
|
||||
|
||||
def power_shutdown(self):
|
||||
log.info("VM %s: soft shutdown", self.vmid)
|
||||
self._post("status/shutdown", forceStop=1, timeout=60)
|
||||
|
||||
def power_reset(self):
|
||||
if self.get_power_state() == "on":
|
||||
log.info("VM %s: reset", self.vmid)
|
||||
self._post("status/reset")
|
||||
else:
|
||||
self.power_on()
|
||||
|
||||
def power_cycle(self):
|
||||
log.info("VM %s: power cycle", self.vmid)
|
||||
if self.get_power_state() == "on":
|
||||
self._wait_task(self._post("status/stop"))
|
||||
self._post("status/start")
|
||||
|
||||
def cold_reset(self):
|
||||
return 0 # BMC reset is a no-op
|
||||
|
||||
def pulse_diag(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_boot_device(self):
|
||||
return self.bootdev
|
||||
|
||||
def set_boot_device(self, bootdevice):
|
||||
cfg = self._get("config")
|
||||
disks = [k for k in ("scsi0", "virtio0", "sata0", "ide0") if k in cfg]
|
||||
cds = sorted(k for k, v in cfg.items() if "media=cdrom" in str(v))
|
||||
nets = sorted(k for k in cfg if k.startswith("net") and k[3:].isdigit())
|
||||
if bootdevice == "network":
|
||||
order = nets + disks + cds
|
||||
elif bootdevice == "hd":
|
||||
order = disks + nets + cds
|
||||
elif bootdevice == "optical":
|
||||
order = cds + disks + nets
|
||||
else: # default / none / safe / setup ...
|
||||
order = disks + cds + nets
|
||||
if order:
|
||||
log.info("VM %s: bootdev %s -> order=%s", self.vmid, bootdevice, ";".join(order))
|
||||
self._put("config", boot="order=" + ";".join(order))
|
||||
self.bootdev = bootdevice
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--config", default="/etc/pve-vbmc/config.json")
|
||||
ap.add_argument("--vmid", type=int, required=True)
|
||||
ap.add_argument("--debug", action="store_true")
|
||||
args = ap.parse_args()
|
||||
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO,
|
||||
format="%(asctime)s %(name)s %(levelname)s %(message)s")
|
||||
with open(args.config) as f:
|
||||
cfg = json.load(f)
|
||||
entry = next((b for b in cfg["bmcs"] if int(b["vmid"]) == args.vmid), None)
|
||||
if entry is None:
|
||||
log.error("vmid %s not in config", args.vmid)
|
||||
sys.exit(2)
|
||||
bmc = PveBmc(cfg, entry)
|
||||
bmc.listen()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user