Esempio n. 1
0
    def __init__(self, save_only=False, managed_iface=None):
        self.save_only = save_only
        self.footer = None
        self.frame = None
        self.screen = None
        self.dns_might_have_changed = False
        self.managediface = managed_iface or network.get_physical_ifaces()[0]
        # Set to true to move all settings to end
        self.globalsave = True
        # Tasks to be executed on Apply
        self.apply_tasks = set()
        self.version = utils.get_fuel_version()
        self.codename = 'xenial'

        # settings load
        self.settings = settings_module.Settings()

        template_kwargs = {
            "mos_version": self.version,
            "codename": self.codename,
        }

        self.settings.load(
            os.path.join(os.path.dirname(__file__), "settings.yaml"),
            template_kwargs=template_kwargs)

        self.settings.load(
            consts.SETTINGS_FILE,
            template_kwargs=template_kwargs)

        self.main()
        self.choices = []
Esempio n. 2
0
    def make_settings_from_responses(cls, responses):
        """Create new Settings object from responses."""
        newsettings = settings_module.Settings()

        for setting in responses:
            cls.set_setting(newsettings, setting, responses[setting])
        return newsettings
Esempio n. 3
0
    def setUp(self):
        self.directory = tempfile.mkdtemp()

        yaml_file = os.path.join(self.directory, "__yamlfile.yaml")
        open(yaml_file, 'w').write("""
sample:
  one:
    a: b
    c: d
""")
        self.settings = settings_module.Settings()
        self.settings.load(yaml_file)
Esempio n. 4
0
 def check_settings(self, settings):
     required_keys = []
     responses = settings_utils.Settings()
     for key, subkeys in KEYS_TO_RESTORE:
         if key not in settings:
             if subkeys:
                 required_keys.extend("{0}/{1}".format(key, subkey)
                                      for subkey in subkeys)
                 continue
             required_keys.append(key)
             continue
         parameters = settings[key]
         if not subkeys:
             responses[key] = parameters
             continue
         for subkey in subkeys:
             subkey_name = "{0}/{1}".format(key, subkey)
             if subkey not in parameters:
                 required_keys.append(subkey_name)
                 continue
             responses[subkey_name] = parameters[subkey]
     return responses, required_keys
Esempio n. 5
0
    def check(self, args):
        self.parent.footer.set_text("Checking data...")
        self.parent.refreshScreen()

        path = self.edits[0].get_edit_text()
        # The PATH field is not required and if it is empty, then there
        # is nothing to check.
        if not path:
            self.parent.footer.set_text("Nothing to check.")
            return None

        path = os.path.abspath(path)
        try:
            settings = settings_utils.Settings()
            settings.load(path)
        except IOError as err:
            self.show_error_msg("Could not fetch settings: {0}".format(err),
                                exc_info=True)
            return False
        except yaml.YAMLError as err:
            self.show_error_msg(
                "Could not parse YAML from the source: {0}.".format(err),
                exc_info=True)
            return False

        LOG.debug("Successfully loaded settings: %s", settings)

        if not settings:
            self.show_error_msg("Settings should not be empty.")
            return False

        responses, required_keys = self.check_settings(settings)
        if required_keys:
            self.show_error_msg("Settings should contain keys: {0}".format(
                ', '.join(required_keys)))
            return False

        self.parent.footer.set_text("No errors found.")
        return responses
Esempio n. 6
0
    def __init__(self):
        self.footer = None
        self.frame = None
        self.screen = None
        self.managediface = network.get_physical_ifaces()[0]
        self.dns_might_have_changed = False
        # Set to true to move all settings to end
        self.globalsave = True
        self.version = utils.get_fuel_version()

        # settings load
        self.settings = settings_module.Settings()

        self.settings.load(
            os.path.join(os.path.dirname(__file__), "settings.yaml"),
            template_kwargs={"mos_version": self.version})

        self.settings.load(
            consts.SETTINGS_FILE,
            template_kwargs={"mos_version": self.version})

        self.main()
        self.choices = []
Esempio n. 7
0
 def test_read_settings_with_error(self, _):
     data = settings_module.Settings()
     data.load('some_path')
     self.assertEqual(data, {})
Esempio n. 8
0
 def setUp(self):
     super(BaseModuleTests, self).setUp()
     self.parent = mock.Mock(apply_tasks=set(),
                             settings=settings.Settings({}))
Esempio n. 9
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)