Debian Codegraph @

ansible_collections/cisco/iosxr/plugins/modules/iosxr_facts.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2019 Red Hat
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6 """
7 The module file for iosxr_facts
8 """
9
10 from __future__ import absolute_import, division, print_function
11
12
13 __metaclass__ = type
14
15
16 DOCUMENTATION = """
17 module: iosxr_facts
18 short_description: Module to collect facts from remote devices.
19 extends_documentation_fragment:
20 - cisco.iosxr.iosxr
21 description:
22 - Collects facts from network devices running the iosxr operating system. This module
23 places the facts gathered in the fact tree keyed by the respective resource name. The
24 facts module will always collect a base set of facts from the device and can enable
25 or disable collection of additional facts.
26 version_added: 1.0.0
27 notes:
28 - This module works with connection C(network_cli). See L(the IOS-XR Platform Options,../network/user_guide/platform_iosxr.html).
29 author:
30 - Ricardo Carrillo Cruz (@rcarrillocruz)
31 - Nilashish Chakraborty (@Nilashishc)
32 options:
33 gather_subset:
34 description:
35 - When supplied, this argument will restrict the facts collected to a given subset. Possible
36 values for this argument include all, hardware, config, and interfaces. Can
37 specify a list of values to include a larger subset. Values can also be used
38 with an initial C(!) to specify that a specific subset should not be collected.
39 required: false
40 default: 'min'
41 type: list
42 elements: str
43 gather_network_resources:
44 description:
45 - When supplied, this argument will restrict the facts collected to a given subset.
46 Possible values for this argument include all and the resources like interfaces,
47 lacp etc. Can specify a list of values to include a larger subset. Values can
48 also be used with an initial C(!) to specify that a specific subset should
49 not be collected. Valid subsets are 'all', 'lacp', 'lacp_interfaces', 'lldp_global',
50 'lldp_interfaces', 'interfaces', 'l2_interfaces', 'l3_interfaces', 'lag_interfaces',
51 'acls', 'acl_interfaces', 'static_routes', 'ospfv2'.
52 required: false
53 type: list
54 elements: str
55 available_network_resources:
56 description: When 'True' a list of network resources for which resource modules are available will be provided.
57 type: bool
58 default: false
59 """
60
61 EXAMPLES = """
62 # Gather all facts
63 - cisco.iosxr.iosxr_facts:
64 gather_subset: all
65 gather_network_resources: all
66
67 # Collect only the config and default facts
68 - cisco.iosxr.iosxr_facts:
69 gather_subset:
70 - config
71
72 # Do not collect hardware facts
73 - cisco.iosxr.iosxr_facts:
74 gather_subset:
75 - '!hardware'
76
77 # Collect only the lacp facts
78 - cisco.iosxr.iosxr_facts:
79 gather_subset:
80 - '!all'
81 - '!min'
82 gather_network_resources:
83 - lacp
84
85 # Do not collect lacp_interfaces facts
86 - cisco.iosxr.iosxr_facts:
87 gather_network_resources:
88 - '!lacp_interfaces'
89
90 # Collect lacp and minimal default facts
91 - cisco.iosxr.iosxr_facts:
92 gather_subset: min
93 gather_network_resources: lacp
94
95 # Collect only the interfaces facts
96 - cisco.iosxr.iosxr_facts:
97 gather_subset:
98 - '!all'
99 - '!min'
100 gather_network_resources:
101 - interfaces
102 - l2_interfaces
103 """
104
105 RETURN = """
106 ansible_net_gather_subset:
107 description: The list of fact subsets collected from the device
108 returned: always
109 type: list
110
111 # default
112 ansible_net_version:
113 description: The operating system version running on the remote device
114 returned: always
115 type: str
116 ansible_net_hostname:
117 description: The configured hostname of the device
118 returned: always
119 type: str
120 ansible_net_image:
121 description: The image file the device is running
122 returned: always
123 type: str
124 ansible_net_api:
125 description: The name of the transport
126 returned: always
127 type: str
128 ansible_net_python_version:
129 description: The Python version Ansible controller is using
130 returned: always
131 type: str
132 ansible_net_model:
133 description: The model name returned from the device
134 returned: always
135 type: str
136
137 # hardware
138 ansible_net_filesystems:
139 description: All file system names available on the device
140 returned: when hardware is configured
141 type: list
142 ansible_net_memfree_mb:
143 description: The available free memory on the remote device in Mb
144 returned: when hardware is configured
145 type: int
146 ansible_net_memtotal_mb:
147 description: The total memory on the remote device in Mb
148 returned: when hardware is configured
149 type: int
150 ansible_net_cpu_utilization:
151 description: The current CPU utilization of the device
152 returned: when hardware is configured
153 type: dict
154
155 # config
156 ansible_net_config:
157 description: The current active config from the device
158 returned: when config is configured
159 type: str
160
161 # interfaces
162 ansible_net_all_ipv4_addresses:
163 description: All IPv4 addresses configured on the device
164 returned: when interfaces is configured
165 type: list
166 ansible_net_all_ipv6_addresses:
167 description: All IPv6 addresses configured on the device
168 returned: when interfaces is configured
169 type: list
170 ansible_net_interfaces:
171 description: A hash of all interfaces running on the system
172 returned: when interfaces is configured
173 type: dict
174 ansible_net_neighbors:
175 description: The list of LLDP and CDP neighbors from the remote device. If both,
176 CDP and LLDP neighbor data is present on one port, CDP is preferred.
177 returned: when interfaces is configured
178 type: dict
179
180 # network resources
181 ansible_net_gather_network_resources:
182 description: The list of fact resource subsets collected from the device
183 returned: always
184 type: list
185 """
186
187 from ansible.module_utils.basic import AnsibleModule
188
189 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.argspec.facts.facts import (
190 FactsArgs,
191 )
192 from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.facts.facts import (
193 FACT_RESOURCE_SUBSETS,
194 Facts,
195 )
196
197
198 def main():
199 """
200 Main entry point for module execution
201
202 :returns: ansible_facts
203 """
204 argument_spec = FactsArgs.argument_spec
205
206 module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
207
208 warnings = []
209
210 ansible_facts = {}
211 if module.params.get("available_network_resources"):
212 ansible_facts["available_network_resources"] = sorted(FACT_RESOURCE_SUBSETS.keys())
213 result = Facts(module).get_facts()
214 additional_facts, additional_warnings = result
215 ansible_facts.update(additional_facts)
216 warnings.extend(additional_warnings)
217
218 module.exit_json(ansible_facts=ansible_facts, warnings=warnings)
219
220
221 if __name__ == "__main__":
222 main()