# 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')