(ipfix) Allow NICs with mode=routed and ip=none
[ganeti-local] / lib / cmdlib / instance.py
index decc04e..115eae5 100644 (file)
@@ -205,11 +205,6 @@ def _ComputeNics(op, cluster, default_ip, cfg, ec_id):
 
       nic_ip = ip
 
-    # TODO: check the ip address for uniqueness
-    if nic_mode == constants.NIC_MODE_ROUTED and not nic_ip:
-      raise errors.OpPrereqError("Routed nic mode requires an ip address",
-                                 errors.ECODE_INVAL)
-
     # MAC address verification
     mac = nic.get(constants.INIC_MAC, constants.VALUE_AUTO)
     if mac not in (constants.VALUE_AUTO, constants.VALUE_GENERATE):
@@ -650,7 +645,7 @@ class LUInstanceCreate(LogicalUnit):
       nics=NICListToTuple(self, self.nics),
       disk_template=self.op.disk_template,
       disks=[(d[constants.IDISK_NAME], d.get("uuid", ""),
-              d[constants.IDISK_SIZE], d[constants.IDISK_MODE])
+              d[constants.IDISK_SIZE], d[constants.IDISK_MODE], {})
              for d in self.disks],
       bep=self.be_full,
       hvp=self.hv_full,
@@ -2539,9 +2534,6 @@ class LUInstanceSetParams(LogicalUnit):
 
     elif new_mode == constants.NIC_MODE_ROUTED:
       ip = params.get(constants.INIC_IP, old_ip)
-      if ip is None:
-        raise errors.OpPrereqError("Cannot set the NIC IP address to None"
-                                   " on a routed NIC", errors.ECODE_INVAL)
 
     elif new_mode == constants.NIC_MODE_OVS:
       # TODO: check OVS link
@@ -2691,6 +2683,8 @@ class LUInstanceSetParams(LogicalUnit):
                                            self.op.disk_template))
         raise errors.OpPrereqError(errmsg, errors.ECODE_STATE)
 
+  # too many local variables
+  # pylint: disable=R0914
   def CheckPrereq(self):
     """Check prerequisites.
 
@@ -2772,10 +2766,19 @@ class LUInstanceSetParams(LogicalUnit):
                                       constants.DT_EXT),
                                      errors.ECODE_INVAL)
 
-    if self.op.hotplug:
+    if self.op.hotplug or self.op.hotplug_if_possible:
       result = self.rpc.call_hotplug_supported(self.instance.primary_node,
                                                self.instance)
-      result.Raise("Hotplug is not supported.")
+      if result.fail_msg:
+        if self.op.hotplug:
+          result.Raise("Hotplug is not possible: %s" % result.fail_msg,
+                       prereq=True)
+        else:
+          self.LogWarning(result.fail_msg)
+          self.op.hotplug = False
+          self.LogInfo("Modification will take place without hotplugging.")
+      else:
+        self.op.hotplug = True
 
     # OS change
     if self.op.os_name and not self.op.force:
@@ -3285,6 +3288,8 @@ class LUInstanceSetParams(LogicalUnit):
 
     (anno_disk,) = AnnotateDiskParams(self.instance, [root], self.cfg)
     for node, disk in anno_disk.ComputeNodeTree(self.instance.primary_node):
+      if self.op.keep_disks and disk.dev_type in constants.DT_EXT:
+        continue
       self.cfg.SetDiskID(disk, node)
       msg = self.rpc.call_blockdev_remove(node, disk).fail_msg
       if msg: