~joetalbott/+junk/fix_tmpdir

« back to all changes in this revision

Viewing changes to core_image_builder/constants.py

  • Committer: Joe Talbott
  • Date: 2015-05-19 21:37:40 UTC
  • Revision ID: joe.talbott@canonical.com-20150519213740-48l0u6bmecbyg9mt
Add core-image-publisher code with name changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# core-image-builder
 
2
# Copyright (C) 2015 Canonical
 
3
#
 
4
# This program is free software: you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation, either version 3 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
#
 
17
 
 
18
"""Constants for this service."""
 
19
 
 
20
API_VERSION = "v1"
 
21
 
 
22
RETRY_COUNT = 3
 
23
 
 
24
SOLUTION_NAME = "core-image-testing"
 
25
 
 
26
SERVICE_NAME = "core-image-builder"
 
27
 
 
28
 
 
29
def _get_hostname():
 
30
    """Return sanitized contents of /etc/hostname.
 
31
 
 
32
    It is necessary because current juju hostnames (juju-<env-name>-machine-#)
 
33
    are too big due to our long environment names ('<spec_name>-<MD5>').
 
34
    Linux (DNS for RFC1035, really) only supports labels up to 64 chars and
 
35
    the fallback varies from tool to tool, `cloud-init` chokes on longer
 
36
    names and sets 'ubuntu' (which is the value considered by socket.get*),
 
37
    `hostnamectl` (systemd) would truncate the given data.
 
38
 
 
39
    None of this is ideal to our applications, that's why we will operate
 
40
    on the pristine /etc/hostname and remove the 'juju-' and '-machine' terms
 
41
    added by juju.
 
42
    """
 
43
    with open('/etc/hostname') as fd:
 
44
        hostname = fd.read()
 
45
    return hostname.replace('juju-', '').replace('-machine', '').strip()
 
46
 
 
47
 
 
48
HOSTNAME = _get_hostname()
 
49
 
 
50
LOGGING_EXTRA = {
 
51
    'solution': SOLUTION_NAME,
 
52
    'service': SERVICE_NAME,
 
53
    'hostname': HOSTNAME,
 
54
}