Add OpenvSwitch functionality to LUNodeAdd
authorSebastian Gebhard <sege@fs.ei.tum.de>
Tue, 20 Aug 2013 10:44:04 +0000 (10:44 +0000)
committerKlaus Aehlig <aehlig@google.com>
Wed, 21 Aug 2013 15:26:26 +0000 (17:26 +0200)
This patch adds functionality to LUNodeAdd to
  - check the arguments given. It will warn if no physical link is given
    and fail if OpenvSwitch is not enabled, but parameters are given
  - call the RPC to configure OpenvSwitch on the node

Signed-off-by: Sebastian Gebhard <sege@fs.ei.tum.de>
Signed-off-by: Klaus Aehlig <aehlig@google.com>
Reviewed-by: Klaus Aehlig <aehlig@google.com>

lib/cmdlib/node.py

index ca4a5a6..c62e691 100644 (file)
@@ -112,6 +112,20 @@ class LUNodeAdd(LogicalUnit):
       raise errors.OpPrereqError("Cannot pass a node group when a node is"
                                  " being readded", errors.ECODE_INVAL)
 
+    # OpenvSwitch: Warn user if link is missing
+    if (self.op.ndparams[constants.ND_OVS] and not
+        self.op.ndparams[constants.ND_OVS_LINK]):
+      self.LogInfo("No physical interface for OpenvSwitch was given."
+                   " OpenvSwitch will not have an outside connection. This"
+                   " might not be what you want.")
+    # OpenvSwitch: Fail if parameters are given, but OVS is not enabled.
+    if (not self.op.ndparams[constants.ND_OVS] and
+        (self.op.ndparams[constants.ND_OVS_NAME] or
+         self.op.ndparams[constants.ND_OVS_LINK])):
+      raise errors.OpPrereqError("OpenvSwitch name or link were given, but"
+                                 " OpenvSwitch is not enabled. Please enable"
+                                 " OpenvSwitch with --ovs", errors.ECODE_INVAL)
+
   def BuildHooksEnv(self):
     """Build hooks env.
 
@@ -375,6 +389,13 @@ class LUNodeAdd(LogicalUnit):
                       (verifier, nl_payload[failed]))
         raise errors.OpExecError("ssh/hostname verification failed")
 
+    # OpenvSwitch initialization on the node
+    if self.new_node.ndparams[constants.ND_OVS]:
+      result = self.rpc.call_node_configure_ovs(
+                 self.new_node.name,
+                 self.new_node.ndparams[constants.ND_OVS_NAME],
+                 self.new_node.ndparams[constants.ND_OVS_LINK])
+
     if self.op.readd:
       self.context.ReaddNode(self.new_node)
       RedistributeAncillaryFiles(self)