コード例 #1
0
ファイル: config.py プロジェクト: tai271828/maas
    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
ファイル: config.py プロジェクト: cloudbase/maas
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
ファイル: config.py プロジェクト: cloudbase/maas
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
ファイル: test_config.py プロジェクト: casual-lemon/maas
 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
ファイル: config.py プロジェクト: cloudbase/maas
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
ファイル: config.py プロジェクト: cloudbase/maas
    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
ファイル: config.py プロジェクト: cloudbase/maas
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
ファイル: test_utils.py プロジェクト: cloudbase/maas
 def test_returns_branch_etc_maas(self):
     self.assertEqual(get_branch_dir('etc/maas'), locate_config())
     self.assertThat(locate_config(), DirExists())
コード例 #19
0
ファイル: test_utils.py プロジェクト: cloudbase/maas
 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
ファイル: snippets.py プロジェクト: cloudbase/maas
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
ファイル: test_utils.py プロジェクト: cloudbase/maas
 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
ファイル: config.py プロジェクト: cloudbase/maas
 def template_dir(self):
     return locate_config(TEMPLATES_DIR)
コード例 #24
0
ファイル: test_utils.py プロジェクト: cloudbase/maas
 def test_returns_absolute_path(self):
     self.useFixture(EnvironmentVariableFixture('MAAS_CONFIG_DIR', '.'))
     self.assertTrue(os.path.isabs(locate_config()))
コード例 #25
0
ファイル: test_utils.py プロジェクト: cloudbase/maas
 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
ファイル: poweraction.py プロジェクト: cloudbase/maas
 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
ファイル: poweraction.py プロジェクト: cloudbase/maas
 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
ファイル: test_utils.py プロジェクト: cloudbase/maas
 def test_normalizes_path(self):
     self.assertEquals(
         get_branch_dir('etc/maas/bar/szot'),
         locate_config('foo/.././bar///szot'))
コード例 #32
0
ファイル: test_poweraction.py プロジェクト: cloudbase/maas
 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')