Ubuntu Pastebin

Paste from Cory at Fri, 11 Dec 2015 15:06:34 +0000

Download as text
 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
# Copyright 2015 Canonical Ltd.
#
# This file is part of the PostgreSQL Charm for Juju.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, 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/>.


class SyslogProvides(reactive.relations.RelationBase):
    # TODO: Should this be global scope?
    class states(reactive.relations.StateList):
        available = reactive.State('{relation_name}.available')

    @hook('{provides:syslog}-relation-changed')
    def changed(self):
        self.set_state('{relation_name}.available')

    def get_loggers(self):
        """
        Returns a mapping of remote units to their private-address
        for all connected loggers.
        """
        loggers = {}
        for conv in self.conversations():
            loggers[conv.scope] = conv.get_remote('private-address')
        return loggers

    def send_config(self, unit, program_name, log_line_prefix):
        conv = self.conversation(unit)
        conv.set_remote(data={
            'programname': program_name,
            'log_line_prefix': log_line_prefix,
        })

    @hook('{provides:syslog}-relation-departed')
    def departed(self):
        self.remove_state('{relation_name}.available')
Download as text