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