Пример #1
0
def save_only(iface):
    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:
        half = int(len(net_ip_list) / 2)
        #In most cases, skip 10.XXX.0.1
        static_pool = list(net_ip_list[1:half])
        dhcp_pool = list(net_ip_list[half:])
        static_start = str(static_pool[0])
        static_end = str(static_pool[-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)
    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/static_pool_start": static_start,
            "ADMIN_NETWORK/static_pool_end": static_end,
            "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(),
            "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": "******",
        }
    newsettings = dict()
    for setting in settings.keys():
        if "/" in setting:
            part1, part2 = setting.split("/")
            if part1 not in newsettings.keys():
                newsettings[part1] = {}
            newsettings[part1][part2] = settings[setting]
        else:
            newsettings[setting] = settings[setting]
    #Write astute.yaml
    Settings().write(newsettings,
                     defaultsfile=None,
                     outfn="/etc/fuel/astute.yaml")
Пример #2
0
def save_only(iface):
    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)
    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,
            "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(),
            "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": "******",
        }
    newsettings = dict()
    for setting in settings.keys():
        if "/" in setting:
            part1, part2 = setting.split("/")
            if part1 not in newsettings.keys():
                newsettings[part1] = {}
            newsettings[part1][part2] = settings[setting]
        else:
            newsettings[setting] = settings[setting]
    #Write astute.yaml
    Settings().write(newsettings, defaultsfile=None,
                     outfn="/etc/fuel/astute.yaml")
Пример #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
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)