Debian Codegraph @

lib/ansible/module_utils/facts/network/nvme.py

raw
1 # NVMe initiator related facts collection for Ansible.
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import annotations
19
20 import sys
21 import typing as t
22
23 from ansible.module_utils.facts.utils import get_file_content
24 from ansible.module_utils.facts.network.base import NetworkCollector
25
26
27 class NvmeInitiatorNetworkCollector(NetworkCollector):
28 name = 'nvme'
29 _fact_ids = set() # type: t.Set[str]
30
31 def collect(self, module=None, collected_facts=None):
32 """
33 Currently NVMe is only supported in some Linux distributions.
34 If NVMe is configured on the host then a file will have been created
35 during the NVMe driver installation. This file holds the unique NQN
36 of the host.
37
38 Example of contents of /etc/nvme/hostnqn:
39
40 # cat /etc/nvme/hostnqn
41 nqn.2014-08.org.nvmexpress:fc_lif:uuid:2cd61a74-17f9-4c22-b350-3020020c458d
42
43 """
44
45 nvme_facts = {}
46 nvme_facts['hostnqn'] = ""
47 if sys.platform.startswith('linux'):
48 for line in get_file_content('/etc/nvme/hostnqn', '').splitlines():
49 if line.startswith('#') or line.startswith(';') or line.strip() == '':
50 continue
51 if line.startswith('nqn.'):
52 nvme_facts['hostnqn'] = line
53 break
54 return nvme_facts