Esempio n. 1
0
    def checkField(self):
        sanitytest = _ipTests[self.fieldName].sanityFunc
        try:
            result = sanitytest(self.userinput)
            if self.userinput:
                if self.fieldName != 'hostname':
                    # get normalized octets
                    self.fields[self.fieldName] = \
                        net_utils.formatIPString(self.userinput)
                else:
                    # hostname: use userinput directly
                    self.fields[self.fieldName] = self.userinput
            else:
                self.fields[self.fieldName] = None

            if self.fieldName == 'ns2':
                if not self.fields.get('ns2'):
                    pass        # empty ns1 okay
                elif not self.fields.get('ns1'):
                    # non-empty ns2 requires non-empty ns1
                    raise ValueError("Primary DNS not yet set.")
                elif self.fields['ns1'] == self.fields['ns2']:
                    raise ValueError("Primary and secondary DNS cannot be identical.")
        except ValueError, msg:
            body = '\n'.join([str(msg), errEpilog])
            self.errorPushPop(self.clientName, body)
            return
 def getIPString(self, name, formatted=1):
     '''Return the contents of an IP_Entry, as is if formatted==0, more
        nicely formatted if formatted==1.
        Arg name needs to be a key in _ipEntries[self.clientName].
     '''
     txt = _ipEntries[self.clientName][name].get_text()
     if not formatted:
         return txt
     else:
         try:
             return net_utils.formatIPString(txt)
         except ValueError:
             return ""
Esempio n. 3
0
 def getIPString(self, name, formatted=1):
     '''Return the contents of an IP_Entry, as is if formatted==0, more
        nicely formatted if formatted==1.
        Arg name needs to be a key in _ipEntries[self.clientName].
     '''
     txt = _ipEntries[self.clientName][name].get_text()
     if not formatted:
         return txt
     else:
         try:
             return net_utils.formatIPString(txt)
         except ValueError:
             return ""
    def testIPSettings(self, tests=[]):
        '''Test numerous IP settings to make certain they are valid.'''
        for testName in tests:
            assert testName in self.relevantIPFields

        ipSettings = {}

        # construct an empty set of network settings
        for setting in self.relevantIPFields:
            ipSettings[setting] = ""

        for testName in tests:
            if testName not in _ipTests:
                raise ValueError("Improper test %s" % (testName))

            (entry, title, error, testFunc) = _ipTests[testName]

            if testName == "hostname":
                ipSetting = self.getHostnameEntry().get_text()
                if not ipSetting:
                    common_windows.MessageWindow(self.thisWindow, title,
                                                 "Enter a hostname.")
                    raise exception.StayOnScreen
            else:
                ipSetting = self.getIPString(entry, formatted=0)

            try:
                testFunc(ipSetting)
            except (ValueError, TypeError), msg:
                if str(msg):
                    # Use the message from the exception, it should be more
                    # descriptive than the generic error from _ipTests.
                    error = str(msg)
                common_windows.MessageWindow(self.thisWindow, title, error)
                raise exception.StayOnScreen
            else:
                if ipSetting and testName != "hostname":
                    # filter out any leading zeros
                    ipSetting = net_utils.formatIPString(ipSetting)
                    self.setIPString(entry, ipSetting)
                ipSettings[testName] = ipSetting
Esempio n. 5
0
    def testIPSettings(self, tests=[]):
        '''Test numerous IP settings to make certain they are valid.'''
        for testName in tests:
            assert testName in self.relevantIPFields

        ipSettings = {}

        # construct an empty set of network settings
        for setting in self.relevantIPFields:
            ipSettings[setting] = ""

        for testName in tests:
            if testName not in _ipTests:
                raise ValueError("Improper test %s" % (testName))

            (entry, title, error, testFunc) = _ipTests[testName]

            if testName == "hostname":
                ipSetting = self.getHostnameEntry().get_text()
                if not ipSetting:
                    common_windows.MessageWindow(self.thisWindow, title,
                                                 "Enter a hostname.")
                    raise exception.StayOnScreen
            else:
                ipSetting = self.getIPString(entry, formatted=0)

            try:
                testFunc(ipSetting)
            except (ValueError, TypeError), msg:
                if str(msg):
                    # Use the message from the exception, it should be more
                    # descriptive than the generic error from _ipTests.
                    error = str(msg)
                common_windows.MessageWindow(self.thisWindow, title, error)
                raise exception.StayOnScreen
            else:
                if ipSetting and testName != "hostname":
                    # filter out any leading zeros
                    ipSetting = net_utils.formatIPString(ipSetting)
                    self.setIPString(entry, ipSetting)
                ipSettings[testName] = ipSetting