Ejemplo n.º 1
0
 def clean(self):
     cd = super(AuthADSettingsForm, self).clean()
     if 'password_server_ip' in cd:
         valid, err = networking.validate_ip(cd['password_server_ip'])
         if err:
             raise Exception(err)
         if not valid:
             del cd["password_server_ip"]
             self._errors["password_server_ip"] = self.error_class(
                 ["Please specify a valid IP address"])
     return cd
 def clean(self):
     cd = super(DNSNameServersForm, self).clean()
     nameservers = cd.get("nameservers")
     if nameservers is not None:
         if nameservers and ',' in nameservers:
             slist = nameservers.split(',')
         else:
             slist = nameservers.split(' ')
         for server in slist:
             valid, err = networking.validate_ip(server)
             if err:
                 self._errors["nameservers"] = self.error_class(
                     ["Error validating DNS server IP address %s : %s" % (server, err)])
                 break
             elif not valid:
                 self._errors["nameservers"] = self.error_class(
                     ["Invalid DNS server IP address : %s" % server])
                 break
     return cd
Ejemplo n.º 3
0
 def clean(self):
     cd = super(DNSNameServersForm, self).clean()
     nameservers = cd.get("nameservers")
     if nameservers is not None:
         if nameservers and ',' in nameservers:
             slist = nameservers.split(',')
         else:
             slist = nameservers.split(' ')
         for server in slist:
             valid, err = networking.validate_ip(server)
             if err:
                 self._errors["nameservers"] = self.error_class([
                     "Error validating DNS server IP address %s : %s" %
                     (server, err)
                 ])
                 break
             elif not valid:
                 self._errors["nameservers"] = self.error_class(
                     ["Invalid DNS server IP address : %s" % server])
                 break
     return cd
Ejemplo n.º 4
0
def configure_interface():

    try:
        os.system('clear')
        interfaces, err = networking.get_interfaces()
        if err:
            raise Exception(
                'Error retrieving interface information : %s' % err)
        if not interfaces:
            raise Exception('No interfaces detected')
        print
        print
        print 'IntegralSTOR interface configuration'
        print '--------------------------------------------'
        print
        print
        print 'Current network interfaces : '
        print
        for if_name, iface in interfaces.items():
            if if_name.startswith('lo'):
                continue
            print '- %s' % if_name
        print

        valid_input = False
        while not valid_input:
            ifname = raw_input(
                'Enter the name of the interface that you wish to configure : ')
            if ifname not in interfaces or ifname.startswith('lo'):
                print 'Invalid interface name'
            else:
                valid_input = True
        print
        ip_info, err = networking.get_ip_info(ifname)
        '''
    if err:
      raise Exception('Error retrieving interface information : %s'%err)
    '''
        if ip_info:
            ip = ip_info["ipaddr"]
            netmask = ip_info["netmask"]
            if "default_gateway" in ip_info:
                gateway = ip_info["default_gateway"]
            else:
                gateway = None
        else:
            ip = None
            netmask = None
            gateway = None

        old_boot_proto, err = networking.get_interface_bootproto(ifname)
        if err:
            # raise Exception(
                # 'Error retrieving interface information : %s' % err)
            old_boot_proto = ''

        config_changed = False

        str_to_print = "Configure for DHCP or static addressing (dhcp/static)? : "
        valid_input = False
        while not valid_input:
            input = raw_input(str_to_print)
            if input:
                if input.lower() in ['static', 'dhcp']:
                    valid_input = True
                    boot_proto = input.lower()
                    if boot_proto != old_boot_proto:
                        config_changed = True
            if not valid_input:
                print "Invalid value. Please try again."
        print

        if boot_proto == 'static':
            if ip:
                str_to_print = "Enter IP address (currently %s, press enter to retain current value) : " % ip
            else:
                str_to_print = "Enter IP address (currently not set) : "
            valid_input = False
            while not valid_input:
                input = raw_input(str_to_print)
                if input:
                    ok, err = networking.validate_ip(input)
                    if err:
                        raise Exception('Error validating IP : %s' % err)
                    if ok:
                        valid_input = True
                        ip = input
                        config_changed = True
                elif ip:
                    valid_input = True
                if not valid_input:
                    print "Invalid value. Please try again."
            print

            if netmask:
                str_to_print = "Enter netmask (currently %s, press enter to retain current value) : " % netmask
            else:
                str_to_print = "Enter netmask (currently not set) : "
            valid_input = False
            while not valid_input:
                input = raw_input(str_to_print)
                if input:
                    ok, err = networking.validate_netmask(input)
                    if err:
                        raise Exception('Error validating netmask : %s' % err)
                    if ok:
                        valid_input = True
                        netmask = input
                        config_changed = True
                elif netmask:
                    valid_input = True
            if not valid_input:
                print "Invalid value. Please try again."
            print

            if gateway:
                str_to_print = "Enter gateway (currently %s, press enter to retain current value) : " % gateway
            else:
                str_to_print = "Enter gateway (currently not set) : "
            valid_input = False
            while not valid_input:
                input = raw_input(str_to_print)
                if input:
                    ok, err = networking.validate_ip(input)
                    if err:
                        raise Exception('Error validating gateway : %s' % err)
                    if ok:
                        valid_input = True
                        gateway = input
                        config_changed = True
                elif gateway:
                    valid_input = True
                if not valid_input:
                    print "Invalid value. Please try again."
            print
        if config_changed:
            d = {}
            d['addr_type'] = boot_proto
            if boot_proto == 'static':
                d['ip'] = ip
                d['netmask'] = netmask
                d['default_gateway'] = gateway
            ret, err = networking.update_interface_ip(ifname, d)
            if not ret:
                if err:
                    raise Exception(
                        'Error changing interface address : %s' % err)
                else:
                    raise Exception('Error changing interface address')

            restart = False
            print
            print
            valid_input = False
            while not valid_input:
                str_to_print = 'Restart network services now (y/n) :'
                print
                input = raw_input(str_to_print)
                if input:
                    if input.lower() in ['y', 'n']:
                        valid_input = True
                        if input.lower() == 'y':
                            restart = True
                if not valid_input:
                    print "Invalid value. Please try again."
            print

            if restart:
                ret, err = networking.restart_networking()
                if not ret:
                    if err:
                        raise Exception(err)
                    else:
                        raise Exception("Couldn't restart.")

                use_salt, err = config.use_salt()
                if err:
                    raise Exception(err)
                if use_salt:
                    (r, rc), err = command.execute_with_rc(
                        'service salt-minion restart')
                    if err:
                        raise Exception(err)
                    if rc == 0:
                        print "Salt minion service restarted succesfully."
                    else:
                        print "Error restarting salt minion services."
                        raw_input('Press enter to return to the main menu')
                        return -1
        else:
            print
            print
            raw_input(
                'No changes have been made to the configurations. Press enter to return to the main menu.')
            return 0

    except Exception, e:
        print "Error configuring network settings : %s" % e
        return -1
