-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
opennebula inventory: add VM id and VM host to data #8532
base: main
Are you sure you want to change the base?
Conversation
##### 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, ```
Not sure why the tests are failing as I'm not adding a new import for the pyone library...? |
Hi, problem is, that you added new method which is calling pyone package. To pass test, you need to also update tests to reflect this. Anyway, for such infromation - host on which is VM running, there is easier method to get this. It is already in VM object, in history records, you just need to get last history record of VM to get host. So no need to do aditional api call and searching for host. |
@feldsam updated PR to reflect the new information you provided. It's a very simple PR now! I'm afraid I don't understand how to fix the tests. |
changelogs/fragments/8532-expand-opennuebula-inventory-data.yml
Outdated
Show resolved
Hide resolved
Co-authored-by: Felix Fontein <[email protected]>
Co-authored-by: Felix Fontein <[email protected]>
'HISTORY_RECORDS': [ | ||
{ | ||
'HISTORY': OrderedDict({ | ||
'OID': '42', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This data structure looks very different from what the code is actually using. Here HISTORY_RECORDS
is a list of dictionaries with a key HISTORY
in them, and that in turn gives a dictionary with a key HOSTNAME
in it.
The code expects HISTORY_RECORDS
to be an object with an attribute HISTORY
, which is a list, and contains objects that have an attribute called HOSTNAME
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid I'm completely lost, this is way beyond my ability. Hoping the original author @feldsam can help.
'HISTORY_RECORDS': [ | ||
{ | ||
'HISTORY': OrderedDict({ | ||
'OID': '42', | ||
'SEQ': '384', | ||
'HOSTNAME': 'sam-691-sam', | ||
'HID': '10', | ||
'CID': '0', | ||
'DS_ID': '100', | ||
'VM_MAD': 'kvm', | ||
'TM_MAD': '3par', | ||
'ACTION': '0' | ||
}), | ||
} | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like:
'HISTORY_RECORDS': [ | |
{ | |
'HISTORY': OrderedDict({ | |
'OID': '42', | |
'SEQ': '384', | |
'HOSTNAME': 'sam-691-sam', | |
'HID': '10', | |
'CID': '0', | |
'DS_ID': '100', | |
'VM_MAD': 'kvm', | |
'TM_MAD': '3par', | |
'ACTION': '0' | |
}), | |
} | |
], | |
'HISTORY_RECORDS': { | |
'HISTORY' : [ | |
{ | |
'OID': '42', | |
'SEQ': '384', | |
'HOSTNAME': 'sam-691-sam', | |
'HID': '10', | |
'CID': '0', | |
'DS_ID': '100', | |
'VM_MAD': 'kvm', | |
'TM_MAD': '3par', | |
'ACTION': '0', | |
}, | |
], | |
}, |
By the way, this construct OrderedDict({ ... })
that appears throughout this test code is likely redundant, they could all be replaced with the dict
content {...}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @russoz. Since my opennebula.py
inventory change does work when run against OpenNebula servers, I am reasonably sure that changing HISTORY_RECORDS back to a {} rather than a [] will break the test, which means it doesn't reflect the actual data structure that ON returns.
If the code is working and the tests are currently passing, is this PR 'good enough' now?
I'm quite burnt out on it and don't want to make myself dislike adding features as I'll be using Open Nebula for the next year plus!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @russoz. Since my
opennebula.py
inventory change does work when run against OpenNebula servers, I am reasonably sure that changing HISTORY_RECORDS back to a {} rather than a [] will break the test, which means it doesn't reflect the actual data structure that ON returns.If the code is working and the tests are currently passing, is this PR 'good enough' now?
Well, the concern is that the piece of code that seems to parse that data goes like this:
if hasattr(vm.HISTORY_RECORDS, 'HISTORY'):
if isinstance(vm.HISTORY_RECORDS.HISTORY, Sequence) and len(vm.HISTORY_RECORDS.HISTORY) > 0:
if hasattr(vm.HISTORY_RECORDS.HISTORY[-1], 'HOSTNAME'):
server['host'] = vm.HISTORY_RECORDS.HISTORY[-1].HOSTNAME
That seems to indicate that HISTORY_RECORDS
has an attribute HISTORY
, which in its turn is a Sequence (with at least one element), from which you select the last element, and the attribute HOSTNAME
out of it. That looks not coherent with the statement that HISTORY_RECORDS
is a list. Could you please explain why that difference?
People other than you (me, Felix, @feldsam and future maintainers of the collection) will need to provide support to this code for potentially a long time and we cannot explain it. Either we are missing some piece of the puzzle, or the test might doing the wrong thing.
So, answering your question, to be 'good enough' we need to understand what's happening. Hope you don't take this badly, but the long-term health of the code is more important than short-term results.
I'm quite burnt out on it and don't want to make myself dislike adding features as I'll be using Open Nebula for the next year plus!
Sorry to hear that, hope you can find some time to decompress. There is no pressure from our side to solve this quickly, so take your time.
All the best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like that should produce the data structure that the inventory plugin actually expects:
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()]
def get_vm_pool():
...
'HISTORY_RECORDS': HistoryRecords(),
...
SUMMARY
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 outputISSUE TYPE
COMPONENT NAME
opennebula.pyADDITIONAL INFORMATION