[gnome-boxes/dont-clone-mac-address] libvirt-machine: Recreate network interface while cloning



commit 7d25ae249702f80bf4e6b224c6a3ebc334705347
Author: Felipe Borges <felipeborges gnome org>
Date:   Wed Oct 17 13:32:31 2018 +0200

    libvirt-machine: Recreate network interface while cloning
    
    While cloning a libvirt machine, Boxes copies the literal VM XML
    config and duplicates it into a newly created machine. This way
    the machines are expected to be identical.
    
    Users won't ever want to have two Boxes with the same mac address.
    
    A common use-case for Boxes is for someone to create and configure
    a single box and clone it into multiple instances.
    
    Fixes #262

 src/libvirt-machine.vala | 7 +++++++
 1 file changed, 7 insertions(+)
---
diff --git a/src/libvirt-machine.vala b/src/libvirt-machine.vala
index 63a94797..cd8d87f9 100644
--- a/src/libvirt-machine.vala
+++ b/src/libvirt-machine.vala
@@ -696,6 +696,13 @@ public override async void clone () {
             config.set_uuid (null);
 
             var media = new LibvirtClonedMedia (storage_volume.get_path (), config);
+
+            // Recreate network interface so clones won't have the same mac address
+            var iface= VMConfigurator.create_network_interface (config,
+                                                                is_libvirt_bridge_net_available (),
+                                                                media.supports_virtio_net);
+            config.add_device (iface);
+
             var vm_cloner = media.get_vm_creator ();
             var clone_machine = yield vm_cloner.create_vm (null);
             vm_cloner.launch_vm (clone_machine, this.config.access_last_time);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]