newvm: Add support for specifying static IP config
Although rare, there are scenarios where we may want to deploy a new virtual machine with a static, manually-configured IP address. Anaconda/Dracut support this via the `ip=` kernel command-line argument. To simplify populating that argument, the `newvm` script now takes additional command-line arguments for IP address (in CIDR prefix), default gateway, and name server address(es) and creates the appropriate string from these discrete values.
This commit is contained in:
62
newvm.sh
62
newvm.sh
@@ -14,6 +14,27 @@ console=true
|
|||||||
default_groups=true
|
default_groups=true
|
||||||
graphics=false
|
graphics=false
|
||||||
|
|
||||||
|
gen_dracut_ipconfig() {
|
||||||
|
local hostname=$1
|
||||||
|
local ip_address=$2
|
||||||
|
local gateway=$3
|
||||||
|
local nameserver=$4
|
||||||
|
|
||||||
|
local netmask=$(ipcalc --no-decorate --netmask "${ip_address}")
|
||||||
|
if [ -z "${gateway}" ]; then
|
||||||
|
gateway=$(ipcalc --no-decorate --minaddr "${ip_address}")
|
||||||
|
fi
|
||||||
|
ip_address=$(ipcalc --no-decorate --address "${ip_address}")
|
||||||
|
|
||||||
|
printf 'ip=%s::%s:%s:%s::none:%s\n' \
|
||||||
|
"${ip_address}" \
|
||||||
|
"${gateway}" \
|
||||||
|
"${netmask}" \
|
||||||
|
"${hostname}" \
|
||||||
|
"${nameserver}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
printf 'usage: %s [options] name\n' "${0##*/}"
|
printf 'usage: %s [options] name\n' "${0##*/}"
|
||||||
}
|
}
|
||||||
@@ -70,6 +91,27 @@ while [ $# -gt 0 ]; do
|
|||||||
--network=*)
|
--network=*)
|
||||||
network="${1#*=}"
|
network="${1#*=}"
|
||||||
;;
|
;;
|
||||||
|
--ip-address)
|
||||||
|
shift
|
||||||
|
ip_address=$1
|
||||||
|
;;
|
||||||
|
--ip-address=*)
|
||||||
|
ip_address=${1#*=}
|
||||||
|
;;
|
||||||
|
--gateway)
|
||||||
|
shift
|
||||||
|
gateway=$1
|
||||||
|
;;
|
||||||
|
--gateway=*)
|
||||||
|
gateway=${1#*=}
|
||||||
|
;;
|
||||||
|
--nameserver)
|
||||||
|
shift
|
||||||
|
nameserver=$1
|
||||||
|
;;
|
||||||
|
--nameserver=*)
|
||||||
|
nameserver=${1#=*}
|
||||||
|
;;
|
||||||
--domain)
|
--domain)
|
||||||
shift
|
shift
|
||||||
dnsdomain=$1
|
dnsdomain=$1
|
||||||
@@ -138,6 +180,24 @@ if [ -z "${LIBVIRT_DEFAULT_URI}" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
case ${ip_address} in
|
||||||
|
'')
|
||||||
|
ipconfig="ip=::::${hostname}::dhcp"
|
||||||
|
;;
|
||||||
|
*/*)
|
||||||
|
ipconfig=$(gen_dracut_ipconfig \
|
||||||
|
"${hostname}" \
|
||||||
|
"${ip_address}" \
|
||||||
|
"${gateway}" \
|
||||||
|
"${nameserver}"
|
||||||
|
)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf 'Invalid IP configuration: missing prefix length\n' >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
if [ ${fedora} -gt 40 ] && [ ${memory} -lt 4096 ]; then
|
if [ ${fedora} -gt 40 ] && [ ${memory} -lt 4096 ]; then
|
||||||
printf 'WARNING Fedora 41+ requires at least 4 GB memory to install\n' >&2
|
printf 'WARNING Fedora 41+ requires at least 4 GB memory to install\n' >&2
|
||||||
memory=4096
|
memory=4096
|
||||||
@@ -163,7 +223,7 @@ else
|
|||||||
printf 'Using HTTP proxy: %s\n' "${http_proxy}" >&2
|
printf 'Using HTTP proxy: %s\n' "${http_proxy}" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
extra_args="ip=::::${hostname}::dhcp inst.ks=${kickstart}"
|
extra_args="${ipconfig} inst.ks=${kickstart}"
|
||||||
if [ -n "${http_proxy}" ]; then
|
if [ -n "${http_proxy}" ]; then
|
||||||
extra_args="${extra_args} inst.proxy=${http_proxy}"
|
extra_args="${extra_args} inst.proxy=${http_proxy}"
|
||||||
if [ ${fedora} -lt 40 ]; then
|
if [ ${fedora} -lt 40 ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user