예제 #1
0
    def handle_sigusr1(self, signum, stack):
        log.info("Received signal: %s" % signum)
        try:
            savetimeout = 60
            success, modulename = timeout.run_with_timeout(
                self.global_save, timeout=savetimeout,
                default=(False, "timeout"))
            if success:
                log.info("Save successful!")
            else:
                log.error("Save failed on module %s" % modulename)

        except (KeyboardInterrupt, timeout.TimeoutError):
            log.exception("Save on signal timed out. Save not complete.")
        except Exception:
            log.exception("Save failed for unknown reason:")
        self.exit_program(None)
예제 #2
0
파일: fuelmenu.py 프로젝트: toby82/fuel-web
    def handle_sigusr1(self, signum, stack):
        log.info("Received signal: %s" % signum)
        try:
            savetimeout = 60
            success, modulename = timeout.run_with_timeout(
                self.global_save, timeout=savetimeout,
                default=(False, "timeout"))
            if success:
                log.info("Save successful!")
            else:
                log.error("Save failed on module %s" % modulename)

        except (KeyboardInterrupt, timeout.TimeoutError):
            log.exception("Save on signal timed out. Save not complete.")
        except Exception:
            log.exception("Save failed for unknown reason:")
        self.exit_program(None)
예제 #3
0
def save_only(iface, settingsfile='/etc/fuel/astute.yaml'):
    import common.network as network
    from common import pwgen
    import netifaces

    #Calculate and set Static/DHCP pool fields
    #Max IPs = net size - 2 (master node + bcast)
    try:
        ip = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr']
        netmask = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['netmask']
        mac = netifaces.ifaddresses(iface)[netifaces.AF_LINK][0]['addr']
    except Exception:
        print("Interface %s is missing either IP address or netmask"
              % (iface))
        sys.exit(1)
    net_ip_list = network.getNetwork(ip, netmask)
    try:
        dhcp_pool = net_ip_list[1:]
        dynamic_start = str(dhcp_pool[0])
        dynamic_end = str(dhcp_pool[-1])
    except Exception:
        print("Unable to define DHCP pools")
        sys.exit(1)
    try:
        hostname, sep, domain = os.uname()[1].partition('.')
    except Exception:
        print("Unable to calculate hostname and domain")
        sys.exit(1)
    try:
        dhcptimeout = 5
        default = []
        with timeout.run_with_timeout(dhcp_checker.utils.IfaceState, [iface],
                                      timeout=dhcptimeout) as iface:
            dhcp_server_data = timeout.run_with_timeout(
                dhcp_checker.api.check_dhcp_on_eth,
                [iface, dhcptimeout], timeout=dhcptimeout,
                default=default)
    except (KeyboardInterrupt, timeout.TimeoutError):
        log.debug("DHCP scan timed out")
        log.warning(traceback.format_exc())
        dhcp_server_data = default

    num_dhcp = len(dhcp_server_data)
    if num_dhcp == 0:
        log.debug("No DHCP servers found")
    else:
        #Problem exists, but permit user to continue
        log.error("%s foreign DHCP server(s) found: %s" %
                  (num_dhcp, dhcp_server_data))
        print("ERROR: %s foreign DHCP server(s) found: %s" %
              (num_dhcp, dhcp_server_data))
    if network.duplicateIPExists(ip, iface):
        log.error("Duplicate host found with IP {0}".format(ip))
        print("ERROR: Duplicate host found with IP {0}".format(ip))

    defaultsettingsfile = os.path.join(os.path.dirname(__file__),
                                       "settings.yaml")
    newsettings = Settings().read(settingsfile)
    settings = \
        {
            "ADMIN_NETWORK/interface": iface,
            "ADMIN_NETWORK/ipaddress": ip,
            "ADMIN_NETWORK/netmask": netmask,
            "ADMIN_NETWORK/mac": mac,
            "ADMIN_NETWORK/dhcp_pool_start": dynamic_start,
            "ADMIN_NETWORK/dhcp_pool_end": dynamic_end,
            "ADMIN_NETWORK/dhcp_gateway": ip,
            "HOSTNAME": hostname,
            "DNS_DOMAIN": domain,
            "DNS_SEARCH": domain,
            "astute/user": "******",
            "astute/password": pwgen.password(),
            "cobbler/user": "******",
            "cobbler/password": pwgen.password(),
            "keystone/admin_token": pwgen.password(),
            "keystone/ostf_user": "******",
            "keystone/ostf_password": pwgen.password(),
            "keystone/nailgun_user": "******",
            "keystone/nailgun_password": pwgen.password(),
            "keystone/monitord_user": "******",
            "keystone/monitord_password": pwgen.password(),
            "mcollective/user": "******",
            "mcollective/password": pwgen.password(),
            "postgres/keystone_dbname": "keystone",
            "postgres/keystone_user": "******",
            "postgres/keystone_password": pwgen.password(),
            "postgres/nailgun_dbname": "nailgun",
            "postgres/nailgun_user": "******",
            "postgres/nailgun_password": pwgen.password(),
            "postgres/ostf_dbname": "ostf",
            "postgres/ostf_user": "******",
            "postgres/ostf_password": pwgen.password(),
            "FUEL_ACCESS/user": "******",
            "FUEL_ACCESS/password": "******",
        }
    for setting in settings.keys():
        if "/" in setting:
            part1, part2 = setting.split("/")
            if part1 not in newsettings.keys():
                newsettings[part1] = {}
            #Keep old values for passwords if already set
            if "password" in setting:
                newsettings[part1].setdefault(part2, settings[setting])
            else:
                newsettings[part1][part2] = settings[setting]
        else:
            if "password" in setting:
                newsettings.setdefault(setting, settings[setting])
            else:
                newsettings[setting] = settings[setting]

    #Write astute.yaml
    Settings().write(newsettings, defaultsfile=defaultsettingsfile,
                     outfn=settingsfile)
