Skip to content

opennebula inventory: add VM ID and VM host to data #8532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- opennebula.py - add VM ``id`` and VM ``host`` to inventory host data (https://github.com/ansible-collections/community.general/pull/8532).
3 changes: 3 additions & 0 deletions plugins/inventory/opennebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ def _retrieve_servers(self, label_filter=None):
continue

server['name'] = vm.NAME
server['id'] = vm.ID
if hasattr(vm.HISTORY_RECORDS, 'HISTORY'):
server['host'] = vm.HISTORY_RECORDS.HISTORY[-1].HOSTNAME
server['LABELS'] = labels
server['v4_first_ip'] = self._get_vm_ipv4(vm)
server['v6_first_ip'] = self._get_vm_ipv6(vm)
Expand Down
23 changes: 20 additions & 3 deletions tests/unit/plugins/inventory/test_opennebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,23 @@
from ansible_collections.community.general.tests.unit.compat.mock import create_autospec


class HistoryEntry(object):
def __init__(self):
self.SEQ = '384'
self.HOSTNAME = 'sam-691-sam'
self.HID = '10'
self.CID = '0'
self.DS_ID = '100'
self.VM_MAD = 'kvm'
self.TM_MAD = '3par'
self.ACTION = '0'


class HistoryRecords(object):
def __init__(self):
self.HISTORY = [HistoryEntry()]


@pytest.fixture
def inventory():
r = InventoryModule()
Expand Down Expand Up @@ -58,7 +75,7 @@ def get_vm_pool():
'ETIME': 0,
'GID': 132,
'GNAME': 'CSApparelVDC',
'HISTORY_RECORDS': {},
'HISTORY_RECORDS': HistoryRecords(),
'ID': 7157,
'LAST_POLL': 1632762935,
'LCM_STATE': 3,
Expand Down Expand Up @@ -104,7 +121,7 @@ def get_vm_pool():
'ETIME': 0,
'GID': 0,
'GNAME': 'oneadmin',
'HISTORY_RECORDS': {},
'HISTORY_RECORDS': [],
'ID': 327,
'LAST_POLL': 1632763543,
'LCM_STATE': 3,
Expand Down Expand Up @@ -167,7 +184,7 @@ def get_vm_pool():
'ETIME': 0,
'GID': 0,
'GNAME': 'oneadmin',
'HISTORY_RECORDS': {},
'HISTORY_RECORDS': [],
'ID': 107,
'LAST_POLL': 1632764186,
'LCM_STATE': 3,
Expand Down