Fabian Deutsch has uploaded a new change for review. Change subject: [DRAFT] network: Add BondedNIC model ......................................................................
[DRAFT] network: Add BondedNIC model This model is used to provide a unified API to bonded NICs (slaves). That analogous to what we do with bridged or tagged NICs. Change-Id: Ic6aac336bf2fd9f7e08d6e7c3e39ebc5fa494f05 Signed-off-by: Fabian Deutsch <[email protected]> --- M src/ovirt/node/utils/network.py 1 file changed, 62 insertions(+), 7 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/25/15725/1 diff --git a/src/ovirt/node/utils/network.py b/src/ovirt/node/utils/network.py index 420deb6..ddc9d42 100644 --- a/src/ovirt/node/utils/network.py +++ b/src/ovirt/node/utils/network.py @@ -330,10 +330,10 @@ bridge_nic = None slave_nic = None - def __init__(self, snic, bnic): + def __init__(self, snic): super(BridgedNIC, self).__init__(snic.ifname) self.slave_nic = snic - self.bridge_nic = bnic + self.bridge_nic = NIC(snic.config.bridge) self.config = self.bridge_nic.config def exists(self): @@ -379,6 +379,10 @@ parent_nic = None def __init__(self, vnic): + """A unified API for tagged NICs + Args: + vnic: A NIC instance pointing to the tagged part of a device + """ parent_ifname, _ = TaggedNIC._parent_and_vlanid_from_name(vnic.ifname) super(TaggedNIC, self).__init__(parent_ifname) self.vlan_nic = vnic @@ -435,6 +439,56 @@ return self.build_str(["ifname"], additional_pairs=pairs) +class BondedNIC(NIC): + """A class to provide easy access to bonded NICs + """ + master_nic = None + slave_nic = None + + def __init__(self, snic): + """Handle snic like beeing a slave of a bond device + """ + master_ifname, _ = snic.config.master + super(TaggedNIC, self).__init__(master_ifname) + self.slave_nic = snic + self.master_nic = NIC(master_ifname) + + def exists(self): + return self.master_nic.exists() + + def is_configured(self): + return self.master_nic.is_configured() + + def has_link(self): + return self.master_nic.has_link() + + def ipv4_address(self): + return self.master_nic.ipv4_address() + + def ipv6_address(self): + return self.master_nic.ipv6_address() + + def ip_addresses(self, families=["inet", "inet6"]): + return self.master_nic.ip_addresses(families=families) + + def is_vlan(self): + return self.master_nic.is_vlan() + + def has_vlans(self): + return self.master_nic.has_vlans() + + def vlanids(self): + return self.master_nic.vlanids() + + def identify(self): + self.slave_nic.identify() + + def __str__(self): + pairs = {"slave": self.slave_nic.ifname, + "master": self.master_nic.ifname} + return self.build_str(["ifname"], additional_pairs=pairs) + + class NodeNetwork(base.Base): def all_ifnames(self): return all_ifaces() @@ -486,15 +540,16 @@ nic = NIC(ifname) if nic.config.bridge and nic.config.vlan: - nic = BridgedNIC(TaggedNIC(nic), - NIC(nic.config.bridge)) + nic = BridgedNIC(TaggedNIC(nic)) elif nic.config.bridge: - nic = BridgedNIC(NIC(nic.ifname), - NIC(nic.config.bridge)) + nic = BridgedNIC(nic) elif nic.config.vlan: - nic = TaggedNIC(NIC(nic.ifname)) + nic = TaggedNIC(nic) + + elif nic.config.master: + nic = BondedNIC(nic) return nic -- To view, visit http://gerrit.ovirt.org/15725 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic6aac336bf2fd9f7e08d6e7c3e39ebc5fa494f05 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-node Gerrit-Branch: master Gerrit-Owner: Fabian Deutsch <[email protected]> _______________________________________________ node-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/node-patches
