Fabian Deutsch has uploaded a new change for review. Change subject: [DRAFT] ui: Expose bond creation ......................................................................
[DRAFT] ui: Expose bond creation Change-Id: Ib3f4e7a5918ebc651474cbb11c10b696e101c7f8 Signed-off-by: Fabian Deutsch <[email protected]> --- M src/ovirt/node/setup/core/network_page.py 1 file changed, 83 insertions(+), 24 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/15/15715/1 diff --git a/src/ovirt/node/setup/core/network_page.py b/src/ovirt/node/setup/core/network_page.py index d1313a8..b2a1261 100644 --- a/src/ovirt/node/setup/core/network_page.py +++ b/src/ovirt/node/setup/core/network_page.py @@ -32,10 +32,46 @@ """ +class NicTable(ui.Table): + def __init__(self, path, height=3, multi=False): + header = "Device Status Model MAC Address" + if multi: + header = " " + header + + super(NicTable, self).__init__(path, + "Available System NICs", + header, + self._get_nics(), + height=height, multi=multi), + + def _get_nics(self): + def justify(txt, l): + txt = txt if txt else "" + return txt.ljust(l)[0:l] + node_nics = [] + first_nic = None + model = utils.network.NodeNetwork() + for name, nic in sorted(model.nics().items()): + if first_nic is None: + first_nic = name + is_cfg = "Configured" if nic.is_configured() else "Unconfigured" + description = " ".join([justify(nic.ifname, 7), + justify(is_cfg, 13), + justify(nic.vendor, 14), + justify(nic.hwaddr, 17) + ]) + node_nics.append((name, description)) + node_nics.append(("foo", "foooo")) + return node_nics + + class Plugin(plugins.NodePlugin): """This is the network page """ - _model_extra = {} + _model_extra = {"bond.slaves.selected": []} + + _nic_details_group = None + _bond_group = None def __init__(self, app): super(Plugin, self).__init__(app) @@ -48,6 +84,11 @@ "dialog.nic.ipv6.netmask", "dialog.nic.ipv6.gateway", "dialog.nic.vlanid", "dialog.nic.layout_bridged"]) + + self._bond_group = self.widgets.group([ + "bond.name", + "bond.slaves", + "bond.options"]) def name(self): return "Network" @@ -86,6 +127,9 @@ ip_or_empty = valid.IPAddress() | valid.Empty() fqdn_ip_or_empty = valid.FQDNOrIPAddress() | valid.Empty() + valid_bond_name = valid.RegexValidator("^bond[0-9]+|007$", + "a valid bond name (bond[0-9])") + return {"hostname": fqdn_ip_or_empty, "dns[0]": ip_or_empty, "dns[1]": ip_or_empty, @@ -100,6 +144,8 @@ "dialog.nic.ipv6.gateway": valid.IPv6Address() | valid.Empty(), "dialog.nic.vlanid": (valid.Number(bounds=[0, 4096]) | valid.Empty()), + + "bond.name": valid_bond_name } def ui_content(self): @@ -115,35 +161,18 @@ ui.Entry("ntp[0]", "NTP Server 1:"), ui.Entry("ntp[1]", "NTP Server 2:"), ui.Divider("divider[2]"), - ui.Table("nics", "Available System NICs", - "Device Status Model MAC Address", - self._get_nics()), - ui.Button("button.ping", "Ping") + NicTable("nics", height=3), + + ui.Row("row[0]", + [ui.Button("button.ping", "Ping"), + ui.Button("button.create_bond", "Create Bond") + ]) ] page = ui.Page("page", ws) # Save it "locally" as a dict, for better accessability self.widgets.add(page) return page - - def _get_nics(self): - def justify(txt, l): - txt = txt if txt else "" - return txt.ljust(l)[0:l] - node_nics = [] - first_nic = None - model = utils.network.NodeNetwork() - for name, nic in sorted(model.nics().items()): - if first_nic is None: - first_nic = name - is_cfg = "Configured" if nic.is_configured() else "Unconfigured" - description = " ".join([justify(nic.ifname, 7), - justify(is_cfg, 13), - justify(nic.vendor, 14), - justify(nic.hwaddr, 17) - ]) - node_nics.append((name, description)) - return node_nics def _build_dialog(self, path, txt, widgets): self.widgets.add(widgets) @@ -193,6 +222,12 @@ self.widgets["dialog.nic.vlanid"].enabled(True) self.widgets["dialog.nic.ipv6.bootproto"].enabled(True) + if "bond.slaves" in changes: + self._model_extra["bond.slaves.selected"] = \ + self.widgets["bond.slaves"].selection() + elif "bond.name" in changes and changes["bond.name"] == "007": + self.widgets["bond.options"].text("Bartender: Shaken or stirred?") + def on_merge(self, effective_changes): self.logger.info("Saving network stuff") changes = Changeset(self.pending_changes(False)) @@ -214,6 +249,11 @@ if "dialog.nic.close" in changes: self._nic_dialog.close() return + + if "button.create_bond" in changes: + d = CreateBondDialog("dialog.bond") + self.widgets.add(d) + return d if "button.ping" in changes: self.logger.debug("Opening ping page") @@ -265,6 +305,15 @@ # Fetch the values for the nic keys, they are used as arguments args = effective_model.values_for(self._nic_details_group) txs += self._configure_nic(*args) + + if effective_changes.contains_any(self._bond_group): + mb = defaults.NicBonding() + args = effective_model.values_for(["bond.name", + "bond.slaves.selected", + "bond.options"]) + self.logger.debug("args: %s" % args) + mb.update(*args) + txs += mb.transaction() progress_dialog = ui.TransactionProgressDialog("dialog.txs", txs, self) progress_dialog.run() @@ -480,3 +529,13 @@ ui.CloseButton("dialog.nic.close", "Close") ] self.plugin._nic_details_group.enabled(False) + + +class CreateBondDialog(ui.Dialog): + def __init__(self, path): + widgets = [ui.Entry("bond.name", "Name:"), + ui.Divider("bond.divider[0]"), + ui.Entry("bond.options", "Options:"), + ui.Divider("bond.divider[1]"), + NicTable("bond.slaves", multi=True)] + super(CreateBondDialog, self).__init__(path, "Create Bond", widgets) -- To view, visit http://gerrit.ovirt.org/15715 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib3f4e7a5918ebc651474cbb11c10b696e101c7f8 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
