-
Notifications
You must be signed in to change notification settings - Fork 13
Description
See xPU sZTP provisioning block
today we pass lease file via cmdline arguments like this: --dhcp-lease-file /var/lib/dhclient/dhclient.leases.
but can we detect that info automatically from Network Manager over dbus ?
spec https://networkmanager.dev/
for example I found:
root@bf2:~# nmcli -f DHCP4 device show oob_net0
DHCP4.OPTION[1]: broadcast_address = 172.22.255.255
DHCP4.OPTION[2]: dad_wait_time = 0
DHCP4.OPTION[3]: dhcp_lease_time = 600
DHCP4.OPTION[4]: dhcp_message_type = 5
DHCP4.OPTION[5]: dhcp_server_identifier = 172.22.0.1
DHCP4.OPTION[6]: domain_name = lab.opiproject.org
DHCP4.OPTION[7]: domain_name_servers = 8.8.8.8 1.1.1.1
DHCP4.OPTION[8]: expiry = 1718831245
DHCP4.OPTION[9]: ip_address = 172.22.3.2
DHCP4.OPTION[10]: network_number = 172.22.0.0
DHCP4.OPTION[11]: next_server = 172.22.0.1
DHCP4.OPTION[12]: requested_broadcast_address = 1
DHCP4.OPTION[13]: requested_domain_name = 1
DHCP4.OPTION[14]: requested_domain_name_servers = 1
DHCP4.OPTION[15]: requested_domain_search = 1
DHCP4.OPTION[16]: requested_host_name = 1
DHCP4.OPTION[17]: requested_interface_mtu = 1
DHCP4.OPTION[18]: requested_ms_classless_static_routes = 1
DHCP4.OPTION[19]: requested_netbios_name_servers = 1
DHCP4.OPTION[20]: requested_netbios_scope = 1
DHCP4.OPTION[21]: requested_ntp_servers = 1
DHCP4.OPTION[22]: requested_rfc3442_classless_static_routes = 1
DHCP4.OPTION[23]: requested_root_path = 1
DHCP4.OPTION[24]: requested_routers = 1
DHCP4.OPTION[25]: requested_static_routes = 1
DHCP4.OPTION[26]: requested_subnet_mask = 1
DHCP4.OPTION[27]: requested_sztp_redirect_urls = 1
DHCP4.OPTION[28]: requested_time_offset = 1
DHCP4.OPTION[29]: requested_wpad = 1
DHCP4.OPTION[30]: routers = 172.22.0.1
DHCP4.OPTION[31]: subnet_mask = 255.255.0.0
DHCP4.OPTION[32]: sztp_redirect_urls = https://bootstrap:8080/restconf/operations/ietf-sztp-bootstrap-server:get-bootstrapping-data
or using dbus directly:
root@bf2:~# busctl -j call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects | jq .[] | grep -C 3 sztp
"type": "s",
"data": "1"
},
"requested_sztp_redirect_urls": {
"type": "s",
"data": "1"
},
--
"type": "s",
"data": "255.255.0.0"
},
"sztp_redirect_urls": {
"type": "s",
"data": "https://bootstrap:8080/restconf/operations/ietf-sztp-bootstrap-server:get-bootstrapping-data"
}
}
}
Working example in python:
>>> import dbus
>>>
>>> bus = dbus.SystemBus()
>>> nm = bus.get_object("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager")
>>> conn = bus.get_object("org.freedesktop.NetworkManager", nm.Get("org.freedesktop.NetworkManager", "PrimaryConnection", dbus_interface="org.freedesktop.DBus.Properties"))
>>> dhcp = bus.get_object("org.freedesktop.NetworkManager", conn.Get("org.freedesktop.NetworkManager.Connection.Active", "Dhcp4Config", dbus_interface="org.freedesktop.DBus.Properties"))
>>> options = dhcp.Get("org.freedesktop.NetworkManager.DHCP4Config", "Options", dbus_interface="org.freedesktop.DBus.Properties")
>>> print(str(options["sztp_redirect_urls"]))
https://bootstrap:8080/restconf/operations/ietf-sztp-bootstrap-server:get-bootstrapping-data
Now need to find go bindings for it...
Maybe https://github.com/Wifx/gonetworkmanager ?
like https://pkg.go.dev/github.com/Wifx/gonetworkmanager#DHCP4Config
Or maybe raw https://github.com/godbus/dbus
For running in containers please mount the host dbus into the container. This can simply be done by adding -v /var/run/dbus:/var/run/dbus to your docker run command. Depending on what kind of permissions are required you may need to add --privileged to the command as well.
Please evaluate...