-
Notifications
You must be signed in to change notification settings - Fork 4
/
brooklyn-dns-etc-hosts-generator.bom
100 lines (91 loc) · 4.39 KB
/
brooklyn-dns-etc-hosts-generator.bom
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
brooklyn.catalog:
version: "0.2.0-SNAPSHOT" # BROOKLYN_DNS_VERSION
description: |
Entity that generates an '/etc/hosts' file containing the addresses
of a group of entities that have the 'brooklyn_dns.enabled' config key set.
publish:
license_code: APACHE-2.0
license_url: http://www.apache.org/licenses/LICENSE-2.0.txt
items:
- id: brooklyn-dns-etc-hosts-generator
itemType: entity
item:
type: org.apache.brooklyn.entity.group.DynamicGroup
name: Brooklyn DNS /etc/hosts Generation Group
iconUrl: classpath:///dns-150x150.jpg
id: brooklyn-dns-etc-hosts-generator
brooklyn.parameters:
- name: brooklyn_dns.domain
label: "Domain Name"
description: |
The domain name suffix to use for generated hostnames
default: "brooklyn.local"
- name: brooklyn_dns.hosts.basename.sensor
label: Basename sensor
description: |
The sensor giving the host basename on entities for which this provides name serving;
the domain name is appended to the basename coming from that entity
default: entity.id
- name: brooklyn_dns.hosts.address.sensor
label: IP address sensor
description: |
The sensor giving the IP address on entities for which this provides name serving;
usually of the form 'host...address...', defaulting to the public IP address
but if all nodes are in a private subnet 'host.subnet.address' may be better
default: host.address
brooklyn.config:
dynamicgroup.entityfilter:
$brooklyn:object:
type: org.apache.brooklyn.core.entity.EntityPredicates
factoryMethod.name: "configEqualTo"
factoryMethod.args:
- "brooklyn_dns.enabled"
- true
brooklyn.enrichers:
- type: org.apache.brooklyn.enricher.stock.MapAggregator
brooklyn.config:
uniqueTag: host-address-aggregator
enricher.keySensor: $brooklyn:sensor($brooklyn:config("brooklyn_dns.hosts.basename.sensor"))
enricher.valueSensor: $brooklyn:sensor($brooklyn:config("brooklyn_dns.hosts.address.sensor"))
enricher.targetSensor: $brooklyn:sensor("host.map")
enricher.aggregating.fromMembers: true
enricher.aggregator.excludeBlank: true
- type: org.apache.brooklyn.enricher.stock.Joiner
brooklyn.config:
uniqueTag: host-address-joiner
enricher.sourceSensor: $brooklyn:sensor("host.map")
enricher.targetSensor: $brooklyn:sensor("host.addresses")
enricher.joiner.quote: false
enricher.joiner.separator: " "
enricher.joiner.keyValueSeparator: "="
enricher.joiner.joinMapEntries: true
brooklyn.policies:
- type: org.apache.brooklyn.policy.InvokeEffectorOnSensorChange
brooklyn.config:
sensor: host.addresses
effector: updateEtcHostsOnMembers
brooklyn.initializers:
- type: org.apache.brooklyn.core.effector.ssh.SshCommandEffector
brooklyn.config:
name: updateEtcHostsOnMembers
description: "Updates /etc/hosts file on all members"
executionTarget: MEMBERS
shell.env:
HOST_ADDRESSES:
$brooklyn:entity("brooklyn-dns-etc-hosts-generator").attributeWhenReady("host.addresses")
DOMAIN_NAME:
$brooklyn:entity("brooklyn-dns-etc-hosts-generator").config("brooklyn_dns.domain")
ENTITY_ID: $brooklyn:attributeWhenReady("entity.id")
command: |
(
flock 10
( sed '/# BEGIN_BROOKLYN_MANAGED_HOSTS/,/# END_BROOKLYN_MANAGED_HOSTS/d' /etc/hosts
echo "# BEGIN_BROOKLYN_MANAGED_HOSTS"
for host in ${HOST_ADDRESSES} ; do
name=$(echo ${host} | cut -d= -f1)
address=$(echo ${host} | cut -d= -f2)
echo "${address} ${name} ${name}.${DOMAIN_NAME}"
done
echo "# END_BROOKLYN_MANAGED_HOSTS" ) > /tmp/etc_hosts
sudo mv /tmp/etc_hosts /etc/hosts
) 10>> /tmp/updateEtcHosts.${ENTITY_ID}.lock