summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2008-08-26 15:53:08 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2008-08-26 15:53:08 -0300
commit2a83efb83ae4f878bf4ecfdc711f287446e5f630 (patch)
treec5cb0bae9598e1e423696d8a00df838f41ac0b4f
parent330c8c4fa727547528b1e33612a417b84fa27458 (diff)
downloadpython-ethtool-2a83efb83ae4f878bf4ecfdc711f287446e5f630.tar.gz
python-ethtool-2a83efb83ae4f878bf4ecfdc711f287446e5f630.tar.xz
python-ethtool-2a83efb83ae4f878bf4ecfdc711f287446e5f630.zip
pifconfig: Add python ifconfig equivalent to test featuresv0.3
A la pethtool Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--MANIFEST1
-rwxr-xr-xpifconfig.py98
-rw-r--r--rpm/SPECS/python-ethtool.spec9
3 files changed, 107 insertions, 1 deletions
diff --git a/MANIFEST b/MANIFEST
index aef5263..cf268f4 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,5 +1,6 @@
COPYING
pethtool.py
+pifconfig.py
python-ethtool/ethtool.c
python-ethtool/ethtool-copy.h
setup.py
diff --git a/pifconfig.py b/pifconfig.py
new file mode 100755
index 0000000..cfaa2a6
--- /dev/null
+++ b/pifconfig.py
@@ -0,0 +1,98 @@
+#! /usr/bin/python
+# -*- python -*-
+# -*- coding: utf-8 -*-
+# Copyright (C) 2008 Red Hat Inc.
+#
+# Arnaldo Carvalho de Melo <acme@redhat.com>
+#
+# This application is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2.
+#
+# This application is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+
+import getopt, ethtool, sys
+
+def usage():
+ print '''Usage:
+ pifconfig <interface>
+'''
+
+def flags2str(flags):
+ string = ""
+ if flags & ethtool.IFF_UP:
+ string += "UP "
+ if flags & ethtool.IFF_BROADCAST:
+ string += "BROADCAST "
+ if flags & ethtool.IFF_DEBUG:
+ string += "DEBUG "
+ if flags & ethtool.IFF_LOOPBACK:
+ string += "LOOPBACK "
+ if flags & ethtool.IFF_POINTOPOINT:
+ string += "POINTOPOINT "
+ if flags & ethtool.IFF_NOTRAILERS:
+ string += "NOTRAILERS "
+ if flags & ethtool.IFF_RUNNING:
+ string += "RUNNING "
+ if flags & ethtool.IFF_NOARP:
+ string += "NOARP "
+ if flags & ethtool.IFF_PROMISC:
+ string += "PROMISC "
+ if flags & ethtool.IFF_ALLMULTI:
+ string += "ALLMULTI "
+ if flags & ethtool.IFF_MASTER:
+ string += "MASTER "
+ if flags & ethtool.IFF_SLAVE:
+ string += "SLAVE "
+ if flags & ethtool.IFF_MULTICAST:
+ string += "MULTICAST "
+ if flags & ethtool.IFF_PORTSEL:
+ string += "PORTSEL "
+ if flags & ethtool.IFF_AUTOMEDIA:
+ string += "AUTOMEDIA "
+ if flags & ethtool.IFF_DYNAMIC:
+ string += "DYNAMIC "
+
+ return string.strip()
+
+def show_config(device):
+ ipaddr = ethtool.get_ipaddr(device)
+ netmask = ethtool.get_netmask(device)
+ flags = ethtool.get_flags(device)
+ print '%-9.9s' % device,
+ if not (flags & ethtool.IFF_LOOPBACK):
+ print "HWaddr %s" % ethtool.get_hwaddr(device),
+ print '''
+ inet addr:%s''' % ipaddr,
+ if not (flags & (ethtool.IFF_LOOPBACK | ethtool.IFF_POINTOPOINT)):
+ print "Bcast:%s" % ethtool.get_broadcast(device),
+ print ''' Mask:%s
+ %s
+''' % (netmask, flags2str(flags))
+
+def main():
+ global all_devices
+
+ try:
+ opts, args = getopt.getopt(sys.argv[1:],
+ "h",
+ ("help",))
+ except getopt.GetoptError, err:
+ usage()
+ print str(err)
+ sys.exit(2)
+
+ for o, a in opts:
+ if o in ("-h", "--help"):
+ usage()
+ return
+
+ active_devices = ethtool.get_active_devices()
+ for device in active_devices:
+ show_config(device)
+
+if __name__ == '__main__':
+ main()
diff --git a/rpm/SPECS/python-ethtool.spec b/rpm/SPECS/python-ethtool.spec
index cacbd5e..cbd2969 100644
--- a/rpm/SPECS/python-ethtool.spec
+++ b/rpm/SPECS/python-ethtool.spec
@@ -3,7 +3,7 @@
Summary: Ethernet settings python bindings
Name: python-ethtool
-Version: 0.2
+Version: 0.3
Release: 1%{?dist}
URL: http://git.kernel.org/?p=linux/kernel/git/acme/python-ethtool.git
Source: http://userweb.kernel.org/~acme/python-ethtool/%{name}-%{version}.tar.bz2
@@ -28,6 +28,7 @@ rm -rf %{buildroot}
make DESTDIR=%{buildroot} install
mkdir -p %{buildroot}%{_sbindir}
cp -f pethtool.py %{buildroot}%{_sbindir}/pethtool
+cp -f pifconfig.py %{buildroot}%{_sbindir}/pifconfig
%clean
rm -rf %{buildroot}
@@ -36,12 +37,18 @@ rm -rf %{buildroot}
%defattr(-,root,root)
%doc COPYING
%{_sbindir}/pethtool
+%{_sbindir}/pifconfig
%{python_sitearch}/ethtool.so
%if "%{python_ver}" >= "2.5"
%{python_sitearch}/*.egg-info
%endif
%changelog
+* Tue Aug 26 2008 Arnaldo Carvalho de Melo <acme@redhat.com> - 0.3-1
+- Add get_flags method from the first python-ethtool contributor, yay
+- Add pifconfig command, that mimics the ifconfig tool using the
+ bindings available
+
* Wed Aug 20 2008 Arnaldo Carvalho de Melo <acme@redhat.com> - 0.2-1
- Expand description and summary fields, as part of the fedora
review process.