opennebula inventory: add VM ID and VM host to data (#8532)
* Add VM id and VM host to opennebula inventory data ##### SUMMARY <!--- Describe the change below, including rationale and design decisions --> To enable greater use of the inventory, add the ID of the VM, and the hostname of the host the VM is running on to the inventory output <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue --> <!--- Please do not forget to include a changelog fragment: https://docs.ansible.com/ansible/devel/community/collection_development_process.html#creating-changelog-fragments No need to include one for docs-only or test-only PR, and for new plugin/module PRs. Read about more details in CONTRIBUTING.md. --> ##### ISSUE TYPE <!--- Pick one or more below and delete the rest. 'Test Pull Request' is for PRs that add/extend tests without code changes. --> - Feature Pull Request ##### COMPONENT NAME <!--- Write the SHORT NAME of the module, plugin, task or feature below. --> opennebula.py ##### ADDITIONAL INFORMATION <!--- Include additional information to help people understand the change here --> <!--- A step-by-step reproduction of the problem is helpful if there is no related issue --> <!--- Paste verbatim command output below, e.g. before and after your change --> ```paste below "host": "foo23.host", "id": 1234, ``` * Create 8532-expand-opennuebula-inventory-data.yml * Update opennebula.py * Update changelogs/fragments/8532-expand-opennuebula-inventory-data.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Add check for empty records and add test * fix attribute test * fix attribute test * fix attribute test * fix attribute test * Update plugins/inventory/opennebula.py Co-authored-by: Felix Fontein <felix@fontein.de> * update as per guidance * restore attribute checks * fix attr * fix indent * PR Fixes * add attribute check in case of empty variable --------- Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Александр Бакановский <abakanovskii@astralinux.ru>pull/9012/head
parent
c814fd0530
commit
24b74cc4b9
|
@ -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).
|
|
@ -199,6 +199,9 @@ class InventoryModule(BaseInventoryPlugin, Constructable):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
server['name'] = vm.NAME
|
server['name'] = vm.NAME
|
||||||
|
server['id'] = vm.ID
|
||||||
|
if hasattr(vm.HISTORY_RECORDS, 'HISTORY') and vm.HISTORY_RECORDS.HISTORY:
|
||||||
|
server['host'] = vm.HISTORY_RECORDS.HISTORY[-1].HOSTNAME
|
||||||
server['LABELS'] = labels
|
server['LABELS'] = labels
|
||||||
server['v4_first_ip'] = self._get_vm_ipv4(vm)
|
server['v4_first_ip'] = self._get_vm_ipv4(vm)
|
||||||
server['v6_first_ip'] = self._get_vm_ipv6(vm)
|
server['v6_first_ip'] = self._get_vm_ipv6(vm)
|
||||||
|
|
|
@ -21,6 +21,23 @@ from ansible_collections.community.general.plugins.inventory.opennebula import I
|
||||||
from ansible_collections.community.general.tests.unit.compat.mock import create_autospec
|
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
|
@pytest.fixture
|
||||||
def inventory():
|
def inventory():
|
||||||
r = InventoryModule()
|
r = InventoryModule()
|
||||||
|
@ -58,7 +75,7 @@ def get_vm_pool():
|
||||||
'ETIME': 0,
|
'ETIME': 0,
|
||||||
'GID': 132,
|
'GID': 132,
|
||||||
'GNAME': 'CSApparelVDC',
|
'GNAME': 'CSApparelVDC',
|
||||||
'HISTORY_RECORDS': {},
|
'HISTORY_RECORDS': HistoryRecords(),
|
||||||
'ID': 7157,
|
'ID': 7157,
|
||||||
'LAST_POLL': 1632762935,
|
'LAST_POLL': 1632762935,
|
||||||
'LCM_STATE': 3,
|
'LCM_STATE': 3,
|
||||||
|
@ -104,7 +121,7 @@ def get_vm_pool():
|
||||||
'ETIME': 0,
|
'ETIME': 0,
|
||||||
'GID': 0,
|
'GID': 0,
|
||||||
'GNAME': 'oneadmin',
|
'GNAME': 'oneadmin',
|
||||||
'HISTORY_RECORDS': {},
|
'HISTORY_RECORDS': [],
|
||||||
'ID': 327,
|
'ID': 327,
|
||||||
'LAST_POLL': 1632763543,
|
'LAST_POLL': 1632763543,
|
||||||
'LCM_STATE': 3,
|
'LCM_STATE': 3,
|
||||||
|
@ -167,7 +184,7 @@ def get_vm_pool():
|
||||||
'ETIME': 0,
|
'ETIME': 0,
|
||||||
'GID': 0,
|
'GID': 0,
|
||||||
'GNAME': 'oneadmin',
|
'GNAME': 'oneadmin',
|
||||||
'HISTORY_RECORDS': {},
|
'HISTORY_RECORDS': [],
|
||||||
'ID': 107,
|
'ID': 107,
|
||||||
'LAST_POLL': 1632764186,
|
'LAST_POLL': 1632764186,
|
||||||
'LCM_STATE': 3,
|
'LCM_STATE': 3,
|
||||||
|
|
Loading…
Reference in New Issue