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

Added support for the 'bridge' command. #123

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
25 changes: 25 additions & 0 deletions rrmngmnt/network.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import logging
import netaddr
import os
Expand Down Expand Up @@ -479,6 +480,30 @@ def delete_bridge(self, bridge):
self._cmd(cmd_del_br)
return True

@keep_session
def get_bridges(self):
"""
Gets a host's bridges details using the 'bridge' command.

Returns:
list[dict]: a list of dicts where each dict represents a bridge,
and has the keys:
* "ifname" -> str
The interface enslaved to the bridge.
* "flags" -> list[str]
A list of flags associated with the bridge.
* "mtu" -> int
The MTU configured on the bridge.
* "master" -> str
The bridge name.
* "state" -> str
* "priority" -> int
* "cost" -> int
* "ifindex" -> int
"""
raw_bridges = self._cmd(shlex.split("bridge -j link show"))
return json.loads(s=raw_bridges)

@keep_session
def get_info(self):
"""
Expand Down
39 changes: 39 additions & 0 deletions tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ class TestNetwork(object):
__test__ = True

data = {
"bridge -j link show": (
0,
'[{"ifindex":2,"ifname":"enp1s0f0","flags":'
'["BROADCAST","MULTICAST","UP","LOWER_UP"],'
'"mtu":1500,"master":"ovirtmgmt","state":"forwarding",'
'"priority":32,"cost":100},'
'{"ifindex":9,"ifname":"virbr0-nic","flags":'
'["BROADCAST","MULTICAST"],'
'"mtu":1500,"master":"virbr0","state":"disabled",'
'"priority":32,"cost":100}]',
""
),
'ip route': (
0,
'\n'.join(
Expand Down Expand Up @@ -279,6 +291,33 @@ def test_add_ip_with_subnet_mask(self):
nic="eth0", ip="1.2.3.4", mask="255.255.255.0"
)

def test_get_bridges(self):
assert (
get_host().network.get_bridges() ==
[
{
"ifindex": 2,
"ifname": "enp1s0f0",
"flags": ["BROADCAST", "MULTICAST", "UP", "LOWER_UP"],
"mtu": 1500,
"master": "ovirtmgmt",
"state": "forwarding",
"priority": 32,
"cost": 100
},
{
"ifindex": 9,
"ifname": "virbr0-nic",
"flags": ["BROADCAST", "MULTICAST"],
"mtu": 1500,
"master": "virbr0",
"state": "disabled",
"priority": 32,
"cost": 100
}
]
)


class TestHostNameCtl(object):

Expand Down