예제 #4
0
파일: fuelmenu.py 프로젝트: toby82/fuel-web
def save_only(iface, settingsfile='/etc/fuel/astute.yaml'):
    import common.network as network
    from common import pwgen
    import netifaces

    #Calculate and set Static/DHCP pool fields
    #Max IPs = net size - 2 (master node + bcast)
    try:
        ip = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr']
        netmask = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['netmask']
        mac = netifaces.ifaddresses(iface)[netifaces.AF_LINK][0]['addr']
    except Exception:
        print("Interface %s is missing either IP address or netmask"
              % (iface))
        sys.exit(1)
    net_ip_list = network.getNetwork(ip, netmask)
    try:
        dhcp_pool = net_ip_list[1:]
        dynamic_start = str(dhcp_pool[0])
        dynamic_end = str(dhcp_pool[-1])
    except Exception:
        print("Unable to define DHCP pools")
        sys.exit(1)
    try:
        hostname, sep, domain = os.uname()[1].partition('.')
    except Exception:
        print("Unable to calculate hostname and domain")
        sys.exit(1)
    try:
        dhcptimeout = 5
        default = []
        with timeout.run_with_timeout(dhcp_checker.utils.IfaceState, [iface],
                                      timeout=dhcptimeout) as iface:
            dhcp_server_data = timeout.run_with_timeout(
                dhcp_checker.api.check_dhcp_on_eth,
                [iface, dhcptimeout], timeout=dhcptimeout,
                default=default)
    except (KeyboardInterrupt, timeout.TimeoutError):
        log.debug("DHCP scan timed out")
        log.warning(traceback.format_exc())
        dhcp_server_data = default

    num_dhcp = len(dhcp_server_data)
    if num_dhcp == 0:
        log.debug("No DHCP servers found")
    else:
        #Problem exists, but permit user to continue
        log.error("%s foreign DHCP server(s) found: %s" %
                  (num_dhcp, dhcp_server_data))
        print("ERROR: %s foreign DHCP server(s) found: %s" %
              (num_dhcp, dhcp_server_data))
    if network.duplicateIPExists(ip, iface):
        log.error("Duplicate host found with IP {0}".format(ip))
        print("ERROR: Duplicate host found with IP {0}".format(ip))

    newsettings = Settings().read(settingsfile)
    settings = \
        {
            "ADMIN_NETWORK/interface": iface,
            "ADMIN_NETWORK/ipaddress": ip,
            "ADMIN_NETWORK/netmask": netmask,
            "ADMIN_NETWORK/mac": mac,
            "ADMIN_NETWORK/dhcp_pool_start": dynamic_start,
            "ADMIN_NETWORK/dhcp_pool_end": dynamic_end,
            "ADMIN_NETWORK/dhcp_gateway": ip,
            "HOSTNAME": hostname,
            "DNS_DOMAIN": domain,
            "DNS_SEARCH": domain,
            "astute/user": "******",
            "astute/password": pwgen.password(),
            "cobbler/user": "******",
            "cobbler/password": pwgen.password(),
            "keystone/admin_token": pwgen.password(),
            "keystone/ostf_user": "******",
            "keystone/ostf_password": pwgen.password(),
            "keystone/nailgun_user": "******",
            "keystone/nailgun_password": pwgen.password(),
            "keystone/monitord_user": "******",
            "keystone/monitord_password": pwgen.password(),
            "mcollective/user": "******",
            "mcollective/password": pwgen.password(),
            "postgres/keystone_dbname": "keystone",
            "postgres/keystone_user": "******",
            "postgres/keystone_password": pwgen.password(),
            "postgres/nailgun_dbname": "nailgun",
            "postgres/nailgun_user": "******",
            "postgres/nailgun_password": pwgen.password(),
            "postgres/ostf_dbname": "ostf",
            "postgres/ostf_user": "******",
            "postgres/ostf_password": pwgen.password(),
            "FUEL_ACCESS/user": "******",
            "FUEL_ACCESS/password": "******",
        }
    for setting in settings.keys():
        if "/" in setting:
            part1, part2 = setting.split("/")
            if part1 not in newsettings.keys():
                newsettings[part1] = {}
            #Keep old values for passwords if already set
            if "password" in setting:
                newsettings[part1].setdefault(part2, settings[setting])
            else:
                newsettings[part1][part2] = settings[setting]
        else:
            if "password" in setting:
                newsettings.setdefault(setting, settings[setting])
            else:
                newsettings[setting] = settings[setting]

    #Write astute.yaml
    Settings().write(newsettings, defaultsfile=None,
                     outfn=settingsfile)