-
Notifications
You must be signed in to change notification settings - Fork 681
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
Add option to search for interface names in ganeti run-time to kvm_net #946
base: master
Are you sure you want to change the base?
Add option to search for interface names in ganeti run-time to kvm_net #946
Conversation
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.
Thank you for taking the time to improve this plugin!
Please take a look at my comments below.
@@ -148,7 +168,6 @@ def detect_kvm(): | |||
|
|||
def find_vm_names(pids): | |||
"""Find and clean vm names from pids | |||
|
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.
@@ -29,7 +29,8 @@ In all other cases you need to use other munin plugins instead, e.g. "libvirt". | |||
parsed environment variables: | |||
|
|||
* vmsuffix: part of vm name to be removed | |||
|
|||
* ganeti: True/False (default False), use ganeti run-time information to resolve |
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.
Please use a more descriptive name for the specific purpose (maybe there will be more ganeti-related features in the future).
How about: use_ganeti_nic_name_map
?
@@ -136,9 +137,28 @@ def get_vm_network_interface_names(pid): | |||
match = KVM_INTERFACE_NAME_REGEX.search(netdev_description) | |||
if match: | |||
result.add(match.groups()[0]) | |||
if os.getenv('ganeti'): |
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.
Please use a non-surprising parsing approach. E.g. here you would interprete ganeti=0
as True
.
How about the following instead?
bool(distutils.util.strtobool(os.getenv("ganeti", "False")))
if os.getenv('ganeti'): | ||
vm_name = _get_ganeti_vm_name(pid) | ||
if vm_name: | ||
for root, dirs, files in os.walk('/var/run/ganeti/kvm-hypervisor/nic/{0}'.format(vm_name)): |
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.
Please move this part of the code (walking through the ganeti directories) into the _get_ganeti_vm_name
function. This keeps the ganeti-related code in a single place.
read_pid = f.read() | ||
if int(read_pid) == int(pid): | ||
vm_name = name | ||
break |
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 think, a quite pythonic approach would be to return name
here and add return ""
after the loop.
The break
that you used instead, is usually harder to comprehend and requires more context.
vm_name = name | ||
break | ||
return vm_name | ||
|
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.
Please follow PEP8 and add two empty lines here.
python3 -m flake8 FILENAME
is a good test for compliance.
Ping? |
Stale pull request message |
Ping? |
Virtual machines started using ganeti have the NICs defined in the command line by hotplug IDs. The mapping of interfaces -> virtual machine is stored in the the ganeti run-time directory. Searching for ganeti interface mappings is disabled by default.