~canonical-ci-engineering/core-image-watcher/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# core-image-watcher
# Copyright (C) 2015 Canonical
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

"""Constants for this service."""


API_VERSION = "v1"

SOLUTION_NAME = "core-image-testing"

SERVICE_NAME = "core-image-watcher"

def _get_hostname():
    """Return sanitized contents of /etc/hostname.

    It is necessary because current juju hostnames (juju-<env-name>-machine-#)
    are too big due to our long environment names ('<spec_name>-<MD5>').
    Linux (DNS for RFC1035, really) only supports labels up to 64 chars and
    the fallback varies from tool to tool, `cloud-init` chokes on longer
    names and sets 'ubuntu', `hostnamectl` (systemd) would truncate the
    given data. 

    None of this is ideal to our applications, that's why we will operate
    on the pristine /etc/hostname and remove the 'juju-' and '-machine' terms
    added by juju.
    """
    with open('/etc/hostname') as fd:
        hostname = fd.read()
    return hostname.replace('juju-', '').replace('-machine', '').strip()


HOSTNAME = _get_hostname()