blob: e6550635595d360b2bae47c30becaea6a6f270ea [file] [log] [blame]
Tony Hansen749bc2d2017-10-03 02:51:42 +00001# -*- indent-tabs-mode: nil -*- # vi: set expandtab:
2#
3# ============LICENSE_START====================================================
4# org.onap.dcae
5# =============================================================================
6# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7# =============================================================================
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19# ============LICENSE_END======================================================
20
Michael Hwangc74aad52017-09-11 13:49:15 -040021tosca_definitions_version: cloudify_dsl_1_3
22
23imports:
24 - http://www.getcloudify.org/spec/cloudify/3.4/types.yaml
25 - http://www.getcloudify.org/spec/openstack-plugin/1.4/plugin.yaml
26 - http://www.getcloudify.org/spec/fabric-plugin/1.4.1/plugin.yaml
27 - {{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/dnsdesig/dns_types.yaml
28 - {{ ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases }}/type_files/sshkeyshare/sshkey_types.yaml
Hansen, Tony (th1395)68765fc2018-04-27 00:37:31 +000029 - {{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/relationshipplugin/1.0.0/relationshipplugin_types.yaml
Lusheng Ji2283aba2017-10-10 16:59:05 +000030 - {{ ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases }}/type_files/dockerplugin/2/dockerplugin_types.yaml
31
32
Michael Hwangc74aad52017-09-11 13:49:15 -040033
34inputs:
35 registered_dockerhost_name:
36 description: the name that this Dockerhost is registered as
37 location_id:
38 description: the location ID for the location where the Docker hsot is being deployed
39 type: string
Michael Hwang78d00cd2017-10-11 12:39:58 -040040 target_datacenter:
41 description: |-
42 This is the name of the target Consul datacenter that the docker host will try to join
43 type: string
Michael Hwangc74aad52017-09-11 13:49:15 -040044 registrator_image:
45 description: |-
46 Full uri to registrator Docker image. Note! You should be using the forked version of
47 registrator in order to have Consul health checks for Docker containers.
48 type: string
49 centos7image_id:
50 type: string
51 default: ''
52 ubuntu1604image_id:
53 type: string
54 flavor_id:
55 type: string
56 security_group:
57 type: string
58 public_net:
59 type: string
60 private_net:
61 type: string
62 openstack: {}
Michael Hwangc74aad52017-09-11 13:49:15 -040063 keypair:
64 type: string
65 location_prefix:
66 type: string
67 location_domain:
68 type: string
69 node_name:
70 description: Used to construct the fqdn of the docker host
71 type: string
72 default: dokr00
73 key_filename:
74 type: string
75 codesource_url:
76 type: string
77 codesource_version:
78 type: string
79 vm_init_dokr_00:
80 type: string
81 default: |-
82 #!/bin/sh
83 set -x
84 DATACENTER=
85 vm_init_dokr_01:
86 type: string
87 default: |-
88 REGNAME=
89 vm_init_dokr_fqdn:
90 type: string
91 description: |-
92 The FQDN environment variable is to be used in the cloud init script for the Docker host.
93 This is to be applied as metadata on the Consul node for the Docker host under the key
94 "fqdn".
95 default: |-
96 FQDN=
97 vm_init_dokr_service_tags:
98 type: string
99 description: |-
100 Environment variable assigned to a list of strings that are to be used as tags to label
101 the docker host. These tags are used when registering the docker host as a service in
102 Consul. The format of this input parameter is a string that is a shell script variable
103 assignment of the variable SERVICE_TAGS. It must be either null or a json array of strings.
104 Here is a valid example of when the value is a json array:
105
106 'SERVICE_TAGS="[\"foo\", \"bar\"]"'
107
108 Note how the double quotes per array element are escaped.
109 default: "SERVICE_TAGS=null"
110 vm_init_dokr_02:
111 type: string
112 default: |
113 MYIP=`wget -qO- http://169.254.169.254/2009-04-04/meta-data/local-ipv4`
Lusheng Ji532197c2017-10-19 01:41:26 -0400114 while [ -z "$MYPUB" ]; do
115 MYPUB=`wget -qO- http://169.254.169.254/2009-04-04/meta-data/public-ipv4`
116 sleep 5
117 done
Michael Hwangc74aad52017-09-11 13:49:15 -0400118 echo "My public IP: $MYPUB"
119 MYNAME=`hostname`
120 echo >>/etc/hosts
121 echo $MYIP $MYNAME >>/etc/hosts
122
123 # Grab nameservers to be used to setup recursors for Consul
124 cat <<EOF > /tmp/grab_nameservers.py
125 with open("/etc/resolv.conf", "r") as f:
126 nss = [line.split(" ")[1].strip() for line in f.readlines() if line.startswith("nameserver")]
127 print("[\"{0}\"]".format("\",\"".join(nss)))
128 EOF
129 NAMESERVERS=$(python3 /tmp/grab_nameservers.py)
130
131 mkdir -p /opt/consul/config /opt/consul/data /opt/consul/bin
132 # Download Consul from Nexus
Michael Hwang78d00cd2017-10-11 12:39:58 -0400133 apt-get update
134 DEBIAN_FRONTEND=noninteractive apt-get install -y -q unzip
Michael Hwang13c16b32017-10-13 10:58:32 -0400135 CONSUL_BIN_DIR=/opt/consul/bin
136 curl -Ss https://releases.hashicorp.com/consul/0.8.3/consul_0.8.3_linux_amd64.zip > $CONSUL_BIN_DIR/consul_0.8.3_linux_amd64.zip
137 unzip $CONSUL_BIN_DIR/consul_0.8.3_linux_amd64.zip -d $CONSUL_BIN_DIR
Michael Hwang68b32f42017-10-17 12:14:28 -0400138 # NOTE: The health check for the docker host is a simple existence look up for
139 # registrator (name is hardcoded). It does not check if registrator is running.
140 # This would require a script health check which means we might need to turn on
141 # "enable_script_check".
142 # NOTE: At the time of this change, there is no issue but there could be a
143 # chicken-and-egg issue where the health check might depend upon future downstream
144 # nodes (registrator) that downstream node requires a *healthy* docker host.
Michael Hwangc74aad52017-09-11 13:49:15 -0400145 cat <<EOF > /opt/consul/config/consul.json
146 {
147 "bind_addr" : "0.0.0.0",
148 "client_addr" : "0.0.0.0",
149 "advertise_addr" : "$MYIP",
150 "data_dir" : "/opt/consul/data",
151 "datacenter": "$DATACENTER",
152 "http_api_response_headers": {
153 "Access-Control-Allow-Origin" : "*"
154 },
155 "rejoin_after_leave": true,
156 "server": false,
157 "ui": false,
158 "enable_syslog": true,
159 "log_level": "info",
160 "ports": {
161 "dns": 53
162 },
163 "recursors": $NAMESERVERS,
164 "service" : {
165 "id": "$REGNAME",
166 "name": "$REGNAME",
167 "address": "$MYPUB",
168 "port": 2376,
Michael Hwang68b32f42017-10-17 12:14:28 -0400169 "tags": $SERVICE_TAGS,
170 "checks": [
171 {
172 "http": "http://$MYPUB:2376/containers/registrator/json",
173 "interval": "30s"
174 }
175 ]
Michael Hwangc74aad52017-09-11 13:49:15 -0400176 },
177 "node_meta": {
178 "fqdn": "$FQDN"
179 }
180 }
181 EOF
182
183 # Specify DOCKER_HOST environment variable to support healthchecks for Docker containers
184 # in Consul. Tried using the local unix socket but that did not work (possible bug in Consul)
185 # so forcing to use the http connection to Docker engine.
186 cat <<EOF > /lib/systemd/system/consul.service
187 [Unit]
188 Description=Consul
189 Requires=network-online.target
190 After=network.target
191 [Service]
192 Type=simple
193 Environment=DOCKER_HOST=tcp://localhost:2376
194 ExecStart=/opt/consul/bin/consul agent -config-dir=/opt/consul/config
195 ExecReload=/bin/kill -HUP \$MAINPID
196 [Install]
197 WantedBy=multi-user.target
198 EOF
199 systemctl enable consul
200 systemctl start consul
201 until /opt/consul/bin/consul join "cloudify-manager-${DATACENTER}"
202 do
203 echo Waiting to join Consul cluster
204 sleep 60
205 done
206
Michael Hwangc74aad52017-09-11 13:49:15 -0400207 DEBIAN_FRONTEND=noninteractive apt-get install -y -q linux-image-extra-`uname -r` linux-image-extra-virtual apparmor dirmngr
208 DEBIAN_FRONTEND=noninteractive apt-get install -y -q docker.io
209 echo 'DOCKER_OPTS="--raw-logs -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock"' >>/etc/default/docker
210 systemctl restart docker
211node_templates:
212 key_pair:
213 type: cloudify.openstack.nodes.KeyPair
214 properties:
215 private_key_path: { get_input: key_filename }
216 use_external_resource: True
217 resource_id: { get_input: keypair }
218 openstack_config: &open_conf
219 get_input: openstack
220 private_net:
221 type: cloudify.openstack.nodes.Network
222 properties:
223 use_external_resource: True
224 resource_id: { get_input: private_net }
225 openstack_config: *open_conf
226 security_group:
227 type: cloudify.openstack.nodes.SecurityGroup
228 properties:
229 use_external_resource: True
230 resource_id: { get_input: security_group }
231 openstack_config: *open_conf
232 fixedip_dokr00:
233 type: cloudify.openstack.nodes.Port
234 properties:
235 port:
236 extra_dhcp_opts:
237 - opt_name: 'domain-name'
238 opt_value: { get_input: location_domain }
239 openstack_config: *open_conf
240 relationships:
241 - type: cloudify.relationships.contained_in
242 target: private_net
243 floatingip_dokr00:
244 type: cloudify.openstack.nodes.FloatingIP
245 properties:
246 openstack_config: *open_conf
247 interfaces:
248 cloudify.interfaces.lifecycle:
249 create:
250 inputs:
251 args:
252 floating_network_name: { get_input: public_net }
253 dns_dokr00:
Andrew Gaulde9c68562017-10-11 10:30:51 -0400254 type: ccsdk.nodes.dns.arecord
Michael Hwangc74aad52017-09-11 13:49:15 -0400255 properties:
256 fqdn: { concat: [ { get_input: location_prefix }, { get_input: node_name }, '.', { get_input: location_domain } ] }
Michael Hwangc74aad52017-09-11 13:49:15 -0400257 openstack: *open_conf
258 interfaces:
259 cloudify.interfaces.lifecycle:
260 create:
261 inputs:
262 args:
263 ip_addresses:
264 - { get_attribute: [ floatingip_dokr00, floating_ip_address ] }
265 relationships:
266 - type: cloudify.relationships.depends_on
267 target: floatingip_dokr00
268 host_dokr00:
269 type: cloudify.openstack.nodes.Server
270 properties:
271 install_agent: false
272 image: { get_input: ubuntu1604image_id }
273 flavor: { get_input: flavor_id }
274 management_network_name: { get_input: private_net }
275 openstack_config: *open_conf
276 interfaces:
277 cloudify.interfaces.lifecycle:
278 create:
279 inputs:
280 args:
281 name: { concat: [ { get_input: location_prefix }, { get_input: node_name }] }
282 userdata:
283 concat:
284 - { get_input: vm_init_dokr_00 }
Michael Hwang78d00cd2017-10-11 12:39:58 -0400285 - { get_input: target_datacenter }
Michael Hwangc74aad52017-09-11 13:49:15 -0400286 - |+
287
288 - { get_input: vm_init_dokr_01 }
289 - { get_input: registered_dockerhost_name }
290 - |+
291
292 - { get_input: vm_init_dokr_fqdn }
293 - { get_property: [ dns_dokr00, fqdn ] }
294 - |+
295
296 - { get_input: vm_init_dokr_service_tags }
297 - |+
298
299 - { get_input: vm_init_dokr_02 }
300 relationships:
301 - type: cloudify.openstack.server_connected_to_port
302 target: fixedip_dokr00
303 - type: cloudify.openstack.server_connected_to_security_group
304 target: security_group
305 - type: cloudify.openstack.server_connected_to_floating_ip
306 target: floatingip_dokr00
307 - type: cloudify.openstack.server_connected_to_keypair
308 target: key_pair
309 - type: cloudify.relationships.depends_on
310 target: dns_dokr00
311
312 registrator:
313 type: dcae.nodes.DockerContainer
314 properties:
315 name:
316 'registrator'
317 image:
318 { get_input: registrator_image }
319 relationships:
320 - type: dcae.relationships.component_contained_in
321 target: docker_host
322 interfaces:
323 cloudify.interfaces.lifecycle:
324 start:
325 inputs:
326 envs:
327 EXTERNAL_IP:
328 get_attribute: [ floatingip_dokr00, floating_ip_address ]
329 volumes:
330 - host:
331 path: '/var/run/docker.sock'
332 container:
333 bind: '/tmp/docker.sock'
334 mode: 'ro'
335
336 docker_host:
337 type: dcae.nodes.SelectedDockerHost
338 properties:
339 location_id:
340 { get_input: location_id }
341 docker_host_override:
342 { get_input: registered_dockerhost_name }
343 relationships:
344 - type: cloudify.relationships.depends_on #this is to avoid a race condition
345 target: host_dokr00