Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libnetplan: expose dhcp4 and dhcp6 properties #394

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/netplan.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ netplan_netdef_has_match(const NetplanNetDefinition* netdef);
NETPLAN_PUBLIC gboolean
netplan_netdef_match_interface(const NetplanNetDefinition* netdef, const char* name, const char* mac, const char* driver_name);

NETPLAN_PUBLIC gboolean
netplan_netdef_get_dhcp4(const NetplanNetDefinition* netdef);

NETPLAN_PUBLIC gboolean
netplan_netdef_get_dhcp6(const NetplanNetDefinition* netdef);

/********** Old API below this ***********/

NETPLAN_DEPRECATED NETPLAN_PUBLIC const char *
Expand Down
2 changes: 2 additions & 0 deletions python-cffi/netplan/_build_cffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
gboolean netplan_netdef_get_delay_virtual_functions_rebind(const NetplanNetDefinition* netdef);
gboolean netplan_netdef_match_interface(
const NetplanNetDefinition* netdef, const char* name, const char* mac, const char* driver_name);
gboolean netplan_netdef_get_dhcp4(const NetplanNetDefinition* netdef);
gboolean netplan_netdef_get_dhcp6(const NetplanNetDefinition* netdef);

// NetDefinition (internal)
ssize_t _netplan_netdef_get_embedded_switch_mode(const NetplanNetDefinition* netdef, char* out_buffer, size_t out_buf_size);
Expand Down
8 changes: 8 additions & 0 deletions python-cffi/netplan/netdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def _match_interface(self, iface_name: str = None, iface_driver: str = None, ifa
def addresses(self) -> '_NetdefAddressIterator':
return _NetdefAddressIterator(self._ptr)

@property
def dhcp4(self) -> bool:
return bool(lib.netplan_netdef_get_dhcp4(self._ptr))

@property
def dhcp6(self) -> bool:
return bool(lib.netplan_netdef_get_dhcp6(self._ptr))

@property
def _has_match(self) -> bool:
return bool(lib.netplan_netdef_has_match(self._ptr))
Expand Down
12 changes: 12 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,18 @@ netplan_netdef_get_set_name(const NetplanNetDefinition* netdef, char* out_buffer
return netplan_copy_string(netdef->set_name, out_buffer, out_buf_size);
}

gboolean
netplan_netdef_get_dhcp4(const NetplanNetDefinition* netdef)
{
return netdef->dhcp4;
}

gboolean
netplan_netdef_get_dhcp6(const NetplanNetDefinition* netdef)
{
return netdef->dhcp6;
}

gboolean
is_multicast_address(const char* address)
{
Expand Down
21 changes: 21 additions & 0 deletions tests/test_libnetplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,27 @@ def test_interface_has_pointer_to_peer(self):
self.assertEqual(state['patch0-1'].links.get('peer').id, "patch1-0")
self.assertEqual(state['patch1-0'].links.get('peer').id, "patch0-1")

def test_dhcp4_dhcp6(self):
state = state_from_yaml(self.confdir, '''network:
ethernets:
eth0:
dhcp4: true
dhcp6: false
''')

self.assertTrue(state['eth0'].dhcp4)
self.assertFalse(state['eth0'].dhcp6)

state = state_from_yaml(self.confdir, '''network:
ethernets:
eth0:
dhcp4: false
dhcp6: true
''')

self.assertFalse(state['eth0'].dhcp4)
self.assertTrue(state['eth0'].dhcp6)


class TestFreeFunctions(TestBase):
def test_create_yaml_patch_dict(self):
Expand Down
Loading