LUCreateInstance: reuse mac address on import
authorGuido Trotter <ultrotter@google.com>
Mon, 20 Oct 2008 13:44:19 +0000 (13:44 +0000)
committerGuido Trotter <ultrotter@google.com>
Mon, 20 Oct 2008 13:44:19 +0000 (13:44 +0000)
When importing an instance with the same name as the exported one if the
mac address is "auto" we try to reuse the previous mac address. One can
still force generation of a new one with mac="generate".

Forward-port-of: r1887, Reviewed-by: iustinp

Reviewed-by: imsnah

lib/cmdlib.py

index c7370c7..5d59145 100644 (file)
@@ -3491,6 +3491,14 @@ class LUCreateInstance(LogicalUnit):
                                                          'disk0_dump'))
       self.src_image = diskimage
 
+      if self.op.mac == constants.VALUE_AUTO:
+        old_name = export_info.get(constants.INISECT_INS, 'name')
+        if self.op.instance_name == old_name:
+          # FIXME: adjust every nic, when we'll be able to create instances
+          # with more than one
+          if int(export_info.get(constants.INISECT_INS, 'nic_count')) >= 1:
+            self.op.mac = export_info.get(constants.INISECT_INS, 'nic_0_mac')
+
     # ip ping checks (we use the same ip that was resolved in ExpandNames)
 
     if self.op.start and not self.op.ip_check: