Skip to content

Commit

Permalink
modules: misc: Improvements on ip address setting
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleidea committed Nov 8, 2024
1 parent 0c0583a commit 43bd847
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions modules/misc/main.mcl
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,15 @@ Name=${dev}
}

# network_manager_static sets up a static ip address with network manager.
# NOTE: to see what it's using run: nmcli -f name,uuid,filename connection
# NOTE: To see what it's using run: `nmcli -f name,uuid,filename connection`.
class network_manager_static($st) {
$uuid = $st->uuid || "" # 01234567-89ab-cdef-0123-456789abcdef
$mac = $st->mac || ""
$dev = $st->dev || "eth0"
$cidr = $st->cidr # cidr
$ip = net.cidr_to_ip($cidr)
$prefix = net.cidr_to_prefix($cidr)
$router = $st->router
$router = $st->router || ""
$dns = $st->dns || "8.8.8.8"

$tmpl =
Expand All @@ -80,13 +81,23 @@ uuid=${uuid}
{{ end -}}
type=ethernet
interface-name=${dev}
autoconnect=true

[ipv4]
{{ if .router -}}
address1=${ip}/${prefix},${router}
{{ else -}}
address1=${ip}/${prefix}
{{ end -}}
dns=${dns};
dns-search=
may-fail=false
method=manual

[ethernet]
{{ if .mac -}}
mac-address=${mac}
{{ end -}}
"

$args = struct{
Expand Down

0 comments on commit 43bd847

Please sign in to comment.