mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #8713/0f59bb7a backport][stable-9] Get interfaces for Proxmox LXC containers (#8750)
Get interfaces for Proxmox LXC containers (#8713)
* Get interfaces for Proxmox LXC containers
* Add changelog
* Don't use bare except
* Update changelog from suggestion
Co-authored-by: Felix Fontein <felix@fontein.de>
* Only lookup interfaces for running containers
* Ignore not implemented status
* Check that key exists in properties dict
* define ignore errors in mock
* Use not in
---------
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 0f59bb7a99
)
Co-authored-by: Scott Langendyk <scott@langendyk.com>
This commit is contained in:
parent
825bd81e44
commit
7d23c90c6e
3 changed files with 34 additions and 1 deletions
2
changelogs/fragments/8713-proxmox_lxc_interfaces.yml
Normal file
2
changelogs/fragments/8713-proxmox_lxc_interfaces.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- proxmox inventory plugin - add new fact for LXC interface details (https://github.com/ansible-collections/community.general/pull/8713).
|
|
@ -362,6 +362,34 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
except Exception:
|
||||
return None
|
||||
|
||||
def _get_lxc_interfaces(self, properties, node, vmid):
|
||||
status_key = self._fact('status')
|
||||
|
||||
if status_key not in properties or not properties[status_key] == 'running':
|
||||
return
|
||||
|
||||
ret = self._get_json("%s/api2/json/nodes/%s/lxc/%s/interfaces" % (self.proxmox_url, node, vmid), ignore_errors=[501])
|
||||
if not ret:
|
||||
return
|
||||
|
||||
result = []
|
||||
|
||||
for iface in ret:
|
||||
result_iface = {
|
||||
'name': iface['name'],
|
||||
'hwaddr': iface['hwaddr']
|
||||
}
|
||||
|
||||
if 'inet' in iface:
|
||||
result_iface['inet'] = iface['inet']
|
||||
|
||||
if 'inet6' in iface:
|
||||
result_iface['inet6'] = iface['inet6']
|
||||
|
||||
result.append(result_iface)
|
||||
|
||||
properties[self._fact('lxc_interfaces')] = result
|
||||
|
||||
def _get_agent_network_interfaces(self, node, vmid, vmtype):
|
||||
result = []
|
||||
|
||||
|
@ -526,6 +554,9 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
self._get_vm_config(properties, node, vmid, ittype, name)
|
||||
self._get_vm_snapshots(properties, node, vmid, ittype, name)
|
||||
|
||||
if ittype == 'lxc':
|
||||
self._get_lxc_interfaces(properties, node, vmid)
|
||||
|
||||
# ensure the host satisfies filters
|
||||
if not self._can_add_host(name, properties):
|
||||
return None
|
||||
|
|
|
@ -37,7 +37,7 @@ def get_auth():
|
|||
|
||||
# NOTE: when updating/adding replies to this function,
|
||||
# be sure to only add only the _contents_ of the 'data' dict in the API reply
|
||||
def get_json(url):
|
||||
def get_json(url, ignore_errors=None):
|
||||
if url == "https://localhost:8006/api2/json/nodes":
|
||||
# _get_nodes
|
||||
return [{"type": "node",
|
||||
|
|
Loading…
Reference in a new issue