Kubenretes node role added to inventory.
[ta/config-manager.git] / cmdatahandlers / src / cmdatahandlers / hosts / config.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 re
16
17 from cmdatahandlers.api import configerror
18 from cmdatahandlers.api import config
19 from cmdatahandlers.api import utils
20 from serviceprofiles import profiles
21
22 VNF_EMBEDDED_RESERVED_MEMORY = "512Mi"
23 DUAL_VIM_CONTROLLER_RESERVED_MEMORY = "64Gi"
24 DUAL_VIM_DEFAULT_RESERVED_MEMORY = "32Gi"
25 MIDDLEWARE_RESERVED_MEMORY = "12Gi"
26
27 class Config(config.Config):
28     def __init__(self, confman):
29         super(Config, self).__init__(confman)
30         self.ROOT = 'cloud.hosts'
31         self.DOMAIN = 'hosts'
32         try:
33             self.update_service_profiles()
34         except Exception:
35             pass
36
37     def init(self):
38         pass
39
40     def validate(self):
41         hosts = []
42         try:
43             hosts = self.get_hosts()
44         except configerror.ConfigError:
45             pass
46
47         if hosts:
48             utils.validate_list_items_unique(hosts)
49
50         for host in hosts:
51             self._validate_host(host)
52
53     def mask_sensitive_data(self):
54         for hostname in self.config[self.ROOT].keys():
55             self.config[self.ROOT][hostname]['hwmgmt']['password'] = self.MASK
56             self.config[self.ROOT][hostname]['hwmgmt']['snmpv2_trap_community_string'] = self.MASK
57             self.config[self.ROOT][hostname]['hwmgmt']['snmpv3_authpass'] = self.MASK
58             self.config[self.ROOT][hostname]['hwmgmt']['snmpv3_privpass'] = self.MASK
59
60     def _validate_host(self, hostname):
61         self._validate_hwmgmt(hostname)
62         self._validate_service_profiles(hostname)
63         self._validate_network_profiles(hostname)
64         self._validate_performance_profiles(hostname)
65         self._validate_storage_profiles(hostname)
66
67     def _validate_hwmgmt(self, hostname):
68         ip = self.get_hwmgmt_ip(hostname)
69         utils.validate_ipv4_address(ip)
70         self.get_hwmgmt_user(hostname)
71         self.get_hwmgmt_password(hostname)
72         netconf = self.confman.get_networking_config_handler()
73
74         hwmgmtnet = None
75         try:
76             hwmgmtnet = netconf.get_hwmgmt_network_name()
77         except configerror.ConfigError:
78             pass
79
80         if hwmgmtnet:
81             domain = self.get_host_network_domain(hostname)
82             cidr = netconf.get_network_cidr(hwmgmtnet, domain)
83             utils.validate_ip_in_network(ip, cidr)
84
85     def get_hwmgmt_priv_level(self, hostname):
86         """get the hwmgmt IPMI privilege level.  Defaults to ADMINISTRATOR
87
88            Arguments:
89
90            hostname: The name of the node
91
92            Return:
93
94            The prvilege level, or ADMINISTRATOR if unspecified
95
96            Raise:
97
98            ConfigError in-case of an error
99         """
100         self._validate_hostname(hostname)
101
102         if 'hwmgmt' not in self.config[self.ROOT][hostname]:
103             raise configerror.ConfigError('No hwmgmt info defined for host')
104
105         return self.config[self.ROOT][hostname]['hwmgmt'].get('priv_level', 'ADMINISTRATOR')
106
107     def _validate_service_profiles(self, hostname):
108         node_profiles = self.get_service_profiles(hostname)
109         utils.validate_list_items_unique(node_profiles)
110         service_profiles_lib = profiles.Profiles()
111         serviceprofiles = service_profiles_lib.get_service_profiles()
112         for profile in node_profiles:
113             if profile not in serviceprofiles:
114                 raise configerror.ConfigError('Invalid service profile %s specified for host %s' % (profile, hostname))
115
116     def _validate_network_profiles(self, hostname):
117         node_profiles = self.get_network_profiles(hostname)
118         utils.validate_list_items_unique(profiles)
119         netprofconf = self.confman.get_network_profiles_config_handler()
120         netprofiles = netprofconf.get_network_profiles()
121         for profile in node_profiles:
122             if profile not in netprofiles:
123                 raise configerror.ConfigError('Invalid network profile %s specified for host %s' % (profile, hostname))
124
125     def _validate_performance_profiles(self, hostname):
126         node_performance_profiles = []
127         try:
128             node_performance_profiles = self.get_performance_profiles(hostname)
129         except configerror.ConfigError:
130             pass
131
132         if node_performance_profiles:
133             utils.validate_list_items_unique(node_performance_profiles)
134             perfprofconf = self.confman.get_performance_profiles_config_handler()
135             perfprofiles = perfprofconf.get_performance_profiles()
136             for profile in node_performance_profiles:
137                 if profile not in perfprofiles:
138                     raise configerror.ConfigError('Invalid performance profile %s specified for host %s' % (profile, hostname))
139
140     def _validate_storage_profiles(self, hostname):
141         node_storage_profiles = []
142         try:
143             node_storage_profiles = self.get_storage_profiles(hostname)
144         except configerror.ConfigError:
145             pass
146
147         if node_storage_profiles:
148             utils.validate_list_items_unique(node_storage_profiles)
149             storageprofconf = self.confman.get_storage_profiles_config_handler()
150             storageprofiles = storageprofconf.get_storage_profiles()
151             for profile in node_storage_profiles:
152                 if profile not in storageprofiles:
153                     raise configerror.ConfigError('Invalid storage profile %s specific for %s' % (profile, hostname))
154
155     def get_hosts(self):
156         """ get the list of hosts in the cloud
157
158             Return:
159
160             A sorted list of host names
161
162             Raise:
163
164             ConfigError in-case of an error
165         """
166         self.validate_root()
167
168         return sorted(self.config[self.ROOT].keys())
169
170     def get_labels(self, hostname):
171         mandatory_labels = \
172             {"nodetype": self.get_nodetype(hostname),
173              "nodeindex": self.get_nodeindex(hostname),
174              "nodename": self.get_nodename(hostname)}
175         labels = self.config[self.ROOT][hostname].get('labels', {}).copy()
176         labels.update(mandatory_labels)
177
178         if self.is_sriov_enabled(hostname):
179             labels.update({"sriov": "enabled"})
180
181         black_list = ['name']
182         return {name: attributes
183                 for name, attributes in labels.iteritems()
184                 if name not in black_list}
185
186     def get_nodetype(self, hostname):
187         service_profiles_lib = profiles.Profiles()
188         service_profiles = self.get_service_profiles(hostname)
189
190         if service_profiles_lib.get_caasmaster_service_profile() in service_profiles:
191             return service_profiles_lib.get_caasmaster_service_profile()
192         if service_profiles_lib.get_caasworker_service_profile() in service_profiles:
193             return service_profiles_lib.get_caasworker_service_profile()
194
195         return service_profiles[0]
196
197     def set_nodeindex(self):
198         hostsconf = self.confman.get_hosts_config_handler()
199         install_host = utils.get_installation_host_name(hostsconf)
200         self.config[self.ROOT][install_host]['caas_nodeindex'] = 1
201
202         masters = self.get_service_profile_hosts('caas_master')
203         masters.remove(install_host)
204         self._set_nodeindexes(masters, 2)
205         self._set_nodeindexes(self.get_service_profile_hosts('caas_worker'), 1)
206
207     def _set_nodeindexes(self, hosts, base_index):
208         index = base_index
209         for host in hosts:
210             self.config[self.ROOT][host]['caas_nodeindex'] = index
211             index += 1
212
213     def get_nodeindex(self, hostname):
214         return self.config[self.ROOT][hostname]['caas_nodeindex']
215
216     def get_nodename(self, hostname):
217         return "{}{}".format(self.get_nodetype(hostname), self.get_nodeindex(hostname))
218
219     def get_noderole(self, hostname):
220         service_profiles_lib = profiles.Profiles()
221         service_profiles = self.get_service_profiles(hostname)
222
223         if service_profiles_lib.get_caasmaster_service_profile() in service_profiles:
224             return "master"
225         return "worker"
226
227     def is_sriov_enabled(self, hostname):
228         netprofs = self.get_network_profiles(hostname)
229         netprofconf = self.confman.get_network_profiles_config_handler()
230         for netprof in netprofs:
231             if 'sriov_provider_networks' in self.config[netprofconf.ROOT][netprof]:
232                 return True
233         return False
234
235     def get_enabled_hosts(self):
236         """ get the list of enabled hosts in the cloud
237
238             Return:
239
240             A list of host names
241
242             Raise:
243
244             ConfigError in-case of an error
245         """
246         self.validate_root()
247         hosts = self.get_hosts()
248         ret = []
249         for host in hosts:
250             if self.is_host_enabled(host):
251                 ret.append(host)
252         return ret
253
254     def get_hwmgmt_ip(self, hostname):
255         """get the hwmgmt ip address
256
257             Arguments:
258
259             hostname: The name of the node
260
261             Return:
262
263             The BMC ip address as a string
264
265             Raise:
266
267             ConfigError in-case of an error
268         """
269         self._validate_hostname(hostname)
270
271         if 'hwmgmt' not in self.config[self.ROOT][hostname] or 'address' not in self.config[self.ROOT][hostname]['hwmgmt']:
272             raise configerror.ConfigError('No hwmgmt info defined for host')
273
274         return self.config[self.ROOT][hostname]['hwmgmt']['address']
275
276     def get_hwmgmt_user(self, hostname):
277         """get the hwmgmt user
278
279             Arguments:
280
281             hostname: The name of the node
282
283             Return:
284
285             The BMC user name.
286
287             Raise:
288
289             ConfigError in-case of an error
290         """
291         self._validate_hostname(hostname)
292
293         if 'hwmgmt' not in self.config[self.ROOT][hostname] or 'user' not in self.config[self.ROOT][hostname]['hwmgmt']:
294             raise configerror.ConfigError('No hwmgmt info defined for host')
295
296         return self.config[self.ROOT][hostname]['hwmgmt']['user']
297
298     def get_hwmgmt_password(self, hostname):
299         """get the hwmgmt password
300
301            Arguments:
302
303            hostname: The name of the node
304
305            Return:
306
307            The BMC password
308
309            Raise:
310
311            ConfigError in-case of an error
312         """
313         self._validate_hostname(hostname)
314
315         if 'hwmgmt' not in self.config[self.ROOT][hostname] or 'password' not in self.config[self.ROOT][hostname]['hwmgmt']:
316             raise configerror.ConfigError('No hwmgmt info defined for host')
317
318         return self.config[self.ROOT][hostname]['hwmgmt']['password']
319
320     def get_service_profiles(self, hostname):
321         """get the node service profiles
322
323            Arguments:
324
325            hostname: The name of the node
326
327            Return:
328
329            A list containing service profile names
330
331            Raise:
332
333            ConfigError in-case of an error
334         """
335         self._validate_hostname(hostname)
336
337         if 'service_profiles' not in self.config[self.ROOT][hostname]:
338             raise configerror.ConfigError('No service profiles found')
339
340         return self.config[self.ROOT][hostname]['service_profiles']
341
342     def get_performance_profiles(self, hostname):
343         """ get the performance profiles
344
345             Arguments:
346
347             hostname: The name of the node
348
349             Return:
350
351             A list containing the perfromance profile names.
352
353             Raise:
354
355             ConfigError in-case of an error
356         """
357         self._validate_hostname(hostname)
358
359         if 'performance_profiles' not in self.config[self.ROOT][hostname]:
360             raise configerror.ConfigError('No performance profiles found')
361
362         return self.config[self.ROOT][hostname]['performance_profiles']
363
364     def get_network_profiles(self, hostname):
365         """get the node network profiles
366
367            Arguments:
368
369            hostname: The name of the node
370
371            Return:
372
373            A list containing network profile names
374
375            Raise:
376
377            ConfigError in-case of an error
378         """
379         self._validate_hostname(hostname)
380
381         if 'network_profiles' not in self.config[self.ROOT][hostname]:
382             raise configerror.ConfigError('No network profiles found')
383
384         return self.config[self.ROOT][hostname]['network_profiles']
385
386     def get_storage_profiles(self, hostname):
387         """get the node storage profiles
388
389            Arguments:
390
391            hostname: The name of the node
392
393            Return:
394
395            A list containing storage profile names
396
397            Raise:
398
399            ConfigError in-case of an error
400         """
401         self._validate_hostname(hostname)
402
403         if 'storage_profiles' not in self.config[self.ROOT][hostname]:
404             raise configerror.ConfigError('No storage profiles found')
405
406         return self.config[self.ROOT][hostname]['storage_profiles']
407
408     def _validate_hostname(self, hostname):
409         if not self.is_valid_host(hostname):
410             raise configerror.ConfigError('Invalid hostname given %s' % hostname)
411
412     def is_valid_host(self, hostname):
413         """check if a host is valid
414
415            Arguments:
416
417            hostname: The name of the node
418
419            Return:
420
421            True or False
422
423            Raise:
424
425            ConfigError in-case of an error
426         """
427         self.validate_root()
428         if hostname in self.config[self.ROOT]:
429             return True
430         return False
431
432     def get_service_profile_hosts(self, profile):
433         """ get hosts having some service profile
434
435             Argument:
436
437             service profile name
438
439             Return:
440
441             A list of host names
442
443             Raise:
444
445             ConfigError in-case of an error
446         """
447         hosts = self.get_hosts()
448         result = []
449         for host in hosts:
450             node_profiles = self.get_service_profiles(host)
451             if profile in node_profiles:
452                 result.append(host)
453
454         return result
455
456     def get_network_profile_hosts(self, profile):
457         """ get hosts having some network profile
458
459             Argument:
460
461             network profile name
462
463             Return:
464
465             A list of host names
466
467             Raise:
468
469             ConfigError in-case of an error
470         """
471         hosts = self.get_hosts()
472         result = []
473         for host in hosts:
474             node_network_profiles = self.get_network_profiles(host)
475             if profile in node_network_profiles:
476                 result.append(host)
477         if not result:
478             raise configerror.ConfigError('No hosts found for profile %s' % profile)
479
480         return result
481
482     def get_performance_profile_hosts(self, profile):
483         """ get hosts having some performance profile
484
485             Argument:
486
487             performance profile name
488
489             Return:
490
491             A list of host names
492
493             Raise:
494
495             ConfigError in-case of an error
496         """
497         hosts = self.get_hosts()
498         result = []
499         for host in hosts:
500             node_performance_profiles = self.get_performance_profiles(host)
501             if profile in node_performance_profiles:
502                 result.append(host)
503         if not result:
504             raise configerror.ConfigError('No hosts found for profile %s' % profile)
505
506         return result
507
508     def get_storage_profile_hosts(self, profile):
509         """ get hosts having some storage profile
510
511             Argument:
512
513             storage profile name
514
515             Return:
516
517             A list of host names
518
519             Raise:
520
521             ConfigError in-case of an error
522         """
523         hosts = self.get_hosts()
524         result = []
525         for host in hosts:
526             try:
527                 node_storage_profiles = self.get_storage_profiles(host)
528                 if profile in node_storage_profiles:
529                     result.append(host)
530             except configerror.ConfigError:
531                 pass
532
533         if not result:
534             raise configerror.ConfigError('No hosts found for profile %s' % profile)
535
536         return result
537
538     def get_host_network_interface(self, host, network):
539         """ get the host interface used for some network
540
541             Argument:
542
543             the host name
544
545             the network name
546
547             Return:
548
549             The interface name
550
551             Raise:
552
553             ConfigError in-case of an error
554         """
555         node_network_profiles = self.get_network_profiles(host)
556         netprofconf = self.confman.get_network_profiles_config_handler()
557         for profile in node_network_profiles:
558             interfaces = netprofconf.get_profile_network_mapped_interfaces(profile)
559             for interface in interfaces:
560                 networks = netprofconf.get_profile_interface_mapped_networks(profile, interface)
561                 if network in networks:
562                     return interface
563
564         raise configerror.ConfigError('No interfaces found for network %s in host %s' % (network, host))
565
566     def get_host_network_ip_holding_interface(self, host, network):
567         """ get the host ip holding interface some network
568
569             Argument:
570
571             the host name
572
573             the network name
574
575             Return:
576
577             The interface name
578
579             Raise:
580
581             ConfigError in-case of an error
582         """
583         networkingconf = self.confman.get_networking_config_handler()
584         vlan = None
585         try:
586             domain = self.get_host_network_domain(host)
587             vlan = networkingconf.get_network_vlan_id(network, domain)
588         except configerror.ConfigError as exp:
589             pass
590
591         if vlan:
592             return 'vlan'+str(vlan)
593
594         return self.get_host_network_interface(host, network)
595
596     def get_host_networks(self, hostname):
597         """ get the host networks
598
599             Argument:
600
601             The host name
602
603             Return:
604
605             A list of network names
606
607             Raise:
608
609             ConfigError in-case of an error
610         """
611         node_network_profiles = self.get_network_profiles(hostname)
612         netprofconf = self.confman.get_network_profiles_config_handler()
613         result = []
614         for profile in node_network_profiles:
615             interfaces = netprofconf.get_profile_network_mapped_interfaces(profile)
616             for interface in interfaces:
617                 networks = netprofconf.get_profile_interface_mapped_networks(profile, interface)
618                 for network in networks:
619                     if network not in result:
620                         result.append(network)
621         if not result:
622             raise configerror.ConfigError('No networks found for host %s' % hostname)
623
624         return result
625
626     def get_host_having_hwmgmt_address(self, hwmgmtips):
627         """ get the node name matching an ipmi address
628
629             Argument:
630
631             The ipmi address
632
633             Return:
634
635             The node name
636
637             Raise:
638
639             ConfigError in-case of an error
640         """
641         import ipaddress
642         hosts = self.get_hosts()
643         for host in hosts:
644             ip = self.get_hwmgmt_ip(host)
645             for hwmgtip in hwmgmtips:
646                 addr=ipaddress.ip_address(unicode(hwmgtip))
647                 if addr.version == 6:
648                    hwmgtip=addr.compressed
649                    ip=ipaddress.ip_address(unicode(ip))
650                    ip=ip.compressed
651                 if ip == hwmgtip:
652                    return host
653         raise configerror.ConfigError('No hosts are matching the provided hw address %s' % hwmgmtips)
654
655     def set_installation_host(self, name):
656         """ set the installation node
657
658             Argument:
659
660             The installation node name
661
662             Raise:
663
664             ConfigError in-case of an error
665         """
666         self._validate_hostname(name)
667
668         self.config[self.ROOT][name]['installation_host'] = True
669
670     def is_installation_host(self, name):
671         """ get if the node is an installation node
672
673             Argument:
674
675             The node name
676
677             Return:
678
679             True if installation node
680
681             Raise:
682
683             ConfigError in-case of an error
684         """
685         self._validate_hostname(name)
686
687         if 'installation_host' in self.config[self.ROOT][name]:
688             return self.config[self.ROOT][name]['installation_host']
689
690         return False
691
692     def get_installation_host(self):
693         """ get the name of the node used for installation
694
695             Return:
696
697             The node name
698
699             Raise:
700
701             ConfigError in-case of an error
702         """
703         hosts = self.get_hosts()
704         for host in hosts:
705             if self.is_installation_host(host):
706                 return host
707
708         raise configerror.ConfigError('No installation host found')
709
710     def disable_host(self, host):
711         """ disable the hosts visible via configuration.
712             This can be used in bootstrapping phase.
713
714             Argument:
715
716             host to disable
717
718             Raise:
719
720             ConfigError in-case if provided host is not valid
721         """
722         self._validate_hostname(host)
723
724         self.config[self.ROOT][host]['disabled'] = True
725
726     def enable_host(self, host):
727         """ enable  the hosts visible via configuration.
728             This can be used in bootstrapping phase.
729
730             Argument:
731
732             host to enable
733
734             Raise:
735
736             ConfigError in-case if provided host is not valid
737         """
738         self._validate_hostname(host)
739
740         self.config[self.ROOT][host]['disabled'] = False
741
742     def is_host_enabled(self, host):
743         """ is the host enabled
744
745             Argument:
746
747             the host to be checked
748
749             Raise:
750
751             ConfigError in-case if provided host is not valid
752         """
753         self._validate_hostname(host)
754
755         if 'disabled' in self.config[self.ROOT][host]:
756             return not self.config[self.ROOT][host]['disabled']
757
758         return True
759
760     def get_mgmt_mac(self, host):
761         self._validate_hostname(host)
762
763         if 'mgmt_mac' in self.config[self.ROOT][host]:
764             return self.config[self.ROOT][host]['mgmt_mac']
765         return []
766
767     def get_host_network_domain(self, host):
768         self._validate_hostname(host)
769         if 'network_domain' not in self.config[self.ROOT][host]:
770             raise configerror.ConfigError('Missing network domain for host %s' % host)
771         return self.config[self.ROOT][host]['network_domain']
772
773     def get_controllers_network_domain(self):
774         controllers = self.get_service_profile_hosts('controller')
775         domains = set()
776         for controller in controllers:
777             domains.add(self.get_host_network_domain(controller))
778
779         if len(domains) != 1:
780             raise configerror.ConfigError('Controllers in different networking domains not supported')
781         return domains.pop()
782
783     def get_managements_network_domain(self):
784         managements = self.get_service_profile_hosts('management')
785         domains = set()
786         for management in managements:
787             domains.add(self.get_host_network_domain(management))
788         if len(domains) != 1:
789             raise configerror.ConfigError('Management in different networking domains not supported')
790         return domains.pop()
791
792     def update_service_profiles(self):
793         profs = profiles.Profiles()
794         hosts = self.get_hosts()
795         for host in hosts:
796             new_profiles = []
797             current_profiles = self.config[self.ROOT][host]['service_profiles']
798             new_profiles = current_profiles
799             for profile in current_profiles:
800                 included_profiles = profs.get_included_profiles(profile)
801                 new_profiles = utils.add_lists(new_profiles, included_profiles)
802             self.config[self.ROOT][host]['service_profiles'] = new_profiles
803
804     def get_pre_allocated_ips(self, host, network):
805         ips_field = "pre_allocated_ips"
806         self._validate_hostname(host)
807         if (ips_field not in self.config[self.ROOT][host]
808                 or network not in self.config[self.ROOT][host][ips_field]):
809             return None
810         return self.config[self.ROOT][host][ips_field][network]
811
812     def allocate_port(self, host, base, name):
813         used_ports = []
814         hosts = self.get_hosts()
815         for node in hosts:
816             if name in self.config[self.ROOT][node]:
817                 used_ports.append(self.config[self.ROOT][node][name])
818
819         free_port = 0
820
821         for port in range(base, base+1000):
822             if port not in used_ports:
823                 free_port = port
824                 break
825
826         if free_port == 0:
827             raise configerror.ConfigError('No free ports available')
828
829         self.config[self.ROOT][host][name] = free_port
830
831     def add_vbmc_port(self, host):
832         base_vbmc_port = 61600
833         name = 'vbmc_port'
834         self._validate_hostname(host)
835         if name not in self.config[self.ROOT][host]:
836             self.allocate_port(host, base_vbmc_port, name)
837
838     def add_ipmi_terminal_port(self, host):
839         base_console_port = 61401
840         name = 'ipmi_terminal_port'
841         self._validate_hostname(host)
842         if name not in self.config[self.ROOT][host]:
843             self.allocate_port(host, base_console_port, name)
844
845     def get_ceph_osd_disks(self, host):
846         self._validate_hostname(host)
847         caas_disks = self.config[self.ROOT][host].get('caas_disks', [])
848         osd_disks = filter(lambda disk: disk.get('osd_disk', False), caas_disks)
849         return map(lambda disk: _get_path_for_virtio_id(disk), osd_disks)
850
851     def get_system_reserved_memory(self, hostname):
852         caasconf = self.confman.get_caas_config_handler()
853         if caasconf.is_vnf_embedded_deployment():
854             return VNF_EMBEDDED_RESERVED_MEMORY
855
856         profiles = self.get_service_profiles(hostname)
857         if 'controller' in profiles:
858             return DUAL_VIM_CONTROLLER_RESERVED_MEMORY
859         if 'compute' in profiles:
860             return DUAL_VIM_DEFAULT_RESERVED_MEMORY
861
862         return self.config.get(self.ROOT, {}).get('middleware_reserved_memory',
863                                                    MIDDLEWARE_RESERVED_MEMORY)
864
865     def set_default_reserved_memory_to_all_hosts(self, def_memory):
866         for host in self.get_hosts():
867             self.config[self.ROOT][host]['middleware_reserved_memory'] = def_memory
868
869     def set_default_ipmi_priv_level_to_all_hosts(self, def_priv):
870         for host in self.get_hosts():
871             if 'hwmgmt' not in self.config[self.ROOT][host]:
872                 self.config[self.ROOT][host]['hwmgmt'] = {'priv_level': def_priv}
873             elif 'priv_level' not in self.config[self.ROOT][host]['hwmgmt']:
874                 self.config[self.ROOT][host]['hwmgmt']['priv_level'] = def_priv
875
876
877 def _get_path_for_virtio_id(disk):
878     disk_id = disk.get('id', '')
879     if disk_id:
880         return "/dev/disk/by-id/virtio-{}".format(disk_id[:20])
881
882