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