xenserver: Validate controller IP address in xsconsole
authorJustin Pettit <jpettit@nicira.com>
Thu, 25 Jun 2009 04:52:34 +0000 (21:52 -0700)
committerJustin Pettit <jpettit@nicira.com>
Thu, 25 Jun 2009 04:52:34 +0000 (21:52 -0700)
When a switch is using in-band control, the controller must be specified
in dotted quad format, since DNS names cannot be resolved until a
connection to the controller has been established.  This commit
validates the user input in the xsconsole plugin.

xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py

index 95020ad..4523139 100644 (file)
@@ -12,6 +12,7 @@ log = logging.getLogger("vswitch-cfg-update")
 logging.basicConfig(filename="/var/log/vswitch-xsplugin.log", level=logging.DEBUG)
 
 import os
+import socket
 import subprocess
 
 cfg_mod="/root/vswitch/bin/ovs-cfg-mod"
@@ -162,6 +163,14 @@ class VSwitchControllerDialogue(Dialogue):
             inputValues = pane.GetFieldValues()
             self.controller = inputValues['address']
             Layout.Inst().PopDialogue()
+
+            # Make sure the controller is specified as a valid dotted quad
+            try:
+                socket.inet_aton(self.controller)
+            except socket.error:
+                Layout.Inst().PushDialogue(InfoDialogue(Lang("Please enter in dotted quad format")))
+                return True
+
             Layout.Inst().TransientBanner(Lang("Setting controller..."))
             try:
                 self.SetController(self.controller)