2021-10-29 09:57:19 +01:00

14 lines
982 B
Bash
Executable File

#!/bin/bash
export MACHINE_NAME=$1
export STATIC_IP=$2
export SUBNET_NAME=$3
export SUBNET_ID=$(maas root subnets read | jq '.[] | {id:.id,name:.name}' --compact-output | grep $SUBNET_NAME | jq .id)
export SYSTEM_ID=$(maas root nodes read | jq '.[] | {hostname:.hostname,system_id: .system_id, status:.status}' --compact-output | grep $MACHINE_NAME | jq .system_id | awk -F"\"" '{print $2}')
export EXISTING_LINK_ID=$(maas root interfaces read ${SYSTEM_ID} | jq '.[] | .links[] | {link_id:.id, mode:.mode, subnet:.subnet.name}' --compact-output | grep $SUBNET_NAME | jq .link_id)
export NIC_ID=$(maas root interfaces read ${SYSTEM_ID} | jq '.[] | {iface_id:.id, name:.name, mac:.mac_address, subnet:.subnet.name, link: .links}' --compact-output | grep ${EXISTING_LINK_ID} | jq .iface_id)
maas root interface unlink-subnet ${SYSTEM_ID} ${NIC_ID} id=${EXISTING_LINK_ID}
maas root interface link-subnet ${SYSTEM_ID} ${NIC_ID} mode=STATIC subnet=${SUBNET_ID} ip_address=${STATIC_IP}