Merge "Make update-from-keystone-admin-internal-api.yaml work on newton+"
[apex-tripleo-heat-templates.git] / firstboot / os-net-config-mappings.yaml
1 heat_template_version: ocata
2
3 description: >
4   Configure os-net-config mappings for specific nodes
5   Your environment file needs to look like:
6     parameter_defaults:
7       NetConfigDataLookup:
8         node1:
9           nic1: "00:c8:7c:e6:f0:2e"
10         node2:
11           nic1: "00:18:7d:99:0c:b6"
12   This will result in the first nodeN entry where a mac matches a
13   local device being written as a mapping file for os-net-config in
14   /etc/os-net-config/mapping.yaml
15
16 parameters:
17   # Note this requires a liberty heat or newer in the undercloud due to
18   # the 2015-10-15 (which is required to enable str_replace serializing
19   # the json parameter to json, another approch with a string parameter
20   # will be required for older heat versions)
21   NetConfigDataLookup:
22     type: json
23     default: {}
24     description: per-node configuration map
25
26 resources:
27   userdata:
28     type: OS::Heat::MultipartMime
29     properties:
30       parts:
31       - config: {get_resource: OsNetConfigMappings}
32
33   OsNetConfigMappings:
34     type: OS::Heat::SoftwareConfig
35     properties:
36       group: ungrouped
37       config:
38         str_replace:
39           template: |
40             #!/bin/sh
41             eth_addr=$(cat /sys/class/net/*/address | tr '\n' ',')
42             mkdir -p /etc/os-net-config
43
44             # Create an os-net-config mapping file, note this defaults to
45             # /etc/os-net-config/mapping.yaml, so we use that name despite
46             # rendering the result as json
47             echo '$node_lookup' | python -c "
48             import json
49             import sys
50             import yaml
51             input = sys.stdin.readline() or '{}'
52             data = json.loads(input)
53             for node in data:
54               if any(x in '$eth_addr'.split(',') for x in data[node].values()):
55                 interface_mapping = {'interface_mapping': data[node]}
56                 with open('/etc/os-net-config/mapping.yaml', 'w') as f:
57                   yaml.safe_dump(interface_mapping, f, default_flow_style=False)
58                 break
59             "
60           params:
61             $node_lookup: {get_param: NetConfigDataLookup}
62
63 outputs:
64   OS::stack_id:
65     value: {get_resource: userdata}