..in case attached to a network.

This allows us to define an IPv6 only network (currently with a
dummy IPv4 subnet) with connectivity mode 'routed' and let a NIC
inside this network have only an IPv6 address, e.g. an
auto-generated one derived form its MAC and the network's IPv6
prefix (SLAAC).

Signed-off-by: Dimitris Aragiorgis <[email protected]>
---
 lib/cmdlib/instance.py              |   10 ++++++----
 test/py/cmdlib/instance_unittest.py |    8 ++++++--
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lib/cmdlib/instance.py b/lib/cmdlib/instance.py
index b86089c..c8b89e2 100644
--- a/lib/cmdlib/instance.py
+++ b/lib/cmdlib/instance.py
@@ -212,8 +212,9 @@ 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",
+    if nic_mode == constants.NIC_MODE_ROUTED and not nic_ip and not net:
+      raise errors.OpPrereqError("Routed nic mode requires an ip address"
+                                 " if not attached to a network",
                                  errors.ECODE_INVAL)
 
     # MAC address verification
@@ -2896,9 +2897,10 @@ class LUInstanceSetParams(LogicalUnit):
 
     elif new_mode == constants.NIC_MODE_ROUTED:
       ip = params.get(constants.INIC_IP, old_ip)
-      if ip is None:
+      if ip is None and not new_net_uuid:
         raise errors.OpPrereqError("Cannot set the NIC IP address to None"
-                                   " on a routed NIC", errors.ECODE_INVAL)
+                                   " on a routed NIC if not attached to a"
+                                   " network", errors.ECODE_INVAL)
 
     elif new_mode == constants.NIC_MODE_OVS:
       # TODO: check OVS link
diff --git a/test/py/cmdlib/instance_unittest.py 
b/test/py/cmdlib/instance_unittest.py
index e9a5939..84141e9 100644
--- a/test/py/cmdlib/instance_unittest.py
+++ b/test/py/cmdlib/instance_unittest.py
@@ -233,10 +233,12 @@ class TestLUInstanceCreate(CmdlibTestCase):
   def testRoutedNoIp(self):
     op = self.CopyOpCode(self.diskless_op,
                          nics=[{
+                           constants.INIC_NETWORK: constants.VALUE_NONE,
                            constants.INIC_MODE: constants.NIC_MODE_ROUTED
                          }])
     self.ExecOpCodeExpectOpPrereqError(
-      op, "Routed nic mode requires an ip address")
+      op, "Routed nic mode requires an ip address"
+      " if not attached to a network")
 
   def testValicMac(self):
     op = self.CopyOpCode(self.diskless_op,
@@ -2062,10 +2064,12 @@ class TestLUInstanceSetParams(CmdlibTestCase):
     op = self.CopyOpCode(self.op,
                          nics=[(constants.DDM_MODIFY, 0,
                                 {
+                                  constants.INIC_NETWORK: constants.VALUE_NONE,
                                   constants.INIC_MODE: 
constants.NIC_MODE_ROUTED
                                 })])
     self.ExecOpCodeExpectOpPrereqError(
-      op, "Cannot set the NIC IP address to None on a routed NIC")
+      op, "Cannot set the NIC IP address to None on a routed NIC"
+      " if not attached to a network")
 
   def testModifyNicSetMac(self):
     op = self.CopyOpCode(self.op,
-- 
1.7.10.4

Reply via email to