Ejemplo n.º 5
0
def main():
    try:
        nodes = {}
        node1_hostname, err = networking.get_hostname()
        if err:
            raise Exception("Error getting hostname: %s" % err)
        print "HA Configuration requires hostname and IP address of the participating nodes"
        if not node1_hostname:
            print "Hostname not set, Please set a hostname for this machine before configuring HA"
            while True:
                node1_hostname = raw_input("Hostname: ")
                valid, err = networking.validate_hostname(node1_hostname)
                if err:
                    raise Exception("Error validating hostname: %s" % err)
                if err and not valid:
                    print "Invalid Hostname!"
                    continue
                if re.findall(r"\w+\.", node1_hostname):
                    tmp = node1_hostname.split('.')
                    ok, err = networking.update_hostname(
                        tmp[0], "".join(tmp[1:]))
                else:
                    ok, err = networking.update_hostname(node1_hostname)
                if err:
                    raise Exception("Error updating hostname: %s" % err)
                if not ok:
                    print "Unable to update hostname!"
                else:
                    break
        else:
            print "Current Hostname for this machine is %s" % node1_hostname
            ch = raw_input("Do you want to change it? (y/n): ")
            if ch.lower() == "y" or ch.lower() == "yes":
                while True:
                    node1_hostname = raw_input("Hostname: ")
                    valid, err = networking.validate_hostname(node1_hostname)
                    if err:
                        raise Exception("Error validating hostname: %s" % err)
                    if not valid:
                        print "Invalid hostname!"
                        continue
                    if re.findall(r"\w+\.", node1_hostname):
                        tmp = node1_hostname.split('.')
                        ok, err = networking.update_hostname(
                            tmp[0], "".join(tmp[1:]))
                    else:
                        ok, err = networking.update_hostname(node1_hostname)
                    if err:
                        raise Exception("Error updating hostname: %s" % err)
                    if not ok:
                        print "Unable to update hostname!"
                    else:
                        break
        print "HA Configuration requires the hostname to be resolvable by an IP address"
        while True:
            node1_ip = raw_input("Please enter IP for %s: " % node1_hostname)
            valid, err = networking.validate_ip(node1_ip)
            if err:
                raise Exception("Error validating IP address: %s" % err)
            if not valid:
                print "Invalid IP Adress!"
            else:
                connect, err = networking.can_ping(node1_ip)
                if err:
                    raise Exception("Error trying to ping host: %s " % err)
                if not connect:
                    print "%s is not reachable, Please check if you've entered the correct IP address" % node1_ip
                    continue
                break
        while True:
            node2_hostname = raw_input("Please enter second node's hostname: ")
            valid, err = networking.validate_hostname(node2_hostname)
            if err and not valid:
                print "Invalid hostname!"
            else:
                break
        while True:
            node2_ip = raw_input("Please enter IP for %s: " % node2_hostname)
            valid, err = networking.validate_ip(node2_ip)
            if err:
                raise Exception("Error validating IP address: %s" % err)
            if not valid:
                print "Invalid IP Adress!"
            else:
                connect, err = networking.can_ping(node2_ip)
                if err:
                    raise Exception("Error trying to ping host: %s" % err)
                if not connect:
                    print "%s is not reachable, Please check if you've entered the correct IP address" % node2_ip
                    continue
                break
        nodes["node1"] = {'hostname': node1_hostname, 'ip': node1_ip}
        nodes["node2"] = {'hostname': node2_hostname, 'ip': node2_ip}
        configure_cluster(nodes)
    except Exception, e:
        print "Error configuring HA: %s" % e