def test_direct_dhcp(self, *args, **kwargs): mb = defaults.NicBonding() mt = defaults.NetworkLayout() m = defaults.Network() mb.configure_8023ad("bond0", ["ens1", "ens2", "ens3"]) m.configure_dhcp("bond0") mt.configure_direct() run_tx_by_name(m.transaction(), "WriteConfiguration") assert ifcfg_has_items("bond0", [('BONDING_OPTS', 'mode=4'), ('BOOTPROTO', 'dhcp'), ('DEVICE', 'bond0'), ('HWADDR', 'th:em:ac:ad:dr'), ('ONBOOT', 'yes'), ('PEERNTP', 'yes')]) assert ifcfg_has_items("ens1", [('DEVICE', 'ens1'), ('MASTER', 'bond0'), ('ONBOOT', 'yes'), ('SLAVE', 'yes')]) assert ifcfg_has_items("ens2", [('DEVICE', 'ens2'), ('MASTER', 'bond0'), ('ONBOOT', 'yes'), ('SLAVE', 'yes')]) assert ifcfg_has_items("ens3", [('DEVICE', 'ens3'), ('MASTER', 'bond0'), ('ONBOOT', 'yes'), ('SLAVE', 'yes')]) assert len(FakeFs.filemap) == (1 + 1 + 3)
def _configure_nic(self, bootproto, ipaddr, netmask, gateway, ipv6_bootproto, ipv6_address, ipv6_netmask, ipv6_gateway, vlanid, layout_bridged): vlanid = vlanid or None iface = self._model_extra["dialog.nic.ifname"] model = defaults.Network() ipv6model = defaults.IPv6() if bootproto == "none": self.logger.debug("Configuring no networking") model.configure_no_networking(iface) elif bootproto == "dhcp": self.logger.debug("Configuring dhcp") model.configure_dhcp(iface, vlanid) elif bootproto == "static": self.logger.debug("Configuring static ip") model.configure_static(iface, ipaddr, netmask, gateway, vlanid) else: self.logger.debug("No ipv4 interface configuration found") # A hack to also set the BOOTIF when IPv& is used in a second enable_bootif = lambda: model.update(iface=iface) if ipv6_bootproto == "none": self.logger.debug("Configuring no ipv6 networking") ipv6model.disable() elif ipv6_bootproto == "dhcp": self.logger.debug("Configuring ipv6 dhcp") enable_bootif() ipv6model.configure_dhcp() elif ipv6_bootproto == "auto": self.logger.debug("Configuring ipv6 auto") enable_bootif() ipv6model.configure_auto() elif ipv6_bootproto == "static": self.logger.debug("Configuring ipv6 static ip") enable_bootif() ipv6model.configure_static(ipv6_address, ipv6_netmask, ipv6_gateway) else: self.logger.debug("No ipv6 interface configuration found") mt = defaults.NetworkLayout() if layout_bridged: mt.configure_bridged() # Return the resulting transaction txs = model.transaction() # FIXME the ipv6 transaction is IDENTICAL to the model.tranasaction() # (just a call to the legacy code to reconfigure networking) # Therefor we don't add it, to not call it twice. # But it should be added to the ocmplete transaction when the backend # code is more fine granular. #txs += ipv6model.transaction() return txs
def test_tagged_dhcp(self, *args, **kwargs): mt = defaults.NetworkLayout() m = defaults.Network() m.configure_dhcp("p1p2", "42") mt.configure_bridged() run_tx_by_name(m.transaction(), "WriteConfiguration") assert ifcfg_has_items("p1p2", [('DEVICE', 'p1p2'), ('HWADDR', 'th:em:ac:ad:dr'), ('NM_CONTROLLED', 'no'), ('ONBOOT', 'yes')]) assert ifcfg_has_items("p1p2.42", [('BRIDGE', 'brp1p2'), ('DEVICE', 'p1p2.42'), ('NM_CONTROLLED', 'no'), ('ONBOOT', 'yes'), ('VLAN', 'yes')]) assert ifcfg_has_items("brp1p2", [('BOOTPROTO', 'dhcp'), ('DELAY', '0'), ('DEVICE', 'brp1p2'), ('IPV6INIT', 'no'), ('IPV6_AUTOCONF', 'no'), ('NM_CONTROLLED', 'no'), ('ONBOOT', 'yes'), ('PEERNTP', 'yes'), ('TYPE', 'Bridge')])
def test_tagged_bridged_dhcp(self, *args, **kwargs): mb = defaults.NicBonding() mt = defaults.NetworkLayout() m = defaults.Network() mb.configure_8023ad("bond0", ["ens1", "ens2", "ens3"]) m.configure_dhcp("bond0", "42") mt.configure_bridged() run_tx_by_name(m.transaction(), "WriteConfiguration") assert ifcfg_has_items("ens1", [('DEVICE', 'ens1'), ('HWADDR', 'th:em:ac:ad:dr'), ('MASTER', 'bond0'), ('ONBOOT', 'yes'), ('SLAVE', 'yes')]) assert ifcfg_has_items("ens2", [('DEVICE', 'ens2'), ('HWADDR', 'th:em:ac:ad:dr'), ('MASTER', 'bond0'), ('ONBOOT', 'yes'), ('SLAVE', 'yes')]) assert ifcfg_has_items("ens3", [('DEVICE', 'ens3'), ('HWADDR', 'th:em:ac:ad:dr'), ('MASTER', 'bond0'), ('ONBOOT', 'yes'), ('SLAVE', 'yes')]) assert ifcfg_has_items("bond0", [('BONDING_OPTS', 'mode=4'), ('DEVICE', 'bond0'), ('ONBOOT', 'yes'), ('TYPE', 'Bond')]) assert ifcfg_has_items("bond0.42", [('BRIDGE', 'brbond0'), ('DEVICE', 'bond0.42'), ('ONBOOT', 'yes'), ('VLAN', 'yes')]) assert ifcfg_has_items("brbond0", [('BOOTPROTO', 'dhcp'), ('DELAY', '0'), ('DEVICE', 'brbond0'), ('ONBOOT', 'yes'), ('PEERNTP', 'yes'), ('TYPE', 'Bridge')])
def test_dhcp(self, *args, **kwargs): m = defaults.Network() mt = defaults.NetworkLayout() mt.configure_bridged() m.configure_dhcp("eth0") run_tx_by_name(m.transaction(), "WriteConfiguration") assert ifcfg_has_items("eth0", [('BRIDGE', 'breth0'), ('DEVICE', 'eth0'), ('HWADDR', 'th:em:ac:ad:dr'), ('ONBOOT', 'yes')]) assert ifcfg_has_items("breth0", [('BOOTPROTO', 'dhcp'), ('DELAY', '0'), ('DEVICE', 'breth0'), ('ONBOOT', 'yes'), ('PEERNTP', 'yes'), ('TYPE', 'Bridge')])
def test_dhcp(self, *args, **kwargs): """Test bridgeless with DHCP configuration file creation """ mt = defaults.NetworkLayout() m = defaults.Network() mt.configure_direct() m.configure_dhcp("eth0") run_tx_by_name(m.transaction(), "WriteConfiguration") assert ifcfg_has_items("eth0", [('BOOTPROTO', 'dhcp'), ('DEVICE', 'eth0'), ('HWADDR', 'th:em:ac:ad:dr'), ('ONBOOT', 'yes'), ('PEERNTP', 'yes')]) assert "breth0" not in FakeFs.filemap
def test_dhcp(self, *args, **kwargs): mt = defaults.NetworkLayout() m = defaults.Network() mt.configure_direct() m.configure_dhcp("eth0") run_tx_by_name(m.transaction(), "WriteConfiguration") assert ifcfg_has_items("eth0", [('BOOTPROTO', 'dhcp'), ('DEVICE', 'eth0'), ('HWADDR', 'th:em:ac:ad:dr'), ('IPV6INIT', 'no'), ('IPV6_AUTOCONF', 'no'), ('NM_CONTROLLED', 'no'), ('ONBOOT', 'yes'), ('PEERNTP', 'yes')]) assert "breth0" not in FakeFs.filemap
def test_static(self, *args, **kwargs): mt = defaults.NetworkLayout() m = defaults.Network() mt.configure_direct() m.configure_static("ens1", "192.168.122.42", "255.255.255.0", "192.168.122.1", None) run_tx_by_name(m.transaction(), "WriteConfiguration") assert ifcfg_has_items("ens1", [('DEVICE', 'ens1'), ('GATEWAY', '192.168.122.1'), ('HWADDR', 'th:em:ac:ad:dr'), ('IPADDR', '192.168.122.42'), ('NETMASK', '255.255.255.0'), ('ONBOOT', 'yes'), ('PEERNTP', 'yes')]) assert "brens1" not in FakeFs.filemap
def test_static(self, *args, **kwargs): m = defaults.Network() mt = defaults.NetworkLayout() mt.configure_bridged() m.configure_static("ens1", "192.168.122.42", "255.255.255.0", "192.168.122.1", None) run_tx_by_name(m.transaction(), "WriteConfiguration") assert ifcfg_has_items("ens1", [('BRIDGE', 'brens1'), ('DEVICE', 'ens1'), ('HWADDR', 'th:em:ac:ad:dr'), ('NM_CONTROLLED', 'no'), ('ONBOOT', 'yes')]) assert ifcfg_has_items("brens1", [('DELAY', '0'), ('DEVICE', 'brens1'), ('GATEWAY', '192.168.122.1'), ('IPADDR', '192.168.122.42'), ('IPV6INIT', 'no'), ('IPV6_AUTOCONF', 'no'), ('NETMASK', '255.255.255.0'), ('NM_CONTROLLED', 'no'), ('ONBOOT', 'yes'), ('PEERNTP', 'yes'), ('TYPE', 'Bridge')])
def migrate_network_layout(self): from ovirt.node.config import defaults from ovirt.node.utils import network bondcfg = defaults.NicBonding().retrieve() netlayoutcfg = defaults.NetworkLayout().retrieve() if bondcfg["name"] or netlayoutcfg["layout"]: # We can only reliably import pre node-3.0 # network configurations, therefor we abort # the import if it looks like a node-3.0 config self.logger.info("Looks like node-3.0 network, skipping import") return bridges = [x for x in network.Bridges().ifnames() if x.startswith("br")] bridged_nics = [x for x in network.all_ifaces() if network.NIC(x).config.bridge in bridges] self.logger.debug("Found bridges: %s" % bridges) self.logger.debug("Found bridged NICs: %s" % bridged_nics) def cfgset(k, v, prefix="OVIRT_"): if v: self.logger.debug(" Setting %s = %s" % (k, v)) self.aug.set("/files/etc/default/ovirt/%s%s" % (prefix, k), str(v)) found_mgmt = False for brn in ["rhevm", "ovirtmgmt"]: if brn in network.Bridges().ifnames(): self.logger.debug("Found managed nic: %s" % brn) cfgset("MANAGED_BY", "RHEV-M", "") cfgset("MANAGED_IFNAMES", brn, "") found_mgmt = True break self.logger.debug("Found management: %s" % found_mgmt) if not found_mgmt and bridges and bridged_nics: self.logger.debug("Assuming default bridged network") self.aug.set("/files/etc/default/ovirt/OVIRT_NETWORK_LAYOUT", "bridged") ifname = bridged_nics[0] br = bridges[0] vlanid = None self.logger.debug("Bridge and NIC: %s %s" % (br, ifname)) probably_vlan = "." in ifname if probably_vlan: ifname, vlanid = ifname.split(".", 1) self.logger.debug("Found VLAN setup, base NIC: %s %s" % (ifname, vlanid)) self.aug.set("/files/etc/default/ovirt/OVIRT_BOOTIF", ifname) def ifcfg(i, k): v = self.aug.get("/files/etc/sysconfig/network-" + "scripts/ifcfg-%s/%s" % (i, k)) self.logger.debug(" Getting %s.%s = %s" % (i, k, v)) return v proto = ifcfg(br, "BOOTPROTO") cfgset("BOOTPROTO", proto) addr = ifcfg(br, "IPADDR") if addr: cfgset("IP_ADDRESS", addr) cfgset("IP_GATEWAY", ifcfg(br, "GATEWAY")) cfgset("IP_NETMASK", ifcfg(br, "NETMASK")) if vlanid: cfgset("VLAN", vlanid)
def __init__(self, plugin, ifname): super(NicDetailsDialog, self).__init__("dialog.nic", "NIC Details: %s" % ifname, []) self.plugin = plugin # Populate model with nic specific informations self.logger.debug("Building NIC details dialog for %s" % ifname) nic = utils.network.NodeNetwork().nics()[ifname] model = defaults.Network().retrieve() ip6model = defaults.IPv6().retrieve() m_layout = defaults.NetworkLayout().retrieve() self.logger.debug("nic: %s" % nic) self.logger.debug("model: %s" % model) self.logger.debug("ip6model: %s" % ip6model) is_primary_interface = model["iface"] == ifname if not is_primary_interface: # The config contains the information for the primary ifnamee, # because this ifnamee is not the primaryifnameme we clear the # config model = dict((k, "") for k in model.keys()) ipaddr, netmask, gateway, vlanid = (model["ipaddr"], model["netmask"], model["gateway"], model["vlanid"]) ip6addr, ip6netmask, ip6gateway, ip6bootproto = (ip6model["ipaddr"], ip6model["netmask"], ip6model["gateway"], ip6model["bootproto"]) bootproto = model["bootproto"] if model["bootproto"] == "dhcp": if nic.exists(): routes = utils.network.Routes() gateway = routes.default() ipaddr, netmask = nic.ipv4_address().items() vlanid = ",".join(nic.vlanids()) else: if ipaddr: bootproto = "static" link_status_txt = ("Connected" if nic.has_link() else "Disconnected") vendor_txt = nic.vendor[:24] if nic.vendor else "" self.plugin._model_extra.update({ "dialog.nic.driver": nic.driver, "dialog.nic.vendor": vendor_txt, "dialog.nic.link_status": link_status_txt, "dialog.nic.hwaddress": nic.hwaddr, "dialog.nic.ipv4.bootproto": bootproto, "dialog.nic.ipv4.address": ipaddr, "dialog.nic.ipv4.netmask": netmask, "dialog.nic.ipv4.gateway": gateway, "dialog.nic.ipv6.bootproto": ip6bootproto, "dialog.nic.ipv6.address": ip6addr, "dialog.nic.ipv6.netmask": ip6netmask, "dialog.nic.ipv6.gateway": ip6gateway, "dialog.nic.vlanid": vlanid, "dialog.nic.layout_bridged": m_layout["layout"] == "bridged", }) self.logger.debug("model: %s" % self.plugin.model()) padd = lambda l: l.ljust(12) ws = [ ui.Row("dialog.nic._row[0]", [ ui.KeywordLabel("dialog.nic.driver", padd("Driver: ")), ui.KeywordLabel("dialog.nic.vendor", padd("Vendor: ")), ]), ui.Row("dialog.nic._row[2]", [ ui.KeywordLabel("dialog.nic.link_status", padd("Link Status: ")), ui.KeywordLabel("dialog.nic.hwaddress", padd("MAC Address: ")), ]), ui.Divider("dialog.nic._divider[0]"), ui.Label("dialog.nic.ipv4._header", "IPv4 Settings"), ui.Options("dialog.nic.ipv4.bootproto", "Bootprotocol: ", [("none", "Disabled"), ("dhcp", "DHCP"), ("static", "Static")]), ui.Row("dialog.nic._row[4]", [ ui.Entry("dialog.nic.ipv4.address", padd("IP Address: ")), ui.Entry("dialog.nic.ipv4.netmask", padd(" Netmask: ")) ]), ui.Row("dialog.nic._row[5]", [ ui.Entry("dialog.nic.ipv4.gateway", padd("Gateway: ")), ui.Label("dummy[0]", "") ]), ui.Divider("dialog.nic._divider[1]"), ui.Label("dialog.nic.ipv6._header", "IPv6 Settings"), ui.Options("dialog.nic.ipv6.bootproto", "Bootprotocol: ", [("none", "Disabled"), ("auto", "Auto"), ("dhcp", "DHCP"), ("static", "Static")]), ui.Row("dialog.nic._row[6]", [ ui.Entry("dialog.nic.ipv6.address", padd("IP Address: ")), ui.Entry("dialog.nic.ipv6.netmask", padd(" Prefix Length: ")) ]), ui.Row("dialog.nic._row[7]", [ ui.Entry("dialog.nic.ipv6.gateway", padd("Gateway: ")), ui.Label("dummy[1]", "") ]), ui.Divider("dialog.nic._divider[2]"), ui.Row("dialog.nic._row[8]", [ ui.Entry("dialog.nic.vlanid", padd("VLAN ID: ")), ui.Label("dummy[2]", "") ]), ui.Divider("dialog.nic._divider[3]"), ui.Checkbox("dialog.nic.layout_bridged", "Use Bridge: "), ui.Divider("dialog.nic._divider[4]"), ui.Button("dialog.nic.identify", "Flash Lights to Identify"), ] self.plugin.widgets.add(ws) self.children = ws self.buttons = [ ui.SaveButton("dialog.nic.save", "Save"), ui.CloseButton("dialog.nic.close", "Close") ] self.plugin._nic_details_group.enabled(False) self.plugin.widgets["dialog.nic.vlanid"].enabled(True) self.plugin.widgets["dialog.nic.layout_bridged"].enabled(True)