Skip to content
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
2 changes: 1 addition & 1 deletion cloudinit/distros/bsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, name, cfg, paths):
cfg["ssh_svcname"] = "sshd"
cfg["rsyslog_svcname"] = "rsyslogd"
self.osfamily = platform.system().lower()
self.net_ops = bsd_netops
self.net_ops = bsd_netops.BsdNetOps

def _read_system_hostname(self):
sys_hostname = self._read_hostname(self.hostname_conf_fn)
Expand Down
41 changes: 33 additions & 8 deletions cloudinit/net/netops/bsd_netops.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from typing import Optional

import cloudinit.net.netops as netops
from cloudinit import subp


class BsdNetOps(netops.NetOps):
@staticmethod
def link_up(interface: str):
pass
subp.subp(["ifconfig", interface, "up"])

@staticmethod
def link_down(interface: str):
pass
subp.subp(["ifconfig", interface, "down"])

@staticmethod
def add_route(
Expand All @@ -20,11 +21,15 @@ def add_route(
gateway: Optional[str] = None,
source_address: Optional[str] = None
):
pass
subp.subp(["route", "add", route, "-interface", interface])
if gateway and gateway != "0.0.0.0":
subp.subp(
["route", "change", route, gateway],
)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't support source selection

and i had to make this addition in two steps, because when i did it in a single step, the result was nonsense.


@staticmethod
def append_route(interface: str, address: str, gateway: str):
pass
return BsdNetOps.add_route(interface, route=address, gateway=gateway)

@staticmethod
def del_route(
Expand All @@ -34,16 +39,36 @@ def del_route(
gateway: Optional[str] = None,
source_address: Optional[str] = None
):
pass
subp.subp(
["route", "del", address]
+ ([gateway] if gateway and gateway != "0.0.0.0" else []),
)

@staticmethod
def get_default_route() -> str:
pass
std, _ = subp.subp(["route", "-nv", "get", "0.0.0.0/0"])
return std.splitlines()[-1].strip()

@staticmethod
def add_addr(interface: str, address: str, broadcast: str):
pass
subp.subp(
[
"ifconfig",
interface,
address,
"broadcast",
broadcast,
"alias",
],
)

@staticmethod
def del_addr(interface: str, address: str):
pass
subp.subp(
[
"ifconfig",
interface,
address,
"-alias",
],
)