FIX: Set default IPMI privilege level
[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.hwmgmt_priv_level = 'ADMINISTRATOR'
1141         self.mgmt_mac = None
1142         self.is_performance = False
1143         self.os_max_threads = 16
1144
1145
1146     def get_network_ip(self, networkname):
1147         for network in self.networks:
1148             if network.network.name == networkname:
1149                 return network.ip.split('/')[0]
1150
1151     def get_network_ip_holding_interface(self, networkname):
1152         for network in self.networks:
1153             if network.network.name == networkname:
1154                 return network.ip_holding_interface
1155
1156
1157 class HAProxy:
1158     def __init__(self):
1159         self.internal_vip = None
1160         self.external_vip = None
1161
1162 class HAS:
1163     def __init__(self):
1164         self.haproxy = HAProxy()
1165
1166 class openstackinventory(cmansibleinventoryconfig.CMAnsibleInventoryConfigPlugin):
1167     def __init__(self, confman, inventory, ownhost):
1168         super(openstackinventory, self).__init__(confman, inventory, ownhost)
1169         self.networks = []
1170         self.hosts = []
1171         self.controllers = []
1172         self.managements = []
1173         self.caas_masters = []
1174         self.computes = []
1175         self.storages = []
1176         self.neutron_agent_hosts = set()
1177         self.has = HAS()
1178         self.general = General()
1179         self._init_jinja_environment()
1180         self.orig_inventory = inventory.copy()
1181
1182
1183     def handle_bootstrapping(self):
1184         self.handle('bootstrapping')
1185
1186     def handle_provisioning(self):
1187         self.handle('provisioning')
1188
1189     def handle_postconfig(self):
1190         self.handle('postconfig')
1191
1192     def handle_setup(self):
1193         try:
1194             ownhostobj = None
1195             for host in self.hosts:
1196                 if host.name == self.ownhost:
1197                     ownhostobj = host
1198                     break
1199             if not ownhostobj:
1200                 raise cmerror.CMError('Invalid own host configuration %s' % self.ownhost)
1201             text = Environment().from_string(json_text_setup).render(host=ownhostobj, installation_controller=self.ownhost, general=self.general)
1202
1203             inventory = json.loads(text)
1204
1205             #add some variables from the original inventory
1206             self.inventory.update(inventory)
1207             self.inventory['all'] = {'hosts': [self.ownhost]}
1208             self.inventory['all']['vars'] = {}
1209
1210             setuphosts = {}
1211             setupnetworking = {}
1212             setupnetworkprofiles = {}
1213
1214             if 'hosts' in self.orig_inventory['all']['vars'] and self.ownhost in self.orig_inventory['all']['vars']['hosts']:
1215                 setuphosts = self.orig_inventory['all']['vars']['hosts'][self.ownhost]
1216             if 'networking' in self.orig_inventory['all']['vars']:
1217                 setupnetworking = self.orig_inventory['all']['vars']['networking']
1218             if 'network_profiles' in self.orig_inventory['all']['vars']:
1219                 setupnetworkprofiles = self.orig_inventory['all']['vars']['network_profiles']
1220
1221             if setuphosts:
1222                 self.inventory['all']['vars']['hosts'] = {self.ownhost: setuphosts}
1223             if setupnetworking:
1224                 self.inventory['all']['vars']['networking'] = setupnetworking
1225             if setupnetworkprofiles:
1226                 self.inventory['all']['vars']['network_profiles'] = setupnetworkprofiles
1227
1228             #add networking configuration to own host
1229             if self.ownhost in self.orig_inventory['_meta']['hostvars'] and 'networking' in self.orig_inventory['_meta']['hostvars'][self.ownhost]:
1230                 self.inventory['_meta']['hostvars'][self.ownhost]['networking'] = self.orig_inventory['_meta']['hostvars'][self.ownhost]['networking']
1231
1232         except Exception as exp:
1233             raise cmerror.CMError(str(exp))
1234
1235     def handle(self, phase):
1236         try:
1237             networkingconf = self.confman.get_networking_config_handler()
1238             hostsconf = self.confman.get_hosts_config_handler()
1239
1240             infrainternal = networkingconf.get_infra_internal_network_name()
1241             infraexternal = networkingconf.get_infra_external_network_name()
1242
1243             installation_controller = socket.gethostname()
1244
1245             # sort management nodes so that installation_controlle is the first
1246             modified_list = []
1247             for entry in self.managements:
1248                 if entry.name == installation_controller:
1249                     modified_list.append(entry)
1250
1251             for entry in self.managements:
1252                 if entry.name != installation_controller:
1253                     modified_list.append(entry)
1254
1255             self.managements = modified_list
1256
1257             installation_controller_ip = networkingconf.get_host_ip(installation_controller, infrainternal)
1258             installation_network_domain = hostsconf.get_host_network_domain(installation_controller)
1259
1260             virtual_environment = utils.is_virtualized()
1261
1262             openstackconfig = self.confman.get_openstack_config_handler()
1263             storagebackend = openstackconfig.get_storage_backend()
1264
1265             #construct privder netwrks based on the installation controller
1266             infra_mgmt = ProviderNetwork()
1267             infra_external = ProviderNetwork()
1268
1269             host = self._get_host(installation_controller)
1270
1271             #Installation controller has to be the first one in the controllers list
1272             #Most of the openstack ansbile modules are executed on first host in the list. This does not work properly.
1273             if self.controllers:
1274                 self.controllers.remove(host)
1275                 self.controllers.insert(0, host)
1276
1277             for hostnet in host.networks:
1278                 if hostnet.network.name == infrainternal:
1279                     infra_mgmt.cidr = hostnet.network.cidr
1280                     infra_mgmt.cidrs = hostnet.network.cidrs
1281                     infra_mgmt.interface = hostnet.ip_holding_interface
1282                     infra_mgmt.ip = networkingconf.get_host_ip(installation_controller, infrainternal)
1283                 elif hostnet.network.name == infraexternal:
1284                     infra_external.cidr = hostnet.network.cidr
1285                     infra_external.interface = hostnet.ip_holding_interface
1286                     infra_external.ip = networkingconf.get_host_ip(installation_controller, infraexternal)
1287                     infra_external.gateway = networkingconf.get_network_gateway(infraexternal, installation_network_domain)
1288
1289             caas_conf = self.confman.get_caas_config_handler()
1290
1291             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)
1292             #print(text)
1293             inventory = json.loads(text)
1294
1295             #process host vars
1296             for host in inventory['_meta']['hostvars'].keys():
1297                 for var, value in inventory['_meta']['hostvars'][host].iteritems():
1298                     self.add_host_var(host, var, value)
1299
1300             #process all vars
1301             for var, value in inventory['all']['vars'].iteritems():
1302                 self.add_global_var(var, value)
1303
1304             #process groups
1305             for var, value in inventory.iteritems():
1306                 if var == '_meta' or var == 'all':
1307                     continue
1308                 self.inventory[var] = value
1309
1310             #create a mapping between service-groups and vips to be added to /etc/hosts
1311             if phase == "postconfig":
1312                 sgvips = {}
1313                 sgvips['config-manager'] = networkingconf.get_internal_vip()
1314                 sgvips['haproxyvip'] = networkingconf.get_internal_vip()
1315                 self.add_global_var('extra_hosts_entries', sgvips)
1316
1317         except Exception as exp:
1318             raise cmerror.CMError(str(exp))
1319
1320     def _is_host_controller(self, host):
1321         hostsconf = self.confman.get_hosts_config_handler()
1322         node_service_profiles = hostsconf.get_service_profiles(host)
1323         controller_profile = profiles.Profiles.get_controller_service_profile()
1324         for profile in node_service_profiles:
1325             if profile == controller_profile:
1326                 return True
1327         return False
1328
1329     def _is_host_caas_master(self, host):
1330         hostsconf = self.confman.get_hosts_config_handler()
1331         node_service_profiles = hostsconf.get_service_profiles(host)
1332         caas_master_profile = profiles.Profiles.get_caasmaster_service_profile()
1333         for profile in node_service_profiles:
1334             if profile == caas_master_profile:
1335                 return True
1336         return False
1337
1338     def _is_host_management(self, host):
1339         hostsconf = self.confman.get_hosts_config_handler()
1340         node_service_profiles = hostsconf.get_service_profiles(host)
1341         management_profile = profiles.Profiles.get_management_service_profile()
1342         for profile in node_service_profiles:
1343             if profile == management_profile:
1344                 return True
1345         return False
1346
1347     def _is_host_compute(self, host):
1348         hostsconf = self.confman.get_hosts_config_handler()
1349         node_service_profiles = hostsconf.get_service_profiles(host)
1350         compute_profile = profiles.Profiles.get_compute_service_profile()
1351         for profile in node_service_profiles:
1352             if profile == compute_profile:
1353                 return True
1354         return False
1355
1356     def _is_host_storage(self, host):
1357         hostsconf = self.confman.get_hosts_config_handler()
1358         node_service_profiles = hostsconf.get_service_profiles(host)
1359         storage_profile = profiles.Profiles.get_storage_service_profile()
1360         for profile in node_service_profiles:
1361             if profile == storage_profile:
1362                 return True
1363         return False
1364
1365     def _get_network(self, name, host):
1366         for network in self.networks:
1367             if network.name == name:
1368                 return network
1369
1370         hostsconf = self.confman.get_hosts_config_handler()
1371         domain = hostsconf.get_host_network_domain(host)
1372         networkingconf = self.confman.get_networking_config_handler()
1373         network = Network()
1374         network.name = name
1375         network.cidr = networkingconf.get_network_cidr(name, domain)
1376         for dom in networkingconf.get_network_domains(name):
1377             network.cidrs.add(networkingconf.get_network_cidr(name, dom))
1378         network.vlan = None
1379         try:
1380             network.vlan = networkingconf.get_network_vlan_id(name, domain)
1381         except configerror.ConfigError:
1382             pass
1383
1384         network.gateway = None
1385         try:
1386             network.gateway = networkingconf.get_network_gateway(name, domain)
1387         except configerror.ConfigError:
1388             pass
1389
1390         self.networks.append(network)
1391         return network
1392
1393     def _get_platform_cpus(self, host):
1394         hostsconf = self.confman.get_hosts_config_handler()
1395         cpus = 0
1396         try:
1397             perfprofconf = self.confman.get_performance_profiles_config_handler()
1398             pprofile = hostsconf.get_performance_profiles(host.name)[0]
1399             platform_cpus = perfprofconf.get_platform_cpus(pprofile)
1400             if platform_cpus:
1401                 for alloc in platform_cpus.values():
1402                     cpus = cpus + int(alloc)
1403         except configerror.ConfigError:
1404             pass
1405         except IndexError:
1406             pass
1407         except KeyError:
1408             pass
1409         return cpus
1410
1411     def _get_host(self, name):
1412         for host in self.hosts:
1413             if host.name == name:
1414                 return host
1415
1416
1417         hostsconf = self.confman.get_hosts_config_handler()
1418         networkprofilesconf = self.confman.get_network_profiles_config_handler()
1419         networkingconf = self.confman.get_networking_config_handler()
1420
1421         host = Host()
1422         host.name = name
1423         host.is_controller = self._is_host_controller(name)
1424         host.is_caas_master = self._is_host_caas_master(name)
1425         host.is_compute = self._is_host_compute(name)
1426         host.is_storage = self._is_host_storage(name)
1427         host.is_management = self._is_host_management(name)
1428         host.hwmgmt_address = hostsconf.get_hwmgmt_ip(name)
1429         host.hwmgmt_user = hostsconf.get_hwmgmt_user(name)
1430         host.hwmgmt_password = hostsconf.get_hwmgmt_password(name)
1431         host.hwmgmt_priv_level = hostsconf.get_hwmgmt_priv_level(name)
1432         host.mgmt_mac = hostsconf.get_mgmt_mac(name)
1433
1434
1435         platform_cpus = self._get_platform_cpus(host)
1436         if platform_cpus:
1437             host.os_max_threads = platform_cpus
1438             host.is_performance = True
1439
1440         hostnetprofiles = hostsconf.get_network_profiles(name)
1441
1442         hostnetnames = hostsconf.get_host_networks(name)
1443         domain = hostsconf.get_host_network_domain(name)
1444
1445         for net in hostnetnames:
1446             hostnetwork = HostNetwork()
1447             hostnetwork.network = self._get_network(net, name)
1448             hostnetwork.interface = hostsconf.get_host_network_interface(name, net)
1449             hostnetwork.ip_holding_interface = hostsconf.get_host_network_ip_holding_interface(name, net)
1450             hostnetwork.ip = networkingconf.get_host_ip(name, net)
1451             mask = networkingconf.get_network_mask(net, domain)
1452             hostnetwork.ip = hostnetwork.ip + '/' + str(mask)
1453
1454             hostnetwork.is_bonding = False
1455
1456             for profile in hostnetprofiles:
1457                 try:
1458                     bondinginterfaces = networkprofilesconf.get_profile_bonding_interfaces(profile)
1459                     if hostnetwork.interface in bondinginterfaces:
1460                         hostnetwork.is_bonding = True
1461                         hostnetwork.members = networkprofilesconf.get_profile_bonded_interfaces(profile, hostnetwork.interface)
1462                         hostnetwork.linux_bonding_options = networkprofilesconf.get_profile_linux_bonding_options(profile)
1463                         break
1464                 except configerror.ConfigError:
1465                     pass
1466             host.networks.append(hostnetwork)
1467
1468         self.hosts.append(host)
1469         if host.is_controller:
1470             self.controllers.append(host)
1471             self.neutron_agent_hosts.add(host)
1472         if host.is_caas_master:
1473             self.caas_masters.append(host)
1474         if host.is_management:
1475             self.managements.append(host)
1476         if host.is_compute:
1477             self.computes.append(host)
1478             self.neutron_agent_hosts.add(host)
1479         if host.is_storage:
1480             self.storages.append(host)
1481
1482
1483     def _init_jinja_environment(self):
1484         # initialize networks and hosts
1485         networkingconf = self.confman.get_networking_config_handler()
1486         networks = networkingconf.get_networks()
1487         hostsconf = self.confman.get_hosts_config_handler()
1488         hosts = hostsconf.get_enabled_hosts()
1489         for net in networks:
1490             for host in hosts:
1491                 self._get_network(net, host)
1492                 self._get_host(host)
1493
1494         # initialize HAS
1495         self.has.haproxy.external_vip = networkingconf.get_external_vip()
1496         self.has.haproxy.internal_vip = networkingconf.get_internal_vip()
1497
1498         # initialize general
1499         self.general.dns_servers = networkingconf.get_dns()
1500         timeconf = self.confman.get_time_config_handler()
1501         self.general.ntp_servers = timeconf.get_ntp_servers()
1502         self.general.zone = timeconf.get_zone()
1503         usersconf = self.confman.get_users_config_handler()
1504         self.general.admin = usersconf.get_admin_user()
1505         self.general.password = usersconf.get_admin_user_password()
1506         caas_conf = self.confman.get_caas_config_handler()
1507         if caas_conf.get_caas_only():
1508           self.general.openstack_password = usersconf.get_admin_password()
1509         else:
1510           openstackconfighandler = self.confman.get_openstack_config_handler()
1511           self.general.openstack_password = openstackconfighandler.get_admin_password()