Пример #1
0
    def _get_default_filename(cls):
        # Avoid circular imports.
        from provisioningserver.utils import locate_config

        # Get the configuration filename from the environment. Failing that,
        # look for the configuration in its default locations.
        return environ.get(cls.envvar, locate_config(cls.default))
Пример #2
0
def set_up_options_conf(overwrite=True, **kwargs):
    """Write out the named.conf.options.inside.maas file.

    This file should be included by the top-level named.conf.options
    inside its 'options' block.  MAAS cannot write the options file itself,
    so relies on either the DNSFixture in the test suite, or the packaging.
    Both should set that file up appropriately to include our file.
    """
    template_path = os.path.join(locate_config(TEMPLATES_DIR),
                                 "named.conf.options.inside.maas.template")
    template = tempita.Template.from_filename(template_path)

    # Make sure "upstream_dns" is set at least to None.  It's a
    # special piece of config that can't be obtained in celery
    # task code and we don't want to require that every call site
    # has to specify it.  If it's not set, the substitution will
    # fail with the default template that uses this value.
    kwargs.setdefault("upstream_dns")
    try:
        rendered = template.substitute(kwargs)
    except NameError as error:
        raise DNSConfigFail(*error.args)

    target_path = os.path.join(conf.DNS_CONFIG_DIR,
                               MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
    atomic_write(rendered, target_path, overwrite=overwrite, mode=0644)
Пример #3
0
def get_config(**params):
    """Return a DHCP config file based on the supplied parameters.

    :param subnet: The base subnet declaration. e.g. 192.168.1.0
    :param subnet_mask: The mask for the above subnet, e.g. 255.255.255.0
    :param broadcast_address: The broadcast IP address for the subnet,
        e.g. 192.168.1.255
    :param dns_servers: One or more IP addresses of the DNS server for the
        subnet
    :param ntp_server: IP address of the NTP server for the nodes
    :param domain_name: name that will be appended to the client's hostname to
        form a fully-qualified domain-name
    :param gateway: The router/gateway IP address for the subnet.
    :param low_range: The first IP address in the range of IP addresses to
        allocate
    :param high_range: The last IP address in the range of IP addresses to
        allocate
    """
    template_file = locate_config(TEMPLATES_DIR, 'dhcpd.conf.template')
    params['bootloader'] = compose_bootloader_path()
    params['platform_codename'] = linux_distribution()[2]
    params.setdefault("ntp_server")
    try:
        template = tempita.Template.from_filename(template_file,
                                                  encoding="UTF-8")
        return template.substitute(params)
    except NameError as error:
        raise DHCPConfigError(*error.args)
Пример #4
0
def get_config(**params):
    """Return a DHCP config file based on the supplied parameters.

    :param subnet: The base subnet declaration. e.g. 192.168.1.0
    :param subnet_mask: The mask for the above subnet, e.g. 255.255.255.0
    :param broadcast_address: The broadcast IP address for the subnet,
        e.g. 192.168.1.255
    :param dns_servers: One or more IP addresses of the DNS server for the
        subnet
    :param ntp_server: IP address of the NTP server for the nodes
    :param domain_name: name that will be appended to the client's hostname to
        form a fully-qualified domain-name
    :param gateway: The router/gateway IP address for the subnet.
    :param low_range: The first IP address in the range of IP addresses to
        allocate
    :param high_range: The last IP address in the range of IP addresses to
        allocate
    """
    template_file = locate_config(TEMPLATES_DIR, 'dhcpd.conf.template')
    params['bootloader'] = compose_bootloader_path()
    params['platform_codename'] = linux_distribution()[2]
    params.setdefault("ntp_server")
    try:
        template = tempita.Template.from_filename(
            template_file, encoding="UTF-8")
        return template.substitute(params)
    except NameError as error:
        raise DHCPConfigError(*error.args)
Пример #5
0
 def test_get_dns_config_dir_defaults_to_etc_bind_maas(self):
     self.useFixture(EnvironmentVariable("MAAS_DNS_CONFIG_DIR"))
     self.assertThat(
         config.get_dns_config_dir(),
         MatchesAll(SamePath(locate_config("../bind/maas")),
                    IsInstance(str)),
     )
Пример #6
0
def set_up_options_conf(overwrite=True, **kwargs):
    """Write out the named.conf.options.inside.maas file.

    This file should be included by the top-level named.conf.options
    inside its 'options' block.  MAAS cannot write the options file itself,
    so relies on either the DNSFixture in the test suite, or the packaging.
    Both should set that file up appropriately to include our file.
    """
    template_path = os.path.join(
        locate_config(TEMPLATES_DIR),
        "named.conf.options.inside.maas.template")
    template = tempita.Template.from_filename(template_path)

    # Make sure "upstream_dns" is set at least to None.  It's a
    # special piece of config that can't be obtained in celery
    # task code and we don't want to require that every call site
    # has to specify it.  If it's not set, the substitution will
    # fail with the default template that uses this value.
    kwargs.setdefault("upstream_dns")
    try:
        rendered = template.substitute(kwargs)
    except NameError as error:
        raise DNSConfigFail(*error.args)

    target_path = os.path.join(
        conf.DNS_CONFIG_DIR, MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
    atomic_write(rendered, target_path, overwrite=overwrite, mode=0644)
Пример #7
0
    def _get_default_filename(cls):
        # Avoid circular imports.
        from provisioningserver.utils import locate_config

        # Get the configuration filename from the environment. Failing that,
        # look for the configuration in its default locations.
        return environ.get("MAAS_PROVISIONING_SETTINGS",
                           locate_config('pserv.yaml'))
Пример #8
0
 def test_DNSConfig_defaults(self):
     dnsconfig = DNSConfig()
     self.assertEqual(
         (
             locate_config(TEMPLATES_DIR, 'named.conf.template'),
             os.path.join(conf.DNS_CONFIG_DIR, MAAS_NAMED_CONF_NAME)
         ),
         (dnsconfig.template_path, dnsconfig.target_path))
Пример #9
0
def get_bind_config_dir():
    """Location of bind configuration files."""
    setting = os.getenv("MAAS_BIND_CONFIG_DIR",
                        locate_config(os.path.pardir, "bind"))
    if isinstance(setting, bytes):
        fsenc = sys.getfilesystemencoding()
        return setting.decode(fsenc)
    else:
        return setting
Пример #10
0
 def test_computes_dns_config_file_paths(self):
     domain = factory.make_name('zone')
     dns_zone_config = DNSForwardZoneConfig(domain)
     self.assertEqual(
         (
             locate_config(TEMPLATES_DIR, 'zone.template'),
             os.path.join(conf.DNS_CONFIG_DIR, 'zone.%s' % domain),
         ),
         (
             dns_zone_config.template_path,
             dns_zone_config.target_path,
         ))
Пример #11
0
 def test_computes_dns_config_file_paths(self):
     domain = factory.make_name('zone')
     reverse_file_name = 'zone.168.192.in-addr.arpa'
     dns_zone_config = DNSReverseZoneConfig(
         domain, network=IPNetwork("192.168.0.0/22"))
     self.assertEqual(
         (
             locate_config(TEMPLATES_DIR, 'zone.template'),
             os.path.join(conf.DNS_CONFIG_DIR, reverse_file_name)
         ),
         (
             dns_zone_config.template_path,
             dns_zone_config.target_path,
         ))
Пример #12
0
def get_pxe_template(purpose, arch, subarch):
    pxe_templates_dir = locate_config(TEMPLATES_DIR)
    # Templates are loaded each time here so that they can be changed on
    # the fly without restarting the provisioning server.
    for filename in gen_pxe_template_filenames(purpose, arch, subarch):
        template_name = path.join(pxe_templates_dir, filename)
        try:
            return tempita.Template.from_filename(
                template_name, encoding="UTF-8")
        except IOError as error:
            if error.errno != ENOENT:
                raise
    else:
        raise AssertionError(
            "No PXE template found in %r!" % pxe_templates_dir)
Пример #13
0
 def test_get_pxe_template(self):
     purpose = factory.make_name("purpose")
     arch, subarch = factory.make_names("arch", "subarch")
     filename = factory.make_name("filename")
     # Set up the mocks that we've patched in.
     gen_filenames = self.patch(config, "gen_pxe_template_filenames")
     gen_filenames.return_value = [filename]
     from_filename = self.patch(tempita.Template, "from_filename")
     from_filename.return_value = mock.sentinel.template
     # The template returned matches the return value above.
     template = config.get_pxe_template(purpose, arch, subarch)
     self.assertEqual(mock.sentinel.template, template)
     # gen_pxe_template_filenames is called to obtain filenames.
     gen_filenames.assert_called_once_with(purpose, arch, subarch)
     # Tempita.from_filename is called with an absolute path derived from
     # the filename returned from gen_pxe_template_filenames.
     from_filename.assert_called_once_with(
         locate_config(config.TEMPLATES_DIR, filename), encoding="UTF-8")
Пример #14
0
 def test_locates_config_file(self):
     filename = factory.make_string()
     self.assertEqual(get_run_path("etc/maas/", filename),
                      locate_config(filename))
Пример #15
0
 def test_returns_absolute_path(self):
     self.useFixture(EnvironmentVariableFixture("MAAS_ROOT", "."))
     self.assertTrue(os.path.isabs(locate_config()))
Пример #16
0
 def test_defaults_to_global_etc_maas_if_variable_is_empty(self):
     self.useFixture(EnvironmentVariableFixture("MAAS_ROOT", ""))
     self.assertEqual("/etc/maas", locate_config())
Пример #17
0
 def test_returns_branch_etc_maas(self):
     self.assertEqual(get_run_path("etc/maas"), locate_config())
     self.assertThat(locate_config(), DirExists())
Пример #18
0
 def test_returns_branch_etc_maas(self):
     self.assertEqual(get_branch_dir('etc/maas'), locate_config())
     self.assertThat(locate_config(), DirExists())
Пример #19
0
 def test_locates_full_path(self):
     path = [factory.getRandomString() for counter in range(3)]
     self.assertEqual(
         get_branch_dir('etc/maas/', *path),
         locate_config(*path))
Пример #20
0
def get_userdata_template_dir():
    """Return the absolute location of the userdata
    template directory."""
    return locate_config(USERDATA_BASE_DIR)
Пример #21
0
 def config_basedir(self):
     """Directory where power config are stored."""
     # By default, power config lives in the same directory as power
     # templates.  This makes it easy to customize them together.
     return get_power_config_dir() or locate_config('templates/power')
Пример #22
0
 def test_defaults_to_global_etc_maas_if_variable_is_empty(self):
     self.useFixture(EnvironmentVariableFixture('MAAS_CONFIG_DIR', ''))
     self.assertEqual('/etc/maas', locate_config())
Пример #23
0
 def template_dir(self):
     return locate_config(TEMPLATES_DIR)
Пример #24
0
 def test_returns_absolute_path(self):
     self.useFixture(EnvironmentVariableFixture('MAAS_CONFIG_DIR', '.'))
     self.assertTrue(os.path.isabs(locate_config()))
Пример #25
0
 def test_locates_config_file(self):
     filename = factory.getRandomString()
     self.assertEqual(
         get_branch_dir('etc/maas/', filename),
         locate_config(filename))
Пример #26
0
 def test_locates_full_path(self):
     path = [factory.make_string() for counter in range(3)]
     self.assertEqual(get_run_path("etc/maas/", *path),
                      locate_config(*path))
Пример #27
0
 def template_basedir(self):
     """Directory where power templates are stored."""
     return get_power_templates_dir() or locate_config('templates/power')
Пример #28
0
 def test_normalizes_path(self):
     self.assertEqual(
         get_run_path("etc/maas/bar/szot"),
         locate_config("foo/.././bar///szot"),
     )
Пример #29
0
 def config_basedir(self):
     """Directory where power config are stored."""
     # By default, power config lives in the same directory as power
     # templates.  This makes it easy to customize them together.
     return get_power_config_dir() or locate_config('templates/power')
Пример #30
0
 def template_dir(self):
     return locate_config(TEMPLATES_DIR)
Пример #31
0
 def test_normalizes_path(self):
     self.assertEquals(
         get_branch_dir('etc/maas/bar/szot'),
         locate_config('foo/.././bar///szot'))
Пример #32
0
 def test_template_basedir_defaults_to_config_dir(self):
     self.configure_templates_dir()
     power_type = POWER_TYPE.WAKE_ON_LAN
     self.assertEqual(locate_config('templates/power'),
                      PowerAction(power_type).template_basedir)
Пример #33
0
 def template_basedir(self):
     """Directory where power templates are stored."""
     return get_power_templates_dir() or locate_config('templates/power')