Beispiel #1
0
 def _route(self):
     """Route command"""
     try:
         args = get_input("Arguments for \"route\"",
                          self._validate_tool_params)
         self._run_tool("/sbin/route", args)
     except KeyboardInterrupt:
         pass
Beispiel #2
0
 def _ifconfig(self):
     """Ifconfig command"""
     try:
         args = get_input("Arguments for \"ifconfig\"",
                          self._validate_tool_params)
         self._run_tool("/sbin/ifconfig", args)
     except KeyboardInterrupt:
         pass
Beispiel #3
0
    def _get_input(self):
        """Get email and password"""
        print _KEYBOARD_HELP
        print "\nUser Details"

        try:
            email = get_input("E-mail", self._validate_email)
            password = get_input("Password", self._validate_password)

        except KeyboardInterrupt:
            return None, None

        except Exception as e:
            print "FAILED (%s)\x07" % str(e)
            raise

        return email, password
Beispiel #4
0
 def main(self):
     """Main task function"""
     try:
         domain = get_input("Domain",
                            self._validate_domain,
                            default=self.get_domain())
         self._set_domain(domain)
     except KeyboardInterrupt:
         pass
Beispiel #5
0
    def _traceroute(self):
        """Traceroute command"""
        try:
            args = get_input("Arguments for \"traceroute\"",
                             self._validate_tool_params)

            if args:
                self._run_tool("/usr/sbin/traceroute", args)

        except KeyboardInterrupt:
            pass
Beispiel #6
0
    def _ping(self):
        """Ping command"""
        try:
            args = get_input("Arguments for \"ping\"",
                             self._validate_tool_params)

            if args:
                self._run_tool("/bin/ping", "-c3 %s" % args)

        except KeyboardInterrupt:
            pass
Beispiel #7
0
    def _iptables(self):
        """IP tables command"""
        try:
            args = get_input("Arguments for \"iptables\"",
                             self._validate_tool_params)

            if args:
                self._run_tool("/sbin/iptables", args)

        except KeyboardInterrupt:
            pass
Beispiel #8
0
def first_time():
    """First time setup"""
    print FIRST_TIME_GREETING_TEXT
    print AUTOMATIC_TEXT
    print

    try:
        automatic = get_input("Use automatic configuration? Y or N",
                              yes_no_validator,
                              default="Y")
    except KeyboardInterrupt:
        automatic = None

    automatic = automatic.upper() == "Y"
    print

    if automatic:
        print "Automatic Configuration..."

    quit_configuration = True
    tasks = []

    for task in FIRST_TIME_TASKS:
        task = load_task(task)

        if SYSTEM_TYPE in task.SKIP_FOR_SYSTEM_TYPES:
            continue

        tasks.append(task)

    while True:
        number = 1

        for task in tasks:
            if task.NAME:
                if automatic:
                    print "%s: " % task.NAME,
                else:
                    header = "%s (step %i of %i)" % (task.NAME, number,
                                                     len(tasks))
                    print header
                    print "-" * len(header)
                    print task.DESCRIPTION

            task.run(mandatory=True, automatic=automatic)

            if automatic:
                if task.changed:
                    print "OK"
                else:
                    print "FAILED"
                    quit_configuration = False
                    automatic = False

                    print
                    print "Automatic configuration has failed."
                    print "Please use manual configuration to set up the system."
                    print

                    break

            number += 1

        if quit_configuration:
            break
Beispiel #9
0
    def _manual(self):
        """Manual network configuration"""
        print "[Manual Network Configuration]"

        ip, netmask, gateway, nameserver = self.read_defaults()

        try:
            ip = get_input("IP Address", self._validate_ip, default=ip)
            netmask = get_input("Network Mask",
                                self._validate_ip,
                                default=netmask)
            gateway = get_input("Gateway", self._validate_ip, default=gateway)
            nameserver = get_input("Name Server",
                                   self._validate_ns,
                                   default=nameserver)

        except KeyboardInterrupt:
            return

        if not nameserver:
            nameserver = gateway

        if not ip or not netmask or not gateway or not nameserver:
            return

        print "\nSaving..."

        try:
            if not path.exists("%s.%s" %
                               (_NETWORK_CONFIG_PATH, _BACKUP_EXTENSION)):
                copy2(_NETWORK_CONFIG_PATH,
                      "%s.%s" % (_NETWORK_CONFIG_PATH, _BACKUP_EXTENSION))

            if not path.exists("%s.%s" %
                               (_DNS_CONFIG_PATH, _BACKUP_EXTENSION)):
                copy2(_DNS_CONFIG_PATH,
                      "%s.%s" % (_DNS_CONFIG_PATH, _BACKUP_EXTENSION))

            # writing files
            cfg = open(_NETWORK_CONFIG_PATH, "w")
            cfg.write(
                _STATIC_CONFIG_TEMPLATE % {
                    "address": ip,
                    "netmask": netmask,
                    "gateway": gateway,
                    "nameserver": nameserver
                })
            cfg.close()

            cfg = open(_DNS_CONFIG_PATH, "w")
            cfg.write(_DNS_CONFIG_TEMPLATE % {"nameserver": nameserver})
            cfg.close()

        except Exception as e:
            print "FAILED (%s)\x07" % str(e)
            return

        print "Applying..."

        try:
            commands = ("ifconfig eth0 %s netmask %s" % (ip, netmask),
                        "ifconfig eth0 down", "ifconfig eth0 up",
                        "ip route flush root 0/0", "ifconfig eth0 down",
                        "ifconfig eth0 up",
                        "route add default gw %s" % gateway)

            for command in commands:
                ret_code = call([command], shell=True)

                if ret_code != 0:
                    raise SystemCommandError()

                sleep(2)

        except Exception as e:
            print "FAILED (%s)\x07" % str(e)
            return

        self._update_openvz()

        self._network_test()
        self.changed = True