1f6ee81f979e57053b73556b25ab4c569eea906a
[ta/cm-plugins.git] / inventoryhandlers / openstack / openstackinventory.py
1 # Copyright 2019 Nokia
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import json
16 import socket
17 from jinja2 import Environment
18 from cmframework.apis import cmansibleinventoryconfig
19 from cmframework.apis import cmerror
20 from cmdatahandlers.api import utils
21 from cmdatahandlers.api import configerror
22 from serviceprofiles import profiles
23
24 json_text_setup = """
25 {
26     "_meta": {
27         "hostvars": {
28             "{{ installation_controller }}": {
29                 "ansible_connection": "local",
30                 "aio_hostname": "{{ installation_controller }}",
31                 "bootstrap_host_loopback_cinder": "no",
32                 "bootstrap_host_loopback_swift": "no",
33                 "bootstrap_host_loopback_nova": "no",
34                 "bootstrap_host_data_disk_min_size": 30,
35                 "bootstrap_env_file": "{{ '{{' }} bootstrap_host_aio_config_path {{ '}}' }}/env.d/baremetal.yml",
36                 "user_secrets_overrides": {
37                     "keystone_auth_admin_password": "{{ general.openstack_password }}"
38                 },
39                 "sudo_user": "{{ general.admin }}",
40                 "sudo_user_password": "{{ general.password }}"
41             }
42         }
43     }
44 }
45 """
46 json_text = """
47 {
48     "_meta": {
49         "hostvars": {
50             {% set tenant_network = networkingconf.get_cloud_tenant_network_name() %}
51             {% for host in hosts %}
52             "{{ host.name }}": {
53                 "hostname": "{{ host.name }}",
54                 "management_bridge": "{{ hostsconf.get_host_network_ip_holding_interface(host.name, "infra_internal") }}",
55                 "is_metal": true,
56                 "container_address": "{{ host.get_network_ip("infra_internal") }}",
57                 "container_name": "{{ host.name }}",
58                 "container_networks": {
59                     "management_address": {
60                         "address": "{{ host.get_network_ip("infra_internal") }}",
61                         "bridge": "{{ host.get_network_ip_holding_interface("infra_internal") }}",
62                         "netmask": null,
63                         "type": "veth"
64                     },
65                     {% if tenant_network in hostsconf.get_host_networks(host.name) %}
66                     "tunnel_address": {
67                         "address": "{{ host.get_network_ip(tenant_network) }}",
68                         "bridge": "{{ host.get_network_ip_holding_interface(tenant_network) }}",
69                         "netmask": "null",
70                         "type": "veth"
71                     },
72                     {% endif %}
73                     "storage_address": {
74                         "address": "{{ host.get_network_ip("infra_internal") }}",
75                         "bridge": "{{ host.get_network_ip_holding_interface("infra_internal") }}",
76                         "netmask": "null",
77                         "type": "veth"
78                     }
79                 },
80                 {% if host.is_performance %}
81                 "heat_api_threads_max" : {{ host.os_max_threads }},
82                 "nova_api_threads_max" : {{ host.os_max_threads }},
83                 "cinder_osapi_volume_workers_max" : {{ host.os_max_threads }},
84                 "glance_api_threads_max" : {{ host.os_max_threads }},
85                 "neutron_api_threads_max" : {{ host.os_max_threads }},
86                 {% endif %}
87                 "physical_host": "{{ host.name }}",
88                 {% if host.is_controller %}
89                 "physical_host_group": "orchestration_hosts"
90                 {% else %}
91                 "physical_host_group": "compute_hosts"
92                 {% endif %}
93             } {% if not loop.last %},{% endif %}
94             {% endfor %}
95         }
96     },
97     "all": {
98         "vars": {
99             "installation_controller": "{{ installation_controller }}",
100             "is_metal": true,
101             "haproxy_glance_api_nodes": ["glance-api"],
102             "nova_vncserver_listen": "0.0.0.0",
103             "nova_novncproxy_base_url": "{% raw %}{{ nova_novncproxy_base_uri }}/vnc_auto.html{% endraw %}",
104             "properties": {
105                  "is_metal": true
106              },
107             {% if not virtual_environment %}
108             "virtual_env": false,
109             {% else %}
110             "virtual_env": true,
111             {% endif %}
112             "container_cidr": "{{ infra_mgmt.cidr }}",
113             "haproxy_whitelist_networks": [ {% for cidr in infra_mgmt.cidrs %}"{{ cidr }}"{%if not loop.last %},{% endif %}{% endfor %} ],
114             {% if config_phase == 'postconfig' %}
115             "external_lb_vip_address": "{{ has.haproxy.external_vip }}",
116             "internal_lb_vip_address": "{{ has.haproxy.internal_vip }}",
117             "haproxy_keepalived_external_vip_cird": "{{ has.haproxy.external_vip }}/32",
118             "haproxy_keepalived_internal_vip_cidr": "{{ has.haproxy.external_vip }}/32",
119             {% else %}
120             "external_lb_vip_address": "{{ infra_external.ip }}",
121             "internal_lb_vip_address": "{{ infra_mgmt.ip }}",
122             "haproxy_keepalived_external_vip_cird": "{{ infra_external.ip }}/32",
123             "haproxy_keepalived_internal_vip_cidr": "{{ infra_external.ip }}/32",
124             {% endif %}
125             {%if config_phase == 'postconfig' %}
126             "ironic_standalone_auth_strategy": "keystone",
127             "galera_ignore_cluster_state": false,
128             {% else %}
129             "galera_ignore_cluster_state": true,
130             {% endif %}
131             "keepalived_ping_address": "{{ infra_external.gateway }}",
132             "haproxy_keepalived_external_interface": "{{ infra_external.interface }}",
133             "haproxy_keepalived_internal_interface": "{{ infra_mgmt.interface }}",
134             "management_bridge": "{{ infra_mgmt.interface }}",
135             "ntp_servers": [ {% for server in general.ntp_servers %}"{{ server }}"{%if not loop.last %},{% endif %}{% endfor %} ],
136             "openrc_file_dest": "/home/{{ general.admin }}/openrc",
137             "openrc_file_owner": "{{ general.admin }}",
138             "openrc_file_group": "{{ general.admin }}",
139             "openrc_openstack_client_config_dir_dest": "/home/{{ general.admin }}/.config/openstack",
140             "openrc_openstack_client_config_dir_owner": "{{ general.admin }}",
141             "openrc_openstack_client_config_dir_group": "{{ general.admin }}",
142             "openrc_clouds_yml_file_dest": "/home/{{ general.admin }}/.config/openstack/clouds.yaml",
143             "openrc_clouds_yml_file_owner": "{{ general.admin }}",
144             "openrc_clouds_yml_file_group": "{{ general.admin }}",
145             "horizon_images_upload_mode": "legacy",
146             "horizon_time_zone": "{{ general.zone }}",
147             "horizon_disable_password_reveal": true,
148             "nova_cpu_allocation_ratio": "1.0",
149             "nova_resume_guests_state_on_host_boot": "True",
150             "nova_scheduler_default_filters": "RetryFilter,AvailabilityZoneFilter,RamFilter,ComputeFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter,ServerGroupAntiAffinityFilter,ServerGroupAffinityFilter,AggregateCoreFilter,AggregateDiskFilter,NUMATopologyFilter,AggregateInstanceExtraSpecsFilter,PciPassthroughFilter",
151             "cinder_volume_clear": "none",
152             "haproxy_ssl_pem": "/etc/ssl/private/certificate.pem",
153             "ironic_default_network_interface": "noop",
154             "restful_service_port": "61200",
155             "auth_server_service_address": "localhost",
156             "auth_server_service_port": "62200",
157             "aaa_galera_address": "{{ has.haproxy.internal_vip }}",
158             {% if not virtual_environment %}
159             "nova_cpu_mode": "host-passthrough",
160             {% else %}
161             "nova_cpu_mode": "host-model",
162             {% endif %}
163             {% if computes|length == 1 %}
164             "single_compute" : true,
165             {% else %}
166             "single_compute" : false,
167             {% endif %}
168             {% if management_nodes|length == 1 %}
169             "single_management" : true
170             {% else %}
171             "single_management" : false
172             {% endif %}
173         }
174     },
175     "all_containers": {
176         "children": [
177             "unbound_containers",
178             "ceph-osd_containers",
179             "orchestration_containers",
180             "operator_containers",
181             "memcaching_containers",
182             "metering-infra_containers",
183             "ironic-infra_containers",
184             "ceph-mon_containers",
185             "storage_containers",
186             "ironic-server_containers",
187             "mq_containers",
188             "shared-infra_containers",
189             "compute_containers",
190             "storage-infra_containers",
191             "haproxy_containers",
192             "key-manager_containers",
193             "metering-alarm_containers",
194             "network_containers",
195             "os-infra_containers",
196             "image_containers",
197             "compute-infra_containers",
198             "log_containers",
199             "ironic-compute_containers",
200             "metering-compute_containers",
201             "identity_containers",
202             "dashboard_containers",
203             "dnsaas_containers",
204             "database_containers",
205             "metrics_containers",
206             "repo-infra_containers"
207         ],
208         "hosts": []
209     },
210     "aodh_alarm_evaluator": {
211         "children": [],
212         "hosts": [{% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %}]
213     },
214     "aodh_alarm_notifier": {
215         "children": [],
216         "hosts": [{% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %}]
217     },
218     "aodh_all": {
219         "children": [
220             "aodh_alarm_notifier",
221             "aodh_api",
222             "aodh_alarm_evaluator",
223             "aodh_listener"
224         ],
225         "hosts": []
226     },
227     "aodh_api": {
228         "children": [],
229         "hosts": [{% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %}]
230     },
231     "aodh_container": {
232         "hosts": []
233     },
234     "aodh_listener": {
235         "children": [],
236         "hosts": [{% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %}]
237     },
238     "barbican_all": {
239         "children": [
240             "barbican_api"
241         ],
242         "hosts": []
243     },
244     "barbican_api": {
245         "children": [],
246         "hosts": []
247     },
248     "barbican_container": {
249         "hosts": []
250     },
251     "openstack_nodes": {
252         "children": [ "controller", "compute", "storage" ]
253     },
254     "caas_nodes": {
255         "children": [ "caas_master", "caas_worker" ]
256     },
257     "baremetal-infra_hosts": {
258         "hosts": [ {% if not vnf_embedded_deployment %} "{{ installation_controller }}" {% endif %}]
259     },
260     "baremetal-nodes": {
261         "hosts": [ {% if not vnf_embedded_deployment %}{% for host in hosts %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %}{% endif %} ]
262     },
263     "baremetal_management_nodes": {
264         "hosts": [ {% for host in management_nodes %}{% if not vnf_embedded_deployment %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
265     },
266     "ceilometer_agent_central": {
267         "children": [],
268         "hosts": []
269     },
270     "ceilometer_agent_compute": {
271         "children": [],
272         "hosts": []
273     },
274     "ceilometer_agent_notification": {
275         "children": [],
276         "hosts": []
277     },
278     "ceilometer_all": {
279         "children": [
280             "ceilometer_agent_central",
281             "ceilometer_agent_notification",
282             "ceilometer_api",
283             "ceilometer_collector",
284             "ceilometer_agent_compute"
285         ],
286         "hosts": []
287     },
288     "ceilometer_api": {
289         "children": [],
290         "hosts": []
291     },
292     "ceilometer_api_container": {
293         "hosts": []
294     },
295     "ceilometer_collector": {
296         "children": [],
297         "hosts": []
298     },
299     "ceilometer_collector_container": {
300         "hosts": []
301     },
302     {% if storagebackend != 'ceph' %}
303     "ceph-mon": {
304         "children": [],
305         "hosts": []
306     },
307     "ceph-mon_hosts": {
308         "children": [],
309         "hosts": []
310     },
311     "ceph-osd": {
312         "children": [],
313         "hosts": []
314     },
315     "ceph-osd_hosts": {
316         "children": [],
317         "hosts": []
318     },
319     "ceph-mgr": {
320         "children": [],
321         "hosts": []
322     },
323     {% endif %}
324     "ceph-mon_container": {
325         "hosts": []
326     },
327     "ceph-mon_containers": {
328         "children": [],
329         "hosts": []
330     },
331     "ceph-osd_container": {
332         "hosts": []
333     },
334     "ceph-osd_containers": {
335         "children": [],
336         "hosts": []
337     },
338     "ceph_all": {
339         "children": [
340             "ceph-mon",
341             "ceph-osd",
342             "ceph-mgr"
343         ],
344         "hosts": []
345     },
346     "cinder_all": {
347         "children": [
348             "cinder_api",
349             "cinder_backup",
350             "cinder_volume",
351             "cinder_scheduler"
352         ],
353         "hosts": []
354     },
355     "cinder_api": {
356         "children": [],
357         {% if storagebackend == 'ceph' %}
358         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
359         {% else %}
360         "hosts": [ {% if not caas_only_deployment %}"{{ installation_controller }}"{% endif %} ]
361         {% endif %}
362     },
363     "cinder_api_container": {
364         "hosts": []
365     },
366     "cinder_backup": {
367         "children": [],
368         {% if storagebackend == 'ceph' %}
369         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
370         {% else %}
371         "hosts": [ {% if not caas_only_deployment %}"{{ installation_controller }}"{% endif %} ]
372         {% endif %}
373     },
374     "cinder_scheduler": {
375         "children": [],
376         {% if storagebackend == 'ceph' %}
377         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
378         {% else %}
379         "hosts": [ {% if not caas_only_deployment %}"{{ installation_controller }}"{% endif %} ]
380         {% endif %}
381     },
382     "cinder_scheduler_container": {
383         "hosts": []
384     },
385     "cinder_volume": {
386         "children": [],
387         {% if storagebackend == 'ceph' %}
388         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
389         {% else %}
390         "hosts": [ {% if not caas_only_deployment %}"{{ installation_controller }}"{% endif %} ]
391         {% endif %}
392     },
393     "cinder_volumes_container": {
394         "hosts": []
395     },
396     "compute-infra_all": {
397         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
398     },
399     "compute-infra_containers": {
400         "children": [ {% for host in containers %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %} ],
401         "hosts": []
402     },
403     "compute-infra_hosts": {
404         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
405     },
406     "compute_all": {
407         "hosts": [ {% for host in computes %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
408     },
409     "compute_containers": {
410         "children": [ {% for host in computes %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %} ],
411         "hosts": []
412     },
413     "compute_hosts": {
414         "hosts": [ {% for host in computes %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
415     },
416     "dashboard_all": {
417         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
418     },
419     "dashboard_containers": {
420         "children": [ {% for host in controllers %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %} ],
421         "hosts": []
422     },
423     "dashboard_hosts": {
424         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
425     },
426     "database_containers": {
427         "children": [],
428         "hosts": []
429     },
430     "database_hosts": {
431         "children": [],
432         "hosts": []
433     },
434     "designate_all": {
435         "children": [
436             "designate_producer",
437             "designate_mdns",
438             "designate_api",
439             "designate_worker",
440             "designate_central",
441             "designate_sink"
442         ],
443         "hosts": []
444     },
445     "designate_api": {
446         "children": [],
447         "hosts": []
448     },
449     "designate_central": {
450         "children": [],
451         "hosts": []
452     },
453     "designate_container": {
454         "hosts": []
455     },
456     "designate_mdns": {
457         "children": [],
458         "hosts": []
459     },
460     "designate_producer": {
461         "children": [],
462         "hosts": []
463     },
464     "designate_sink": {
465         "children": [],
466         "hosts": []
467     },
468     "designate_worker": {
469         "children": [],
470         "hosts": []
471     },
472     "dnsaas_containers": {
473         "children": [],
474         "hosts": []
475     },
476     "dnsaas_hosts": {
477         "children": [],
478         "hosts": []
479     },
480     "galera": {
481         "children": [],
482         "hosts": [ {% for host in management_nodes %}{% if not vnf_embedded_deployment %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
483     },
484     "galera_all": {
485         "children": [
486             "galera"
487         ],
488         "hosts": []
489     },
490     "galera_container": {
491         "hosts": []
492     },
493     "glance_all": {
494         "children": [
495             "glance_registry",
496             "glance_api"
497         ],
498         "hosts": []
499     },
500     "glance_api": {
501         "children": [],
502         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
503     },
504     "glance_container": {
505         "hosts": []
506     },
507     "glance_registry": {
508         "children": [],
509         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
510     },
511     "gnocchi_all": {
512         "children": [
513             "gnocchi_api",
514             "gnocchi_metricd"
515         ],
516         "hosts": []
517     },
518     "gnocchi_api": {
519         "children": [],
520         "hosts": []
521     },
522     "gnocchi_container": {
523         "hosts": []
524     },
525     "gnocchi_metricd": {
526         "children": [],
527         "hosts": []
528     },
529     {% if config_phase != 'bootstrapping' %}
530     "haproxy": {
531         "children": [],
532         "hosts": [ {% if not vnf_embedded_deployment %}{% for host in management_nodes %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %}{% endif %} ]
533     },
534     "haproxy_all": {
535         "children": [
536             "haproxy"
537         ],
538         "hosts": [ {% if not vnf_embedded_deployment %}{% for host in management_nodes %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %}{% endif %} ]
539     },
540     "haproxy_container": {
541         "hosts": []
542     },
543     "haproxy_containers": {
544         "children": [ {% if not vnf_embedded_deployment %}{% for host in management_nodes %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %}{% endif %} ],
545         "hosts": []
546     },
547     "haproxy_hosts": {
548         "hosts": [ {% if not vnf_embedded_deployment %}{% for host in management_nodes %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %}{% endif %} ]
549     },
550     {% endif %}
551     "heat_all": {
552         "children": [
553             "heat_api",
554             "heat_engine",
555             "heat_api_cloudwatch",
556             "heat_api_cfn"
557         ],
558         "hosts": []
559     },
560     "heat_api": {
561         "children": [],
562         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
563     },
564     "heat_api_cfn": {
565         "children": [],
566         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
567     },
568     "heat_api_cloudwatch": {
569         "children": [],
570         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
571     },
572     "heat_apis_container": {
573         "hosts": []
574     },
575     "heat_engine": {
576         "children": [],
577         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
578     },
579     "heat_engine_container": {
580         "hosts": []
581     },
582     "horizon": {
583         "children": [],
584         "hosts": [ {% if not vnf_embedded_deployment %}{% for host in management_nodes %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %}{% endif %} ]
585     },
586     "horizon_all": {
587         "children": [
588             "horizon"
589         ],
590         "hosts": []
591     },
592     "horizon_container": {
593         "hosts": []
594     },
595     "hosts": {
596         "children": [
597             "memcaching_hosts",
598             "metering-compute_hosts",
599             "image_hosts",
600             "shared-infra_hosts",
601             "storage_hosts",
602             "metering-infra_hosts",
603             "os-infra_hosts",
604             "ironic-server_hosts",
605             "key-manager_hosts",
606             "ceph-osd_hosts",
607             "dnsaas_hosts",
608             "network_hosts",
609             "haproxy_hosts",
610             "mq_hosts",
611             "database_hosts",
612             "ironic-compute_hosts",
613             "metering-alarm_hosts",
614             "log_hosts",
615             "ceph-mon_hosts",
616             "compute_hosts",
617             "orchestration_hosts",
618             "compute-infra_hosts",
619             "identity_hosts",
620             "unbound_hosts",
621             "ironic-infra_hosts",
622             "metrics_hosts",
623             "dashboard_hosts",
624             "storage-infra_hosts",
625             "operator_hosts",
626             "repo-infra_hosts"
627         ],
628         "hosts": []
629     },
630     "identity_all": {
631         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
632     },
633     "identity_containers": {
634         "children": [ {% for host in controllers %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %} ],
635         "hosts": []
636     },
637     "identity_hosts": {
638         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
639     },
640     "image_all": {
641         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
642     },
643     "image_containers": {
644         "children": [ {% for host in controllers %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %} ],
645         "hosts": []
646     },
647     "image_hosts": {
648         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
649     },
650     "installation_controller": {
651         "hosts": [ "{{ installation_controller }}" ]
652     },
653     "ironic-compute_all": {
654         "hosts": []
655     },
656     "ironic-compute_containers": {
657         "children": [],
658         "hosts": []
659     },
660     "ironic-compute_hosts": {
661         "hosts": []
662     },
663     "ironic-infra_all": {
664         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
665     },
666     "ironic-infra_containers": {
667         "children": [ {% for host in controllers %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %} ],
668         "hosts": []
669     },
670     "ironic-infra_hosts": {
671         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
672     },
673     "ironic-server_containers": {
674         "children": [],
675         "hosts": []
676     },
677     "ironic-server_hosts": {
678         "children": [],
679         "hosts": []
680     },
681     "ironic_all": {
682         "children": [
683             "ironic_conductor",
684             "ironic_api"
685         ],
686         "hosts": []
687     },
688     "ironic_api": {
689         "children": [],
690         "hosts": [ {% for host in management_nodes %}{% if not vnf_embedded_deployment %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
691     },
692     "ironic_api_container": {
693         "hosts": []
694     },
695     "ironic_compute": {
696         "children": [],
697         "hosts": []
698     },
699     "ironic_compute_container": {
700         "hosts": []
701     },
702     "ironic_conductor": {
703         "children": [],
704         "hosts": [ {% for host in management_nodes %}{% if not vnf_embedded_deployment %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
705     },
706     "ironic_conductor_container": {
707         "hosts": []
708     },
709     "ironic_server": {
710         "children": [],
711         "hosts": []
712     },
713     "ironic_server_container": {
714         "hosts": []
715     },
716     "ironic_servers": {
717         "children": [
718             "ironic_server"
719         ],
720         "hosts": []
721     },
722     "key-manager_containers": {
723         "children": [],
724         "hosts": []
725     },
726     "key-manager_hosts": {
727         "children": [],
728         "hosts": []
729     },
730     "keystone": {
731         "children": [],
732         "hosts": [ {% for host in management_nodes %}{% if not vnf_embedded_deployment %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
733     },
734     "keystone_all": {
735         "children": [
736             "keystone"
737         ],
738         "hosts": []
739     },
740     "keystone_container": {
741         "hosts": []
742     },
743     "log_containers": {
744         "children": [],
745         "hosts": []
746     },
747     "log_hosts": {
748         "children": [],
749         "hosts": []
750     },
751     "lxc_hosts": {
752         "hosts": [ {% for host in hosts %}{% if not vnf_embedded_deployment %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
753     },
754     "memcached": {
755         "children": [],
756         "hosts": [ {% for host in management_nodes %}{% if not vnf_embedded_deployment %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
757     },
758     "memcached_all": {
759         "children": [
760             "memcached"
761         ],
762         "hosts": []
763     },
764     "memcached_container": {
765         "hosts": []
766     },
767     "memcaching_containers": {
768         "children": [],
769         "hosts": []
770     },
771     "memcaching_hosts": {
772         "children": [],
773         "hosts": []
774     },
775     "metering-alarm_containers": {
776         "children": [],
777         "hosts": []
778     },
779     "metering-alarm_hosts": {
780         "children": [],
781         "hosts": []
782     },
783     "metering-compute_container": {
784         "hosts": []
785     },
786     "metering-compute_containers": {
787         "children": [],
788         "hosts": []
789     },
790     "metering-compute_hosts": {
791         "children": [],
792         "hosts": []
793     },
794     "metering-infra_containers": {
795         "children": [],
796         "hosts": []
797     },
798     "metering-infra_hosts": {
799         "children": [],
800         "hosts": []
801     },
802     "metrics_containers": {
803         "children": [],
804         "hosts": []
805     },
806     "metrics_hosts": {
807         "children": [],
808         "hosts": []
809     },
810     "mq_containers": {
811         "children": [],
812         "hosts": []
813     },
814     "mq_hosts": {
815         "children": [],
816         "hosts": []
817     },
818     "network_all": {
819         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
820     },
821     "network_containers": {
822         "children": [ {% for host in controllers %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %} ],
823         "hosts": []
824     },
825     "network_hosts": {
826         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
827     },
828     "neutron_agent": {
829         "children": [],
830         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
831     },
832     "neutron_agents_container": {
833         "hosts": []
834     },
835     "neutron_all": {
836         "children": [
837             "neutron_agent",
838             "neutron_metadata_agent",
839             "neutron_linuxbridge_agent",
840             "neutron_bgp_dragent",
841             "neutron_dhcp_agent",
842             "neutron_lbaas_agent",
843             "neutron_l3_agent",
844             "neutron_metering_agent",
845             "neutron_server",
846             "neutron_sriov_nic_agent",
847             "neutron_openvswitch_agent"
848         ],
849         "hosts": []
850     },
851     "neutron_bgp_dragent": {
852         "children": [],
853         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
854     },
855     "neutron_dhcp_agent": {
856         "children": [],
857         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
858     },
859     "neutron_l3_agent": {
860         "children": [],
861         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
862     },
863     "neutron_lbaas_agent": {
864         "children": [],
865         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
866     },
867     "neutron_linuxbridge_agent": {
868         "children": [],
869         "hosts": [ {% for host in neutron_agent_hosts %}{% if not caas_only_deployment %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
870     },
871     "neutron_metadata_agent": {
872         "children": [],
873         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
874     },
875     "neutron_metering_agent": {
876         "children": [],
877         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
878     },
879     "neutron_openvswitch_agent": {
880         "children": [],
881         "hosts": [ {% for host in neutron_agent_hosts %}{% if not caas_only_deployment %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
882     },
883     "neutron_server": {
884         "children": [],
885         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
886     },
887     "neutron_server_container": {
888         "hosts": []
889     },
890     "neutron_sriov_nic_agent": {
891         "children": [],
892         "hosts": [ {% for host in computes %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
893     },
894     "nova_all": {
895         "children": [
896             "nova_console",
897             "nova_scheduler",
898             "ironic_compute",
899             "nova_api_placement",
900             "nova_api_metadata",
901             "nova_api_os_compute",
902             "nova_conductor",
903             "nova_compute"
904         ],
905         "hosts": []
906     },
907     "nova_api_metadata": {
908         "children": [],
909         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
910     },
911     "nova_api_metadata_container": {
912         "hosts": []
913     },
914     "nova_api_os_compute": {
915         "children": [],
916         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
917     },
918     "nova_api_os_compute_container": {
919         "hosts": []
920     },
921     "nova_api_placement": {
922         "children": [],
923         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
924     },
925     "nova_api_placement_container": {
926         "hosts": []
927     },
928     "nova_compute": {
929         "children": [],
930         "hosts": [ {% for host in computes %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
931     },
932     "nova_compute_container": {
933         "hosts": []
934     },
935     "nova_conductor": {
936         "children": [],
937         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
938     },
939     "nova_conductor_container": {
940         "hosts": []
941     },
942     "nova_console": {
943         "children": [],
944         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
945     },
946     "nova_console_container": {
947         "hosts": []
948     },
949     "nova_scheduler": {
950         "children": [],
951         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
952     },
953     "nova_scheduler_container": {
954         "hosts": []
955     },
956     "operator_containers": {
957         "children": [],
958         "hosts": []
959     },
960     "operator_hosts": {
961         "children": [],
962         "hosts": []
963     },
964     "orchestration_all": {
965         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
966     },
967     "orchestration_containers": {
968         "children": [ {% for host in controllers %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %} ],
969         "hosts": []
970     },
971     "orchestration_hosts": {
972         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
973     },
974     "os-infra_containers": {
975         "children": [],
976         "hosts": []
977     },
978     "os-infra_hosts": {
979         "children": [],
980         "hosts": []
981     },
982     "pkg_repo": {
983         "children": [],
984         "hosts": []
985     },
986     "rabbit_mq_container": {
987         "hosts": []
988     },
989     "rabbitmq": {
990         "children": [],
991         "hosts": [ {% for host in management_nodes %}{% if not vnf_embedded_deployment %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
992     },
993     "rabbitmq_all": {
994         "children": [
995             "rabbitmq"
996         ],
997         "hosts": []
998     },
999     "repo-infra_containers": {
1000         "children": [],
1001         "hosts": []
1002     },
1003     "repo-infra_hosts": {
1004         "children": [],
1005         "hosts": []
1006     },
1007     "repo_all": {
1008         "children": [
1009             "pkg_repo"
1010         ],
1011         "hosts": []
1012     },
1013     "repo_container": {
1014         "hosts": []
1015     },
1016     "rsyslog": {
1017         "children": [],
1018         "hosts": []
1019     },
1020     "rsyslog_all": {
1021         "children": [
1022             "rsyslog"
1023         ],
1024         "hosts": []
1025     },
1026     "rsyslog_container": {
1027         "hosts": []
1028     },
1029     "shared-infra_hosts":
1030     {
1031         "hosts": [ {% if not vnf_embedded_deployment %}{% for host in management_nodes %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %}{% endif %} ]
1032     },
1033     "storage-infra_all": {
1034         "hosts": [ {% for host in storages %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
1035     },
1036     "storage-infra_containers": {
1037         "children": [ {% for host in storages %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %} ],
1038         "hosts": []
1039     },
1040     "storage-infra_hosts": {
1041         "hosts": [ {% for host in storages %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
1042     },
1043     "storage_all": {
1044         "hosts": [ {% for host in storages %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
1045     },
1046     "storage_containers": {
1047         "children": [ {% for host in storages %}"{{ host.name }}-host_containers"{% if not loop.last %},{% endif %}{% endfor %} ],
1048         "hosts": []
1049     },
1050     "storage_hosts": {
1051         "hosts": [ {% for host in storages %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
1052     },
1053     "unbound": {
1054         "children": [],
1055         "hosts": []
1056     },
1057     "unbound_all": {
1058         "children": [
1059             "unbound"
1060         ],
1061         "hosts": []
1062     },
1063     "unbound_container": {
1064         "hosts": []
1065     },
1066     "unbound_containers": {
1067         "children": [],
1068         "hosts": []
1069     },
1070     "unbound_hosts": {
1071         "children": [],
1072         "hosts": []
1073     },
1074     "utility": {
1075         "children": [],
1076         "hosts": [ {% for host in controllers %}"{{ host.name }}"{% if not loop.last %},{% endif %}{% endfor %} ]
1077     },
1078     "utility_all": {
1079         "children": [
1080             "utility"
1081         ],
1082         "hosts": []
1083     },
1084     "utility_container": {
1085         "hosts": []
1086     },
1087     "vnf-nodes": {
1088         "hosts": [ {% for host in hosts %}{% if vnf_embedded_deployment %} "{{ host.name }}"{% if not loop.last %},{% endif %}{% endif %}{% endfor %} ]
1089     }
1090 }
1091 """
1092
1093 class General:
1094     def __init__(self):
1095         self.dns_servers = []
1096         self.ntp_servers = []
1097         self.zone = None
1098         self.admin = None
1099         self.password = None
1100         self.openstack_password = None
1101
1102 class Network:
1103     def __init__(self):
1104         self.name = None
1105         self.cidr = None
1106         self.cidrs = set()
1107         self.vlan = None
1108         self.gateway = None
1109
1110 class HostNetwork:
1111     def __init__(self):
1112         self.network = None
1113         self.interface = None
1114         self.ip_holding_interface = None
1115         self.is_bonding = False
1116         self.linux_bonding_options = None
1117         self.members = []
1118         self.ip = None
1119
1120 class ProviderNetwork:
1121     def __init__(self):
1122         self.cidr = None
1123         self.cidrs = None
1124         self.interface = None
1125         self.ip = None
1126         self.gateway = None
1127
1128 class Host:
1129     def __init__(self):
1130         self.name = None
1131         self.is_controller = False
1132         self.is_caas_master = False
1133         self.is_compute = False
1134         self.is_storage = False
1135         self.is_management = False
1136         self.networks = []
1137         self.hwmgmt_address = None
1138         self.hwmgmt_password = None
1139         self.hwmgmt_user = None
1140         self.mgmt_mac = None
1141         self.is_performance = False
1142         self.os_max_threads = 16
1143
1144
1145     def get_network_ip(self, networkname):
1146         for network in self.networks:
1147             if network.network.name == networkname:
1148                 return network.ip.split('/')[0]
1149
1150     def get_network_ip_holding_interface(self, networkname):
1151         for network in self.networks:
1152             if network.network.name == networkname:
1153                 return network.ip_holding_interface
1154
1155
1156 class HAProxy:
1157     def __init__(self):
1158         self.internal_vip = None
1159         self.external_vip = None
1160
1161 class HAS:
1162     def __init__(self):
1163         self.haproxy = HAProxy()
1164
1165 class openstackinventory(cmansibleinventoryconfig.CMAnsibleInventoryConfigPlugin):
1166     def __init__(self, confman, inventory, ownhost):
1167         super(openstackinventory, self).__init__(confman, inventory, ownhost)
1168         self.networks = []
1169         self.hosts = []
1170         self.controllers = []
1171         self.managements = []
1172         self.caas_masters = []
1173         self.computes = []
1174         self.storages = []
1175         self.neutron_agent_hosts = set()
1176         self.has = HAS()
1177         self.general = General()
1178         self._init_jinja_environment()
1179         self.orig_inventory = inventory.copy()
1180
1181
1182     def handle_bootstrapping(self):
1183         self.handle('bootstrapping')
1184
1185     def handle_provisioning(self):
1186         self.handle('provisioning')
1187
1188     def handle_postconfig(self):
1189         self.handle('postconfig')
1190
1191     def handle_setup(self):
1192         try:
1193             ownhostobj = None
1194             for host in self.hosts:
1195                 if host.name == self.ownhost:
1196                     ownhostobj = host
1197                     break
1198             if not ownhostobj:
1199                 raise cmerror.CMError('Invalid own host configuration %s' % self.ownhost)
1200             text = Environment().from_string(json_text_setup).render(host=ownhostobj, installation_controller=self.ownhost, general=self.general)
1201
1202             inventory = json.loads(text)
1203
1204             #add some variables from the original inventory
1205             self.inventory.update(inventory)
1206             self.inventory['all'] = {'hosts': [self.ownhost]}
1207             self.inventory['all']['vars'] = {}
1208
1209             setuphosts = {}
1210             setupnetworking = {}
1211             setupnetworkprofiles = {}
1212
1213             if 'hosts' in self.orig_inventory['all']['vars'] and self.ownhost in self.orig_inventory['all']['vars']['hosts']:
1214                 setuphosts = self.orig_inventory['all']['vars']['hosts'][self.ownhost]
1215             if 'networking' in self.orig_inventory['all']['vars']:
1216                 setupnetworking = self.orig_inventory['all']['vars']['networking']
1217             if 'network_profiles' in self.orig_inventory['all']['vars']:
1218                 setupnetworkprofiles = self.orig_inventory['all']['vars']['network_profiles']
1219
1220             if setuphosts:
1221                 self.inventory['all']['vars']['hosts'] = {self.ownhost: setuphosts}
1222             if setupnetworking:
1223                 self.inventory['all']['vars']['networking'] = setupnetworking
1224             if setupnetworkprofiles:
1225                 self.inventory['all']['vars']['network_profiles'] = setupnetworkprofiles
1226
1227             #add networking configuration to own host
1228             if self.ownhost in self.orig_inventory['_meta']['hostvars'] and 'networking' in self.orig_inventory['_meta']['hostvars'][self.ownhost]:
1229                 self.inventory['_meta']['hostvars'][self.ownhost]['networking'] = self.orig_inventory['_meta']['hostvars'][self.ownhost]['networking']
1230
1231         except Exception as exp:
1232             raise cmerror.CMError(str(exp))
1233
1234     def handle(self, phase):
1235         try:
1236             networkingconf = self.confman.get_networking_config_handler()
1237             hostsconf = self.confman.get_hosts_config_handler()
1238
1239             infrainternal = networkingconf.get_infra_internal_network_name()
1240             infraexternal = networkingconf.get_infra_external_network_name()
1241
1242             installation_controller = socket.gethostname()
1243
1244             # sort management nodes so that installation_controlle is the first
1245             modified_list = []
1246             for entry in self.managements:
1247                 if entry.name == installation_controller:
1248                     modified_list.append(entry)
1249
1250             for entry in self.managements:
1251                 if entry.name != installation_controller:
1252                     modified_list.append(entry)
1253
1254             self.managements = modified_list
1255
1256             installation_controller_ip = networkingconf.get_host_ip(installation_controller, infrainternal)
1257             installation_network_domain = hostsconf.get_host_network_domain(installation_controller)
1258
1259             virtual_environment = utils.is_virtualized()
1260
1261             openstackconfig = self.confman.get_openstack_config_handler()
1262             storagebackend = openstackconfig.get_storage_backend()
1263
1264             #construct privder netwrks based on the installation controller
1265             infra_mgmt = ProviderNetwork()
1266             infra_external = ProviderNetwork()
1267
1268             host = self._get_host(installation_controller)
1269
1270             #Installation controller has to be the first one in the controllers list
1271             #Most of the openstack ansbile modules are executed on first host in the list. This does not work properly.
1272             if self.controllers:
1273                 self.controllers.remove(host)
1274                 self.controllers.insert(0, host)
1275
1276             for hostnet in host.networks:
1277                 if hostnet.network.name == infrainternal:
1278                     infra_mgmt.cidr = hostnet.network.cidr
1279                     infra_mgmt.cidrs = hostnet.network.cidrs
1280                     infra_mgmt.interface = hostnet.ip_holding_interface
1281                     infra_mgmt.ip = networkingconf.get_host_ip(installation_controller, infrainternal)
1282                 elif hostnet.network.name == infraexternal:
1283                     infra_external.cidr = hostnet.network.cidr
1284                     infra_external.interface = hostnet.ip_holding_interface
1285                     infra_external.ip = networkingconf.get_host_ip(installation_controller, infraexternal)
1286                     infra_external.gateway = networkingconf.get_network_gateway(infraexternal, installation_network_domain)
1287
1288             caas_conf = self.confman.get_caas_config_handler()
1289
1290             text = Environment().from_string(json_text).render(hosts=self.hosts, networks=self.networks, general=self.general, has=self.has, virtual_environment=virtual_environment, installation_controller=installation_controller, installation_controller_ip=installation_controller_ip, infra_mgmt=infra_mgmt, infra_external=infra_external, controllers=self.controllers, computes=self.computes, storages=self.storages, neutron_agent_hosts=self.neutron_agent_hosts, config_phase=phase, hostsconf=hostsconf, networkingconf=networkingconf, storagebackend=storagebackend, vnf_embedded_deployment = caas_conf.get_vnf_flag(), caas_only_deployment = caas_conf.get_caas_only(), management_nodes = self.managements)
1291             #print(text)
1292             inventory = json.loads(text)
1293
1294             #process host vars
1295             for host in inventory['_meta']['hostvars'].keys():
1296                 for var, value in inventory['_meta']['hostvars'][host].iteritems():
1297                     self.add_host_var(host, var, value)
1298
1299             #process all vars
1300             for var, value in inventory['all']['vars'].iteritems():
1301                 self.add_global_var(var, value)
1302
1303             #process groups
1304             for var, value in inventory.iteritems():
1305                 if var == '_meta' or var == 'all':
1306                     continue
1307                 self.inventory[var] = value
1308
1309             #create a mapping between service-groups and vips to be added to /etc/hosts
1310             if phase == "postconfig":
1311                 sgvips = {}
1312                 sgvips['config-manager'] = networkingconf.get_internal_vip()
1313                 sgvips['haproxyvip'] = networkingconf.get_internal_vip()
1314                 self.add_global_var('extra_hosts_entries', sgvips)
1315
1316         except Exception as exp:
1317             raise cmerror.CMError(str(exp))
1318
1319     def _is_host_controller(self, host):
1320         hostsconf = self.confman.get_hosts_config_handler()
1321         node_service_profiles = hostsconf.get_service_profiles(host)
1322         controller_profile = profiles.Profiles.get_controller_service_profile()
1323         for profile in node_service_profiles:
1324             if profile == controller_profile:
1325                 return True
1326         return False
1327
1328     def _is_host_caas_master(self, host):
1329         hostsconf = self.confman.get_hosts_config_handler()
1330         node_service_profiles = hostsconf.get_service_profiles(host)
1331         caas_master_profile = profiles.Profiles.get_caasmaster_service_profile()
1332         for profile in node_service_profiles:
1333             if profile == caas_master_profile:
1334                 return True
1335         return False
1336
1337     def _is_host_management(self, host):
1338         hostsconf = self.confman.get_hosts_config_handler()
1339         node_service_profiles = hostsconf.get_service_profiles(host)
1340         management_profile = profiles.Profiles.get_management_service_profile()
1341         for profile in node_service_profiles:
1342             if profile == management_profile:
1343                 return True
1344         return False
1345
1346     def _is_host_compute(self, host):
1347         hostsconf = self.confman.get_hosts_config_handler()
1348         node_service_profiles = hostsconf.get_service_profiles(host)
1349         compute_profile = profiles.Profiles.get_compute_service_profile()
1350         for profile in node_service_profiles:
1351             if profile == compute_profile:
1352                 return True
1353         return False
1354
1355     def _is_host_storage(self, host):
1356         hostsconf = self.confman.get_hosts_config_handler()
1357         node_service_profiles = hostsconf.get_service_profiles(host)
1358         storage_profile = profiles.Profiles.get_storage_service_profile()
1359         for profile in node_service_profiles:
1360             if profile == storage_profile:
1361                 return True
1362         return False
1363
1364     def _get_network(self, name, host):
1365         for network in self.networks:
1366             if network.name == name:
1367                 return network
1368
1369         hostsconf = self.confman.get_hosts_config_handler()
1370         domain = hostsconf.get_host_network_domain(host)
1371         networkingconf = self.confman.get_networking_config_handler()
1372         network = Network()
1373         network.name = name
1374         network.cidr = networkingconf.get_network_cidr(name, domain)
1375         for dom in networkingconf.get_network_domains(name):
1376             network.cidrs.add(networkingconf.get_network_cidr(name, dom))
1377         network.vlan = None
1378         try:
1379             network.vlan = networkingconf.get_network_vlan_id(name, domain)
1380         except configerror.ConfigError:
1381             pass
1382
1383         network.gateway = None
1384         try:
1385             network.gateway = networkingconf.get_network_gateway(name, domain)
1386         except configerror.ConfigError:
1387             pass
1388
1389         self.networks.append(network)
1390         return network
1391
1392     def _get_platform_cpus(self, host):
1393         hostsconf = self.confman.get_hosts_config_handler()
1394         cpus = 0
1395         try:
1396             perfprofconf = self.confman.get_performance_profiles_config_handler()
1397             pprofile = hostsconf.get_performance_profiles(host.name)[0]
1398             platform_cpus = perfprofconf.get_platform_cpus(pprofile)
1399             if platform_cpus:
1400                 for alloc in platform_cpus.values():
1401                     cpus = cpus + int(alloc)
1402         except configerror.ConfigError:
1403             pass
1404         except IndexError:
1405             pass
1406         except KeyError:
1407             pass
1408         return cpus
1409
1410     def _get_host(self, name):
1411         for host in self.hosts:
1412             if host.name == name:
1413                 return host
1414
1415
1416         hostsconf = self.confman.get_hosts_config_handler()
1417         networkprofilesconf = self.confman.get_network_profiles_config_handler()
1418         networkingconf = self.confman.get_networking_config_handler()
1419
1420         host = Host()
1421         host.name = name
1422         host.is_controller = self._is_host_controller(name)
1423         host.is_caas_master = self._is_host_caas_master(name)
1424         host.is_compute = self._is_host_compute(name)
1425         host.is_storage = self._is_host_storage(name)
1426         host.is_management = self._is_host_management(name)
1427         host.hwmgmt_address = hostsconf.get_hwmgmt_ip(name)
1428         host.hwmgmt_user = hostsconf.get_hwmgmt_user(name)
1429         host.hwmgmt_password = hostsconf.get_hwmgmt_password(name)
1430         host.mgmt_mac = hostsconf.get_mgmt_mac(name)
1431
1432
1433         platform_cpus = self._get_platform_cpus(host)
1434         if platform_cpus:
1435             host.os_max_threads = platform_cpus
1436             host.is_performance = True
1437
1438         hostnetprofiles = hostsconf.get_network_profiles(name)
1439
1440         hostnetnames = hostsconf.get_host_networks(name)
1441         domain = hostsconf.get_host_network_domain(name)
1442
1443         for net in hostnetnames:
1444             hostnetwork = HostNetwork()
1445             hostnetwork.network = self._get_network(net, name)
1446             hostnetwork.interface = hostsconf.get_host_network_interface(name, net)
1447             hostnetwork.ip_holding_interface = hostsconf.get_host_network_ip_holding_interface(name, net)
1448             hostnetwork.ip = networkingconf.get_host_ip(name, net)
1449             mask = networkingconf.get_network_mask(net, domain)
1450             hostnetwork.ip = hostnetwork.ip + '/' + str(mask)
1451
1452             hostnetwork.is_bonding = False
1453
1454             for profile in hostnetprofiles:
1455                 try:
1456                     bondinginterfaces = networkprofilesconf.get_profile_bonding_interfaces(profile)
1457                     if hostnetwork.interface in bondinginterfaces:
1458                         hostnetwork.is_bonding = True
1459                         hostnetwork.members = networkprofilesconf.get_profile_bonded_interfaces(profile, hostnetwork.interface)
1460                         hostnetwork.linux_bonding_options = networkprofilesconf.get_profile_linux_bonding_options(profile)
1461                         break
1462                 except configerror.ConfigError:
1463                     pass
1464             host.networks.append(hostnetwork)
1465
1466         self.hosts.append(host)
1467         if host.is_controller:
1468             self.controllers.append(host)
1469             self.neutron_agent_hosts.add(host)
1470         if host.is_caas_master:
1471             self.caas_masters.append(host)
1472         if host.is_management:
1473             self.managements.append(host)
1474         if host.is_compute:
1475             self.computes.append(host)
1476             self.neutron_agent_hosts.add(host)
1477         if host.is_storage:
1478             self.storages.append(host)
1479
1480
1481     def _init_jinja_environment(self):
1482         # initialize networks and hosts
1483         networkingconf = self.confman.get_networking_config_handler()
1484         networks = networkingconf.get_networks()
1485         hostsconf = self.confman.get_hosts_config_handler()
1486         hosts = hostsconf.get_enabled_hosts()
1487         for net in networks:
1488             for host in hosts:
1489                 self._get_network(net, host)
1490                 self._get_host(host)
1491
1492         # initialize HAS
1493         self.has.haproxy.external_vip = networkingconf.get_external_vip()
1494         self.has.haproxy.internal_vip = networkingconf.get_internal_vip()
1495
1496         # initialize general
1497         self.general.dns_servers = networkingconf.get_dns()
1498         timeconf = self.confman.get_time_config_handler()
1499         self.general.ntp_servers = timeconf.get_ntp_servers()
1500         self.general.zone = timeconf.get_zone()
1501         usersconf = self.confman.get_users_config_handler()
1502         self.general.admin = usersconf.get_admin_user()
1503         self.general.password = usersconf.get_admin_user_password()
1504         caas_conf = self.confman.get_caas_config_handler()
1505         if caas_conf.get_caas_only():
1506           self.general.openstack_password = usersconf.get_admin_password()
1507         else:
1508           openstackconfighandler = self.confman.get_openstack_config_handler()
1509           self.general.openstack_password = openstackconfighandler.get_admin_password()