2
# Licensed under the Apache License, Version 2.0 (the "License");
3
# you may not use this file except in compliance with the License.
4
# You may obtain a copy of the License at
6
# http://www.apache.org/licenses/LICENSE-2.0
8
# Unless required by applicable law or agreed to in writing, software
9
# distributed under the License is distributed on an "AS IS" BASIS,
10
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
# See the License for the specific language governing permissions and
12
# limitations under the License.
15
from charmhelpers.contrib.bigdata import utils
16
from charmhelpers.core import hookenv
19
# send our hostname info on the relation
20
host, fqdn = utils.get_hostname_data()
21
hookenv.relation_set(hostfqdn=fqdn)
22
hookenv.relation_set(hostname=host)
24
# get the hostname attributes from our remote unit
25
remote_ip = hookenv.relation_get('private-address')
26
remote_fqdn = hookenv.relation_get('hostfqdn') or ""
27
remote_host = hookenv.relation_get('hostname') or ""
29
# onyl update if we have at least one valid hostname
30
if remote_fqdn or remote_host:
31
hookenv.log('Updating /etc/hosts with yarn-master hostname data',
33
host_entry = "{'%s': {'private-address': '%s', 'hostfqdn': '%s', 'hostname': '%s'}}" % (remote_ip, remote_ip, remote_fqdn, remote_host)
34
utils.update_etc_hosts(host_entry)
36
hookenv.log('Incomplete hostname data; not updating /etc/hosts',