Merge "Add retry to RHEL registration"
[apex-tripleo-heat-templates.git] / puppet / extraconfig / all_nodes / neutron-ml2-cisco-nexus-ucsm.yaml
1 heat_template_version: ocata
2
3 description: Configure hieradata for Network Cisco configuration
4
5 parameters:
6   # Parameters passed from the parent template
7   servers:
8     type: json
9
10   # extra parameters passed via parameter_defaults
11   NetworkUCSMIp:
12     type: string
13     description: Cisco UCSM IP
14     default: 127.0.0.1
15   NetworkUCSMUsername:
16     type: string
17     description: Cisco UCSM username
18     default: admin
19   NetworkUCSMPassword:
20     type: string
21     description: Cisco UCSM password
22     default: password
23   NetworkUCSMHostList:
24     type: string
25     description: >
26       Mac address to service profile mapping for UCSM-controlled hosts
27       The format is
28       '<host1-mac>:<profile>, <host2-mac>:<profile>, ...'
29     default: ''
30   NetworkUCSMSupportedPciDevs:
31     type: string
32     description: Cisco UCSM SR-IOV and VM-FEX vendors supported
33     default: ''
34   NetworkNexusConfig:
35     type: json
36     description: Nexus switch configuration
37     default: {}
38   NetworkNexusManagedPhysicalNetwork:
39     type: string
40     description: The name of the physical_network
41     default: ''
42   NetworkNexusVlanNamePrefix:
43     type: string
44     description: A short prefix to prepend to the VLAN name
45     default: 'q-'
46   NetworkNexusSviRoundRobin:
47     type: boolean
48     description: A flag to enable round robin scheduling
49     default: false
50   NetworkNexusProviderVlanNamePrefix:
51     type: string
52     description:  A short prefix to prepend to the VLAN name
53     default: 'p-'
54   NetworkNexusPersistentSwitchConfig:
55     type: string
56     description: To make Nexus device persistent
57     default: false
58   NetworkNexusSwitchHeartbeatTime:
59     type: number
60     description: >
61       Time interval to check the state of the Nexus device. The units of this
62       object are seconds.  Setting this object to a value of 0 disables the
63       replay feature.
64     default: 0
65   NetworkNexusSwitchReplayCount:
66     type: number
67     description: >
68       This configuration item is OBSOLETE.  The Nexus driver replay behavior
69       is to continue to attempt to connect to the down Nexus device with a
70       period equal to the heartbeat time interval.  This was previously the
71       Number of times to attempt config replay.
72     default: 3
73   NetworkNexusProviderVlanAutoCreate:
74     type: boolean
75     description: A flag whether to manage the creation and removal of VLANs
76     default: true
77   NetworkNexusProviderVlanAutoTrunk:
78     type: boolean
79     description: A flag whether to manage the trunk ports on the Nexus
80     default: true
81   NetworkNexusVxlanGlobalConfig:
82     type: boolean
83     description: A flag whether to manage the VXLAN global settings
84     default: true
85   NetworkNexusHostKeyChecks:
86     type: boolean
87     description: enable strict host key checks when connecting to Nexus switches
88     default: false
89   NetworkNexusVxlanVniRanges:
90     type: string
91     description: VXLAN Network IDs that are available for tenant network
92     default: ''
93   NetworkNexusVxlanMcastRanges:
94     type: string
95     description: Multicast groups for the VXLAN interface.
96     default: ''
97
98
99 resources:
100   # First we lay down the base configuration via the static hieradata mappings
101   NetworkCiscoConfig:
102     type: OS::Heat::StructuredConfig
103     properties:
104       group: os-apply-config
105       config:
106         hiera:
107           datafiles:
108             neutron_cisco_data:
109               mapped_data:
110                 neutron::plugins::ml2::cisco::ucsm::ucsm_ip: {get_input: UCSM_ip}
111                 neutron::plugins::ml2::cisco::ucsm::ucsm_username: {get_input: UCSM_username}
112                 neutron::plugins::ml2::cisco::ucsm::ucsm_password: {get_input: UCSM_password}
113                 neutron::plugins::ml2::cisco::ucsm::ucsm_host_list: {get_input: UCSM_host_list}
114                 neutron::plugins::ml2::cisco::ucsm::supported_pci_devs:  {get_input: UCSMSupportedPciDevs}
115                 neutron::plugins::ml2::cisco::nexus::nexus_config: {get_input: NexusConfig}
116                 neutron::plugins::ml2::cisco::nexus::managed_physical_network: {get_input: NexusManagedPhysicalNetwork}
117                 neutron::plugins::ml2::cisco::nexus::vlan_name_prefix: {get_input: NexusVlanNamePrefix}
118                 neutron::plugins::ml2::cisco::nexus::svi_round_robin: {get_input: NexusSviRoundRobin}
119                 neutron::plugins::ml2::cisco::nexus::provider_vlan_name_prefix: {get_input: NexusProviderVlanNamePrefix}
120                 neutron::plugins::ml2::cisco::nexus::persistent_switch_config: {get_input: NexusPersistentSwitchConfig}
121                 neutron::plugins::ml2::cisco::nexus::switch_heartbeat_time: {get_input: NexusSwitchHeartbeatTime}
122                 neutron::plugins::ml2::cisco::nexus::switch_replay_count: {get_input: NexusSwitchReplayCount}
123                 neutron::plugins::ml2::cisco::nexus::provider_vlan_auto_create: {get_input: NexusProviderVlanAutoCreate}
124                 neutron::plugins::ml2::cisco::nexus::provider_vlan_auto_trunk: {get_input: NexusProviderVlanAutoTrunk}
125                 neutron::plugins::ml2::cisco::nexus::vxlan_global_config: {get_input: NexusVxlanGlobalConfig}
126                 neutron::plugins::ml2::cisco::nexus::host_key_checks: {get_input: NexusHostKeyChecks}
127                 neutron::plugins::ml2::cisco::type_nexus_vxlan::vni_ranges: {get_input: NexusVxlanVniRanges}
128                 neutron::plugins::ml2::cisco::type_nexus_vxlan::mcast_ranges: {get_input: NexusVxlanMcastRanges}
129
130   NetworkCiscoDeployment:
131     type: OS::Heat::StructuredDeployments
132     properties:
133       name: NetworkCiscoDeployment
134       config: {get_resource: NetworkCiscoConfig}
135       servers:  {get_param: [servers, Controller]}
136       input_values:
137         UCSM_ip: {get_param: NetworkUCSMIp}
138         UCSM_username: {get_param: NetworkUCSMUsername}
139         UCSM_password: {get_param: NetworkUCSMPassword}
140         UCSM_host_list: {get_attr: [MappingToUCSMDeploymentsController, deploy_stdout]}
141         UCSMSupportedPciDevs: {get_param: NetworkUCSMSupportedPciDevs}
142         NexusConfig: {get_attr: [MappingToNexusDeploymentsController, deploy_stdout]}
143         NexusManagedPhysicalNetwork: {get_param: NetworkNexusManagedPhysicalNetwork}
144         NexusVlanNamePrefix: {get_param: NetworkNexusVlanNamePrefix}
145         NexusSviRoundRobin: {get_param: NetworkNexusSviRoundRobin}
146         NexusProviderVlanNamePrefix: {get_param: NetworkNexusProviderVlanNamePrefix}
147         NexusPersistentSwitchConfig: {get_param: NetworkNexusPersistentSwitchConfig}
148         NexusSwitchHeartbeatTime: {get_param: NetworkNexusSwitchHeartbeatTime}
149         NexusSwitchReplayCount: {get_param: NetworkNexusSwitchReplayCount}
150         NexusProviderVlanAutoCreate: {get_param: NetworkNexusProviderVlanAutoCreate}
151         NexusProviderVlanAutoTrunk: {get_param: NetworkNexusProviderVlanAutoTrunk}
152         NexusVxlanGlobalConfig: {get_param: NetworkNexusVxlanGlobalConfig}
153         NexusHostKeyChecks: {get_param: NetworkNexusHostKeyChecks}
154         NexusVxlanVniRanges: {get_param: NetworkNexusVxlanVniRanges}
155         NexusVxlanMcastRanges: {get_param: NetworkNexusVxlanMcastRanges}
156
157   # Now we collect the Mac->Hostname mappings for all nodes, which enables
158   # calculation of the neutron::plugins::ml2::cisco::nexus::nexus_config data
159   CollectMacConfig:
160     type: OS::Heat::SoftwareConfig
161     properties:
162       group: script
163       config: |
164         #!/bin/sh
165         MACS=$(ifconfig  | grep ether | awk '{print $2}' | tr "\n" " ")
166         HOST_FQDN=$(hostname -f)
167         if [ -z "$HOST_FQDN" ]; then
168           HOSTNAME=$(hostname -s)
169           # hardcoding the domain name to avoid DNS lookup dependency
170           # same type of hardcoding appears elsewhere
171           # --ie. controller-puppet.yaml
172           # FIXME_HOSTNAME_DOMAIN_HARDCODE
173           echo "$HOSTNAME.localdomain $MACS"
174         else
175           echo "$HOST_FQDN $MACS"
176         fi
177
178   CollectMacDeploymentsController:
179     type: OS::Heat::SoftwareDeployments
180     properties:
181       name: CollectMacDeploymentsController
182       servers:  {get_param: [servers, Controller]}
183       config: {get_resource: CollectMacConfig}
184       actions: ['CREATE'] # Only do this on CREATE
185
186   CollectMacDeploymentsCompute:
187     type: OS::Heat::SoftwareDeployments
188     properties:
189       name: CollectMacDeploymentsCompute
190       servers:  {get_param: [servers, Compute]}
191       config: {get_resource: CollectMacConfig}
192       actions: ['CREATE'] # Only do this on CREATE
193
194   CollectMacDeploymentsBlockStorage:
195     type: OS::Heat::SoftwareDeployments
196     properties:
197       name: CollectMacDeploymentsBlockStorage
198       servers:  {get_param: [servers, BlockStorage]}
199       config: {get_resource: CollectMacConfig}
200       actions: ['CREATE'] # Only do this on CREATE
201
202   CollectMacDeploymentsObjectStorage:
203     type: OS::Heat::SoftwareDeployments
204     properties:
205       name: CollectMacDeploymentsObjectStorage
206       servers:  {get_param: [servers, ObjectStorage]}
207       config: {get_resource: CollectMacConfig}
208       actions: ['CREATE'] # Only do this on CREATE
209
210   CollectMacDeploymentsCephStorage:
211     type: OS::Heat::SoftwareDeployments
212     properties:
213       name: CollectMacDeploymentsCephStorage
214       servers:  {get_param: [servers, CephStorage]}
215       config: {get_resource: CollectMacConfig}
216       actions: ['CREATE'] # Only do this on CREATE
217
218   # Now we calculate the additional nexus config based on the mappings
219   MappingToNexusConfig:
220     type: OS::Heat::SoftwareConfig
221     properties:
222       group: script
223       inputs:
224       - name: controller_mappings
225       - name: compute_mappings
226       - name: blockstorage_mappings
227       - name: objectstorage_mappings
228       - name: cephstorage_mappings
229       - name: nexus_config
230       config: |
231         #!/bin/python
232         import ast
233         import json
234         import os
235         from copy import deepcopy
236
237         mappings = ['controller_mappings',
238                     'compute_mappings',
239                     'blockstorage_mappings',
240                     'objectstorage_mappings',
241                     'cephstorage_mappings',
242                     'nexus_config']
243         mapdict_list = []
244         nexus = {}
245         for map_name in mappings:
246           f_name = '/root/' + map_name
247           map_data = os.getenv(map_name, "Nada")
248           with open(f_name, 'a') as f:
249             f.write(map_data)
250           if map_data is not "Nada":
251             if map_name is not 'nexus_config':
252               mapdict_list.append(ast.literal_eval(map_data))
253             else:
254               nexus = ast.literal_eval(map_data)
255
256         mac2host = {}
257         for mapdict in mapdict_list:
258           for (listnum, host2mac_list) in mapdict.iteritems():
259             vals = host2mac_list.rstrip().split()
260             for mac in vals[1:]:
261               mac2host[mac.lower()] = vals[0]
262
263         with open('/root/mac2host', 'a') as f:
264           f.write(str(mac2host))
265
266         # now we have mac to host, map host to switchport in hieradata
267         # nexus = ast.literal_eval(os.getenv('nexus_config', None))
268         nexus_cp = deepcopy(nexus)
269         for nexus_switch in nexus:
270           for (mac,swport) in nexus[nexus_switch]['servers'].iteritems():
271             lmac=mac.lower()
272             if lmac in mac2host:
273               hostname = mac2host[lmac]
274               # for puppet we need a unique title even at the 2nd key level
275               serv_key = nexus_switch + "::" + hostname
276               if serv_key in nexus_cp[nexus_switch]['servers']:
277                 nexus_cp[nexus_switch]['servers'][serv_key]['ports'] += ',' + swport['ports']
278               else:
279                 nexus_cp[nexus_switch]['servers'][serv_key] = swport
280                 nexus_cp[nexus_switch]['servers'][serv_key]['hostname'] = hostname
281             del nexus_cp[nexus_switch]['servers'][mac]
282         # Note this echo means you can view the data via heat deployment-show
283         print json.dumps(nexus_cp)
284
285   MappingToNexusDeploymentsController:
286     type: OS::Heat::SoftwareDeployment
287     properties:
288       name: MappingToNexusDeploymentsController
289       server:  {get_param: [servers, Controller, '0']}
290       config: {get_resource: MappingToNexusConfig}
291       input_values:
292         # FIXME(shardy): It'd be more convenient if we could join these
293         # items together but because the returned format is a map (not a list)
294         # we can't use list_join or str_replace.  Possible Heat TODO.
295         controller_mappings: {get_attr: [CollectMacDeploymentsController, deploy_stdouts]}
296         compute_mappings: {get_attr: [CollectMacDeploymentsCompute, deploy_stdouts]}
297         blockstorage_mappings: {get_attr: [CollectMacDeploymentsBlockStorage, deploy_stdouts]}
298         objectstorage_mappings: {get_attr: [CollectMacDeploymentsObjectStorage, deploy_stdouts]}
299         cephstorage_mappings: {get_attr: [CollectMacDeploymentsCephStorage, deploy_stdouts]}
300         nexus_config: {get_param: NetworkNexusConfig}
301       actions: ['CREATE'] # Only do this on CREATE
302
303   MappingToUCSMConfig:
304     type: OS::Heat::SoftwareConfig
305     properties:
306       group: script
307       inputs:
308        - name: ucsm_config
309       config: |
310         #!/bin/python
311         import ast
312         import os
313         with open('/root/mac2host', 'r') as f:
314           s=f.read()
315           m2h=ast.literal_eval(s)
316         ucs_config = os.getenv('ucsm_config', "Nada")
317         ucs_data = []
318         lines = ucs_config.split(',')
319         for line in lines:
320           entry=line.rsplit(":",1)
321           mac = entry[0].lower().strip()
322           if mac in m2h:
323             ucs_data.append(m2h[mac] + ":" + entry[1])
324
325         print ", ".join(ucs_data)
326
327
328   MappingToUCSMDeploymentsController:
329     type: OS::Heat::SoftwareDeployment
330     depends_on: MappingToNexusDeploymentsController
331     properties:
332       name: MappingToUCSMDeploymentsController
333       server:  {get_param: [servers, Controller, '0']}
334       config: {get_resource: MappingToUCSMConfig}
335       input_values:
336         ucsm_config: {get_param: NetworkUCSMHostList}
337       actions: ['CREATE'] # Only do this on CREATE