Debian Codegraph @

lib/ansible/module_utils/facts/hardware/base.py

raw
1 # This code is part of Ansible, but is an independent component.
2 # This particular file snippet, and this file snippet only, is BSD licensed.
3 # Modules you write using this snippet, which is embedded dynamically by Ansible
4 # still belong to the author of the module, and may assign their own license
5 # to the complete work.
6 #
7 # (c) 2017 Red Hat Inc.
8 #
9 # Redistribution and use in source and binary forms, with or without modification,
10 # are permitted provided that the following conditions are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above copyright notice,
15 # this list of conditions and the following disclaimer in the documentation
16 # and/or other materials provided with the distribution.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
26 # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #
28
29 from __future__ import annotations
30
31 import typing as t
32
33 from ansible.module_utils.facts.collector import BaseFactCollector
34
35
36 class Hardware:
37 platform = 'Generic'
38
39 # FIXME: remove load_on_init when we can
40 def __init__(self, module, load_on_init=False):
41 self.module = module
42
43 def populate(self, collected_facts=None):
44 return {}
45
46
47 class HardwareCollector(BaseFactCollector):
48 name = 'hardware'
49 _fact_ids = set(['processor',
50 'processor_cores',
51 'processor_count',
52 # TODO: mounts isn't exactly hardware
53 'mounts',
54 'devices']) # type: t.Set[str]
55 _fact_class = Hardware
56
57 def collect(self, module=None, collected_facts=None):
58 collected_facts = collected_facts or {}
59 if not module:
60 return {}
61
62 # Network munges cached_facts by side effect, so give it a copy
63 facts_obj = self._fact_class(module)
64
65 facts_dict = facts_obj.populate(collected_facts=collected_facts)
66
67 return facts_dict