[gnome-boxes] libvirt-machine-props: Allow changing network iface
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] libvirt-machine-props: Allow changing network iface
- Date: Mon, 9 Dec 2013 23:22:00 +0000 (UTC)
commit b2128c245b0d58fb8cf22f21f8a0861aba2b0fa5
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Sat Jan 12 03:43:50 2013 +0200
libvirt-machine-props: Allow changing network iface
Allow changing network interface from properties view.
Co-author: Alexander Larsson <alexl redhat com>
https://bugzilla.gnome.org/show_bug.cgi?id=677688
src/libvirt-machine-properties.vala | 39 +++++++++++++++++++++++++++++++++++
src/vm-configurator.vala | 10 ++++++++-
2 files changed, 48 insertions(+), 1 deletions(-)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 25d4933..01341f9 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -53,6 +53,18 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
notify_reboot_required ();
}
+ private void try_change_network_interface (bool bridge, bool virtio) throws GLib.Error {
+ var config = machine.domain.get_config (GVir.DomainXMLFlags.INACTIVE);
+
+ VMConfigurator.remove_network_interface (config);
+ VMConfigurator.add_network_interface (config, bridge, virtio);
+
+ // This will take effect only after next reboot
+ machine.domain.set_config (config);
+ if (machine.is_on ())
+ notify_reboot_required ();
+ }
+
private string collect_logs () {
var builder = new StringBuilder ();
@@ -205,6 +217,8 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
bool has_usb_redir = false;
bool has_smartcard = false;
+ bool bridge_net = false;
+ bool virtio_net = false;
// We look at the INACTIVE config here, because we want to show the usb
// widgetry if usb has been added already but we have not rebooted
try {
@@ -216,6 +230,12 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
if (device is GVirConfig.DomainSmartcard) {
has_smartcard = true;
}
+ if (device is GVirConfig.DomainInterfaceBridge) {
+ bridge_net = true;
+ }
+ if (device is GVirConfig.DomainInterface) {
+ virtio_net = (device as GVirConfig.DomainInterface).get_model () == "virtio";
+ }
}
} catch (GLib.Error error) {
warning ("Failed to fetch configuration for domain '%s': %s", machine.domain.get_name (),
error.message);
@@ -258,6 +278,25 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
});
}
+ var combo = new Gtk.ComboBoxText ();
+ combo.halign = Gtk.Align.START;
+ combo.insert_text (0, _("Fastest"));
+ combo.insert_text (1, _("Most secure"));
+ combo.active = bridge_net? 0 : 1;
+ add_property (ref list, _("Network"), combo);
+ if (!bridge_net && !is_libvirt_bridge_net_available ())
+ combo.sensitive = false;
+ else {
+ combo.changed.connect (() => {
+ try {
+ try_change_network_interface (combo.get_active() == 0, virtio_net);
+ machine.update_domain_config ();
+ } catch (GLib.Error error) {
+ warning ("Failed to change network interface");
+ }
+ });
+ }
+
break;
}
diff --git a/src/vm-configurator.vala b/src/vm-configurator.vala
index 5b5fcba..5f8c8d4 100644
--- a/src/vm-configurator.vala
+++ b/src/vm-configurator.vala
@@ -431,9 +431,17 @@ private class Boxes.VMConfigurator {
// Remove all existing usb controllers. This is used when upgrading from the old usb1 controllers to usb2
public static void remove_usb_controllers (Domain domain) throws Boxes.Error {
+ remove_device_by_type (domain, typeof (DomainControllerUsb));
+ }
+
+ public static void remove_network_interface (Domain domain) throws Boxes.Error {
+ remove_device_by_type (domain, typeof (DomainInterface));
+ }
+
+ public static void remove_device_by_type (Domain domain, Type type) throws Boxes.Error {
GLib.List<GVirConfig.DomainDevice> devices = null;
foreach (var device in domain.get_devices ()) {
- if (!(device is DomainControllerUsb)) {
+ if (!(device.get_type ().is_a (type))) {
devices.prepend (device);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]