~ubuntu-branches/ubuntu/utopic/maas/utopic-security

« back to all changes in this revision

Viewing changes to src/metadataserver/user_data/snippets.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez, Jeroen Vermeulen, Andres Rodriguez, Jason Hobbs, Raphaël Badin, Louis Bouchard, Gavin Panella
  • Date: 2014-08-21 19:36:30 UTC
  • mfrom: (1.3.1)
  • Revision ID: package-import@ubuntu.com-20140821193630-kertpu5hd8yyss8h
Tags: 1.7.0~beta7+bzr3266-0ubuntu1
* New Upstream Snapshot, Beta 7 bzr3266

[ Jeroen Vermeulen ]
* debian/extras/99-maas-sudoers
  debian/maas-dhcp.postinst
  debian/rules
  - Add second DHCP server instance for IPv6.
* debian/maas-region-controller-min.install
  debian/maas-region-controller-min.lintian-overrides
  - Install deployment user-data: maas_configure_interfaces.py script.
* debian/maas-cluster-controller.links
  debian/maas-cluster-controller.install
  debian/maas-cluster-controller.postinst
  - Reflect Celery removal changes made in trunk r3067.
  - Don't install celeryconfig_cluster.py any longer. 
  - Don't install maas_local_celeryconfig_cluster.py any longer.
  - Don't symlink maas_local_celeryconfig_cluster.py from /etc to /usr.
  - Don't insert UUID into maas_local_celeryconfig_cluster.py.

[ Andres Rodriguez ]
* debian/maas-region-controller-min.postrm: Cleanup lefover files.
* debian/maas-dhcp.postrm: Clean leftover configs.
* Provide new maas-proxy package that replaces the usage of
  squid-deb-proxy:
  - debian/control: New maas-proxy package that replaces the usage
    of squid-deb-proxy; Drop depends on squid-deb-proxy.
  - Add upstrart job.
  - Ensure squid3 is stopped as maas-proxy uses a caching proxy.
* Remove Celery references to cluster controller:
  - Rename upstart job from maas-pserv to maas-cluster; rename
    maas-cluster-celery to maas-cluster-register. Ensure services
    are stopped on upgrade.
  - debian/maintscript: Cleanup config files.
  - Remove all references to the MAAS celery daemon and config
    files as we don't use it like that anymore
* Move some entries in debian/maintscript to
  debian/maas-cluster-controller.maintscript
* Remove usage of txlongpoll and rabbitmq-server. Handle upgrades
  to ensure these are removed correctly.

[ Jason Hobbs ]
* debian/maas-region-controller-min.install: Install
  maas-generate-winrm-cert script.

[ Raphaël Badin ]
* debian/extras/maas-region-admin: Bypass django-admin as it prints
  spurious messages to stdout (LP: #1365130).

[Louis Bouchard]
* debian/maas-cluster-controller.postinst:
  - Exclude /var/log/maas/rsyslog when changing ownership
    (LP: #1346703)

[Gavin Panella]
* debian/maas-cluster-controller.maas-clusterd.upstart:
  - Don't start-up the cluster controller unless a shared-secret has
    been installed.
* debian/maas-cluster-controller.maas-cluster-register.upstart: Drop.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012-2014 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Low-level routines for access to snippets.
 
5
 
 
6
These are used by the user-data code, but also by `setup.py`.  That's why
 
7
importing this must not pull in any unnecessary framework modules etc.
 
8
"""
 
9
 
 
10
from __future__ import (
 
11
    absolute_import,
 
12
    print_function,
 
13
    unicode_literals,
 
14
    )
 
15
 
 
16
str = None
 
17
 
 
18
__metaclass__ = type
 
19
__all__ = [
 
20
    'list_snippets',
 
21
    'read_snippet',
 
22
    'strip_name',
 
23
    'get_snippet_context',
 
24
    'get_userdata_template_dir',
 
25
    ]
 
26
 
 
27
import os
 
28
 
 
29
from provisioningserver.utils import locate_config
 
30
from provisioningserver.utils.fs import read_text_file
 
31
 
 
32
 
 
33
USERDATA_BASE_DIR = 'templates/commissioning-user-data'
 
34
 
 
35
 
 
36
def get_userdata_template_dir():
 
37
    """Return the absolute location of the userdata
 
38
    template directory."""
 
39
    return locate_config(USERDATA_BASE_DIR)
 
40
 
 
41
 
 
42
def get_snippet_context(snippets_dir=None, encoding='utf-8'):
 
43
    """Return the context of all of the snippets."""
 
44
    if snippets_dir is None:
 
45
        snippets_dir = os.path.join(get_userdata_template_dir(), 'snippets')
 
46
    snippets = {
 
47
        strip_name(name): read_snippet(snippets_dir, name, encoding=encoding)
 
48
        for name in list_snippets(snippets_dir)
 
49
        }
 
50
    return snippets
 
51
 
 
52
 
 
53
def read_snippet(snippets_dir, name, encoding='utf-8'):
 
54
    """Read a snippet file.
 
55
 
 
56
    :rtype: `unicode`
 
57
    """
 
58
    return read_text_file(os.path.join(snippets_dir, name), encoding=encoding)
 
59
 
 
60
 
 
61
def is_snippet(filename):
 
62
    """Does `filename` represent a valid snippet name?"""
 
63
    return all([
 
64
        not filename.startswith('.'),
 
65
        filename != '__init__.py',
 
66
        filename != 'tests',
 
67
        not filename.endswith('.pyc'),
 
68
        not filename.endswith('~'),
 
69
        ])
 
70
 
 
71
 
 
72
def list_snippets(snippets_dir):
 
73
    """List names of available snippets."""
 
74
    return filter(is_snippet, os.listdir(snippets_dir))
 
75
 
 
76
 
 
77
def strip_name(snippet_name):
 
78
    """Canonicalize a snippet name."""
 
79
    # Dot suffixes do not work well in tempita variable names.
 
80
    return snippet_name.replace('.', '_')