1 heat_template_version: pike
4 Configure os-net-config mappings for specific nodes
5 Your environment file needs to look like:
9 nic1: "00:c8:7c:e6:f0:2e"
11 nic1: "00:18:7d:99:0c:b6"
13 dmiString: 'system-uuid'
14 id: 'A8C85861-1B16-4803-8689-AFC62984F8F6'
18 dmiString: "system-product-name"
25 dmiString: "system-product-name"
30 This will result in the first node* entry where either:
31 a) a mac matches a local device
32 or b) a DMI String matches the specified id
33 being written as a mapping file for os-net-config in
34 /etc/os-net-config/mapping.yaml
37 # Note this requires a liberty heat or newer in the undercloud due to
38 # the 2015-10-15 (which is required to enable str_replace serializing
39 # the json parameter to json, another approch with a string parameter
40 # will be required for older heat versions)
44 description: per-node configuration map
48 type: OS::Heat::MultipartMime
51 - config: {get_resource: OsNetConfigMappings}
54 type: OS::Heat::SoftwareConfig
61 eth_addr=$(cat /sys/class/net/*/address | tr '\n' ',')
62 mkdir -p /etc/os-net-config
64 # Create an os-net-config mapping file, note this defaults to
65 # /etc/os-net-config/mapping.yaml, so we use that name despite
66 # rendering the result as json
67 echo '$node_lookup' | python -c "
71 from subprocess import PIPE, Popen
74 def write_mapping_file(interface_mapping):
75 with open('/etc/os-net-config/mapping.yaml', 'w') as f:
76 yaml.safe_dump(interface_mapping, f, default_flow_style=False)
78 input = sys.stdin.readline() or '{}'
79 data = json.loads(input)
81 interface_mapping = {'interface_mapping':
82 copy.deepcopy(data[node])}
83 if 'dmiString' in interface_mapping['interface_mapping']:
84 del interface_mapping['interface_mapping']['dmiString']
85 if 'id' in interface_mapping['interface_mapping']:
86 del interface_mapping['interface_mapping']['id']
87 # Match on mac addresses first
88 if any(x in '$eth_addr'.split(',') for x in data[node].values()):
89 write_mapping_file(interface_mapping)
91 # If data contain dmiString and id keys, try to match node(group)
92 if 'dmiString' in data[node] and 'id' in data[node]:
93 ps = Popen([ 'dmidecode',
94 '--string', data[node].get('dmiString') ],
96 out, err = ps.communicate()
97 if data[node].get('id') == out.rstrip():
98 write_mapping_file(interface_mapping)
102 $node_lookup: {get_param: NetConfigDataLookup}
106 value: {get_resource: userdata}