Skip to content
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

kvm plugins improvements #186

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

duritong
Copy link

I added a few improvements to the kvm plugins:

  • Make most of them also work on RedHat based systems
  • Add an additional kvm_net_rh Plugin that works on RedHat bases systems. It is more or less a copy of the existing kvm_net plugin, which does not work and which needed to many changes which I'm not sure would have broken things further.

@ssm
Copy link
Member

ssm commented Oct 5, 2014

Closing and opening old pull request, to have it tested by travis-ci.

@ssm ssm closed this Oct 5, 2014
@ssm ssm reopened this Oct 5, 2014
res = {}
macs_to_inf = find_macs_to_inf()
interfaces = {}
for e in Popen('cat /proc/net/dev | awk \'{ print $1 ":" $9 }\'', shell=True, stdout=PIPE).communicate()[0].split('\n'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems to contain a bug, which should be fixed before we can merge.

% cat /proc/net/dev | awk '{ print $1 ":" $9 }'    
Inter-|:
face:multicast|bytes
eth0::0
eth1::5246
virbr0::0
lo::0

The format on my box is:

% cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
  eth0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
  eth1: 3833806033 3143411    0    0    0     0          0      5246 168429641 1939069    0    0    0     0       0          0
virbr0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0
    lo: 86071620  477326    0    0    0     0          0         0 86071620  477326    0    0    0     0       0          0

...which looks more human-readable than strictly parsable.

On a reasonably modern linux kernel, perhaps what you can find with "find /sys/class/net/*/statistics/" may be more useful.

@sumpfralle
Copy link
Collaborator

@duritong: are you still interested in this pull request? What do you think about the issues above?

@duritong
Copy link
Author

duritong commented Dec 1, 2016

So I reworked the whole stuff and I hope problems to be solved by now

Copy link
Collaborator

@sumpfralle sumpfralle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on these plugins!

I added some suggestions.

Regarding the red-hat-specific(?) plugin: what is the difference between this one and the general kvm_net plugin?
Maybe you could merge these into a single plugin handling both cases? Working with code copies is (as you already noticed with the other plugins) a burden, that should be avoided, if possible.

else:
kvm = Popen("which kvm", shell=True, stdout=PIPE)
kvm.communicate()
return not bool(kvm.returncode)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would propose to phrase this clearer (instead of relying on the coincidence of the implicit interger/boolean conversion):
return kvm.returncode == 0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change the original behavior. Just added one that fits more for RHEL/CentOS.
In general this part is from my point of view problematic in 2 cases:

  1. which lookups are expensive
  2. we're not only looking at kvm.

I can change it in general, but as I said the intend of my PR was not to change the original behavior. But I can come up with general improvements, if people would like to see that.

def list_pids():
''' Find the pid of kvm processes
@return a list of pids from running kvm
'''
pid = Popen("pidof qemu-system-x86_64", shell=True, stdout=PIPE)
pid = Popen("pidof qemu-kvm qemu-system-x86_64 kvm", shell=True, stdout=PIPE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this list of names lack "qemu-system-i386"?
Other architectures are probably not available due to kvm being bound to intel/amd - right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above I did not change the original behavior. So I just kept qemu-system-x86_64 as it was the current behavior. I can add though other architectures as well.

else:
kvm = Popen("which kvm", shell=True, stdout=PIPE)
kvm.communicate()
return not bool(kvm.returncode)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

def list_pids():
''' Find the pid of kvm processes
@return a list of pids from running kvm
'''
pid = Popen("pidof qemu-system-x86_64", shell=True, stdout=PIPE)
pid = Popen("pidof qemu-kvm qemu-system-x86_64 kvm", shell=True, stdout=PIPE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

else:
kvm = Popen("which kvm", shell=True, stdout=PIPE)
kvm.communicate()
return not bool(kvm.returncode)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

def list_pids():
''' Find the pid of kvm processes
@return a list of pids from running kvm
'''
pid = Popen("pidof qemu-system-x86_64", shell=True, stdout=PIPE)
pid = Popen("pidof qemu-kvm qemu-system-x86_64 kvm", shell=True, stdout=PIPE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@duritong
Copy link
Author

duritong commented Dec 6, 2016

Regarding the RH specific plugin: I have only rhel based kvm boxes and there were some significant differences, I wasn't able to test on debian based kvm boxes. So either someone needs to test it or we should keep it as seperate plugins.

I agree though, that a unified plugin would be better, but given I don't have access to debian based kvm boxes I can't really verify my changes.

@sumpfralle
Copy link
Collaborator

I would be happy, if you could change the bits necessary for your environment and also fix/improve more details along the way (in separate commits). Most of the plugins do not have a fixed maintainer and cannot be easily tested by the repository maintainers - thus it is usually highly welcome to combine fixes with general cleanups.

Regarding Debian/Red Hat: I have access to Debian systems with kvm and I am fluent in python. Thus I would be happy to test and fix (if necessary) the plugins, as soon as you included the Red Hat specific parts.

@sumpfralle
Copy link
Collaborator

@duritong: what do you think?

@duritong
Copy link
Author

duritong commented Jan 6, 2017

I'll try to work on it, december was a bit a busy month for me.

@sumpfralle
Copy link
Collaborator

@duritong: just a friendly (and patient) reminder ...

@sumpfralle
Copy link
Collaborator

@duritong: ping?

@sumpfralle
Copy link
Collaborator

Ping?

@github-actions
Copy link

Stale pull request message

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants