Beispiel #1
0
 def load(self):
     helper.ModuleHelper.load_to_defaults(self.parent.settings,
                                          self.defaults,
                                          ignoredparams=[SSH_NETWORK])
     admin_network = self.parent.settings["ADMIN_NETWORK"]
     self.defaults[SSH_NETWORK]['value'] = network.getCidr(
         admin_network["ipaddress"], admin_network["netmask"])
     if 'ssh_network' in admin_network:
         self.defaults[SSH_NETWORK]['value'] = admin_network["ssh_network"]
Beispiel #2
0
    def load(self):
        admin_network = network.get_iface_info(self.parent.managediface)
        self.defaults[SSH_NETWORK]['value'] = network.getCidr(
            admin_network["addr"], admin_network["netmask"])

        helper.ModuleHelper.load_to_defaults(
            self.parent.settings,
            self.defaults,
        )
Beispiel #3
0
    def load(self):
        admin_network = network.get_iface_info(self.parent.managediface)
        self.defaults[SSH_NETWORK]['value'] = network.getCidr(
            admin_network["addr"],
            admin_network["netmask"])

        helper.ModuleHelper.load_to_defaults(
            self.parent.settings,
            self.defaults,
        )
Beispiel #4
0
 def load(self):
     helper.ModuleHelper.load_to_defaults(
         self.parent.settings,
         self.defaults,
         ignoredparams=[SSH_NETWORK])
     admin_network = self.parent.settings["ADMIN_NETWORK"]
     self.defaults[SSH_NETWORK]['value'] = network.getCidr(
         admin_network["ipaddress"],
         admin_network["netmask"])
     if 'ssh_network' in admin_network:
         self.defaults[SSH_NETWORK]['value'] = admin_network["ssh_network"]
Beispiel #5
0
    def save(self, responses):
        ## Generic settings start ##
        newsettings = dict()
        for setting in responses.keys():
            if "/" in setting:
                part1, part2 = setting.split("/")
                if part1 not in newsettings:
                    #We may not touch all settings, so copy oldsettings first
                    newsettings[part1] = self.oldsettings[part1]
                newsettings[part1][part2] = responses[setting]
            else:
                newsettings[setting] = responses[setting]
        ## Generic settings end ##

        ## Need to calculate and set cidr, netmask, size
        newsettings['ADMIN_NETWORK']['netmask'] = self.netsettings[newsettings
                   ['ADMIN_NETWORK']['interface']]["netmask"]
        newsettings['ADMIN_NETWORK']['cidr'] = network.getCidr(
            self.netsettings[newsettings['ADMIN_NETWORK']['interface']][
                "addr"], newsettings['ADMIN_NETWORK']['netmask'])
        newsettings['ADMIN_NETWORK']['size'] = network.getCidrSize(
            newsettings['ADMIN_NETWORK']['cidr'])

        log.debug(str(newsettings))
        Settings().write(newsettings,
                         defaultsfile=self.parent.defaultsettingsfile,
                         outfn=self.parent.settingsfile)
        #Write naily.facts
        factsettings = dict()
        #for key in newsettings.keys():
        log.debug(str(facter_translate))
        log.debug(str(newsettings))
        for key in facter_translate.keys():
            factsettings[facter_translate[key]] = responses[key]
        n = nailyfactersettings.NailyFacterSettings()
        log.debug("Facts to write: %s" % factsettings)
        n.write(factsettings)

        #Set oldsettings to reflect new settings
        self.oldsettings = newsettings
        #Update DEFAULTS
        for index, fieldname in enumerate(fields):
            if fieldname != "blank" and "label" not in fieldname:
                DEFAULTS[fieldname]['value'] = responses[fieldname]

        self.parent.footer.set_text("Changes saved successfully.")
Beispiel #6
0
def save_only(iface, settingsfile=consts.SETTINGS_FILE):
    from fuelmenu.common import pwgen
    import netifaces

    if utils.is_post_deployment():
        print("Not updating settings when invoked during post-deployment.\n"
              "Run fuelmenu manually to make changes.")
        sys.exit(0)

    # 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
        dhcp_server_data = network.search_external_dhcp(iface, dhcptimeout)
    except errors.NetworkException:
        log.error("DHCP scan failed")
        dhcp_server_data = []

    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))

    default_settings_file = os.path.join(os.path.dirname(__file__),
                                         "settings.yaml")
    mos_version = utils.get_fuel_version()

    settings = settings_module.Settings()

    settings.load(
        default_settings_file,
        template_kwargs={"mos_version": mos_version})

    settings.load(settingsfile, template_kwargs={"mos_version": mos_version})

    settings_upd = \
        {
            "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,
            "ADMIN_NETWORK/ssh_network": network.getCidr(ip, netmask),
            "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_upd.keys():
        if "/" in setting:
            part1, part2 = setting.split("/")
            settings.setdefault(part1, {})
            # Keep old values for passwords if already set
            if "password" in setting:
                settings[part1].setdefault(part2, settings_upd[setting])
            else:
                settings[part1][part2] = settings_upd[setting]
        else:
            if "password" in setting:
                settings.setdefault(setting, settings_upd[setting])
            else:
                settings[setting] = settings_upd[setting]

    # Write astute.yaml
    settings.write(outfn=settingsfile)