Skip to content

Commit 2a83efb

Browse files
committed
pifconfig: Add python ifconfig equivalent to test features
A la pethtool Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 330c8c4 commit 2a83efb

File tree

3 files changed

+107
-1
lines changed

3 files changed

+107
-1
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
COPYING
22
pethtool.py
3+
pifconfig.py
34
python-ethtool/ethtool.c
45
python-ethtool/ethtool-copy.h
56
setup.py

pifconfig.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#! /usr/bin/python
2+
# -*- python -*-
3+
# -*- coding: utf-8 -*-
4+
# Copyright (C) 2008 Red Hat Inc.
5+
#
6+
# Arnaldo Carvalho de Melo <acme@redhat.com>
7+
#
8+
# This application is free software; you can redistribute it and/or
9+
# modify it under the terms of the GNU General Public License
10+
# as published by the Free Software Foundation; version 2.
11+
#
12+
# This application is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# General Public License for more details.
16+
17+
import getopt, ethtool, sys
18+
19+
def usage():
20+
print '''Usage:
21+
pifconfig <interface>
22+
'''
23+
24+
def flags2str(flags):
25+
string = ""
26+
if flags & ethtool.IFF_UP:
27+
string += "UP "
28+
if flags & ethtool.IFF_BROADCAST:
29+
string += "BROADCAST "
30+
if flags & ethtool.IFF_DEBUG:
31+
string += "DEBUG "
32+
if flags & ethtool.IFF_LOOPBACK:
33+
string += "LOOPBACK "
34+
if flags & ethtool.IFF_POINTOPOINT:
35+
string += "POINTOPOINT "
36+
if flags & ethtool.IFF_NOTRAILERS:
37+
string += "NOTRAILERS "
38+
if flags & ethtool.IFF_RUNNING:
39+
string += "RUNNING "
40+
if flags & ethtool.IFF_NOARP:
41+
string += "NOARP "
42+
if flags & ethtool.IFF_PROMISC:
43+
string += "PROMISC "
44+
if flags & ethtool.IFF_ALLMULTI:
45+
string += "ALLMULTI "
46+
if flags & ethtool.IFF_MASTER:
47+
string += "MASTER "
48+
if flags & ethtool.IFF_SLAVE:
49+
string += "SLAVE "
50+
if flags & ethtool.IFF_MULTICAST:
51+
string += "MULTICAST "
52+
if flags & ethtool.IFF_PORTSEL:
53+
string += "PORTSEL "
54+
if flags & ethtool.IFF_AUTOMEDIA:
55+
string += "AUTOMEDIA "
56+
if flags & ethtool.IFF_DYNAMIC:
57+
string += "DYNAMIC "
58+
59+
return string.strip()
60+
61+
def show_config(device):
62+
ipaddr = ethtool.get_ipaddr(device)
63+
netmask = ethtool.get_netmask(device)
64+
flags = ethtool.get_flags(device)
65+
print '%-9.9s' % device,
66+
if not (flags & ethtool.IFF_LOOPBACK):
67+
print "HWaddr %s" % ethtool.get_hwaddr(device),
68+
print '''
69+
inet addr:%s''' % ipaddr,
70+
if not (flags & (ethtool.IFF_LOOPBACK | ethtool.IFF_POINTOPOINT)):
71+
print "Bcast:%s" % ethtool.get_broadcast(device),
72+
print ''' Mask:%s
73+
%s
74+
''' % (netmask, flags2str(flags))
75+
76+
def main():
77+
global all_devices
78+
79+
try:
80+
opts, args = getopt.getopt(sys.argv[1:],
81+
"h",
82+
("help",))
83+
except getopt.GetoptError, err:
84+
usage()
85+
print str(err)
86+
sys.exit(2)
87+
88+
for o, a in opts:
89+
if o in ("-h", "--help"):
90+
usage()
91+
return
92+
93+
active_devices = ethtool.get_active_devices()
94+
for device in active_devices:
95+
show_config(device)
96+
97+
if __name__ == '__main__':
98+
main()

rpm/SPECS/python-ethtool.spec

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
Summary: Ethernet settings python bindings
55
Name: python-ethtool
6-
Version: 0.2
6+
Version: 0.3
77
Release: 1%{?dist}
88
URL: http://git.kernel.org/?p=linux/kernel/git/acme/python-ethtool.git
99
Source: http://userweb.kernel.org/~acme/python-ethtool/%{name}-%{version}.tar.bz2
@@ -28,6 +28,7 @@ rm -rf %{buildroot}
2828
make DESTDIR=%{buildroot} install
2929
mkdir -p %{buildroot}%{_sbindir}
3030
cp -f pethtool.py %{buildroot}%{_sbindir}/pethtool
31+
cp -f pifconfig.py %{buildroot}%{_sbindir}/pifconfig
3132

3233
%clean
3334
rm -rf %{buildroot}
@@ -36,12 +37,18 @@ rm -rf %{buildroot}
3637
%defattr(-,root,root)
3738
%doc COPYING
3839
%{_sbindir}/pethtool
40+
%{_sbindir}/pifconfig
3941
%{python_sitearch}/ethtool.so
4042
%if "%{python_ver}" >= "2.5"
4143
%{python_sitearch}/*.egg-info
4244
%endif
4345

4446
%changelog
47+
* Tue Aug 26 2008 Arnaldo Carvalho de Melo <acme@redhat.com> - 0.3-1
48+
- Add get_flags method from the first python-ethtool contributor, yay
49+
- Add pifconfig command, that mimics the ifconfig tool using the
50+
bindings available
51+
4552
* Wed Aug 20 2008 Arnaldo Carvalho de Melo <acme@redhat.com> - 0.2-1
4653
- Expand description and summary fields, as part of the fedora
4754
review process.

0 commit comments

Comments
 (0)