Skip to content

Commit

Permalink
Merge remote-tracking branch 'giampaolo/master'
Browse files Browse the repository at this point in the history
* giampaolo/master: (26 commits)
  try to fix failure on py 3
  try to fix occasional appveyor failure
  add test to make sure all example scripts are executable
  fix travis failure
  yet another test for rlimit
  fix giampaolo#513: [Linux] fixed integer overflow for RLIM_INFINITY.
  provide actual test for rlimit
  fix giampaolo#603: [Linux] ionice_set value range is incorrect.  (patch by spacewander)
  fix net_if_addrs on Windows
  update HISTORY - @mrjefftang
  try to fix compilation warning
  make flake8 happy
  fix failing test on OSX
  OSX try to fix swapmem test
  try to debug travis failure
  OSX: fix swap mem test
  use sysctlbyname to get cpu_count() logical and also add unit tests
  C styling
  C styling
  C styling
  ...
  • Loading branch information
mrjefftang committed Aug 12, 2015
2 parents d6ed259 + 3e5aa8a commit 93caf6d
Show file tree
Hide file tree
Showing 28 changed files with 502 additions and 544 deletions.
5 changes: 3 additions & 2 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ W: http://www.jayloden.com

N: Jeff Tang
W: https://github.com/mrjefftang
I: 340, 529, 616, 653, 654, 648
I: 340, 529, 616, 653, 654, 648, 641

N: Jeremy Whitlock
E: [email protected]
Expand Down Expand Up @@ -267,8 +267,9 @@ W: https://github.com/anders-chrigstrom
I: 496

N: spacewander
W: https://github.com/spacewander
E: [email protected]
I: 561
I: 561, 603

N: Sylvain Mouquet
E: [email protected]
Expand Down
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
**Enhancements**

- #648: CI test integration for OSX. (patch by Jeff Tang)
- #663: net_if_addrs() now returns point-to-point addresses (for VPNs).

**Bug fixes**

- #513: [Linux] fixed integer overflow for RLIM_INFINITY.
- #641: [Windows] fixed many compilation warnings. (patch by Jeff Tang)
- #659: [Linux] compilation error on Suse 10.
- #664: [Linux] compilation error on Alpine Linux. (patch by Bart van Kleef)

Expand All @@ -18,6 +21,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues

**Bug fixes**

- #603: [Linux] ionice_set value range is incorrect. (patch by spacewander)
- #645: [Linux] psutil.cpu_times_percent() may produce negative results.
- #656: 'from psutil import *' does not work.
Expand Down
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ Network
...]
>>>
>>> psutil.net_if_addrs()
{'lo': [snic(family=<AddressFamily.AF_INET: 2>, address='127.0.0.1', netmask='255.0.0.0', broadcast='127.0.0.1'),
snic(family=<AddressFamily.AF_INET6: 10>, address='::1', netmask='ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', broadcast=None),
snic(family=<AddressFamily.AF_LINK: 17>, address='00:00:00:00:00:00', netmask=None, broadcast='00:00:00:00:00:00')],
'wlan0': [snic(family=<AddressFamily.AF_INET: 2>, address='192.168.1.3', netmask='255.255.255.0', broadcast='192.168.1.255'),
snic(family=<AddressFamily.AF_INET6: 10>, address='fe80::c685:8ff:fe45:641%wlan0', netmask='ffff:ffff:ffff:ffff::', broadcast=None),
snic(family=<AddressFamily.AF_LINK: 17>, address='c4:85:08:45:06:41', netmask=None, broadcast='ff:ff:ff:ff:ff:ff')]}
{'lo': [snic(family=<AddressFamily.AF_INET: 2>, address='127.0.0.1', netmask='255.0.0.0', broadcast='127.0.0.1', ptp=None),
snic(family=<AddressFamily.AF_INET6: 10>, address='::1', netmask='ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', broadcast=None, ptp=None),
snic(family=<AddressFamily.AF_LINK: 17>, address='00:00:00:00:00:00', netmask=None, broadcast='00:00:00:00:00:00', ptp=None)],
'wlan0': [snic(family=<AddressFamily.AF_INET: 2>, address='192.168.1.3', netmask='255.255.255.0', broadcast='192.168.1.255', ptp=None),
snic(family=<AddressFamily.AF_INET6: 10>, address='fe80::c685:8ff:fe45:641%wlan0', netmask='ffff:ffff:ffff:ffff::', broadcast=None, ptp=None),
snic(family=<AddressFamily.AF_LINK: 17>, address='c4:85:08:45:06:41', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)]}
>>>
>>> psutil.net_if_stats()
{'eth0': snicstats(isup=True, duplex=<NicDuplex.NIC_DUPLEX_FULL: 2>, speed=100, mtu=1500),
Expand Down
29 changes: 21 additions & 8 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -410,28 +410,36 @@ Network
Return the addresses associated to each NIC (network interface card)
installed on the system as a dictionary whose keys are the NIC names and
value is a list of namedtuples for each address assigned to the NIC.
Each namedtuple includes 4 fields:
Each namedtuple includes 5 fields:

- **family**
- **address**
- **netmask**
- **broadcast**
- **ptp**

*family* can be either
`AF_INET <http://docs.python.org//library/socket.html#socket.AF_INET>`__,
`AF_INET6 <http://docs.python.org//library/socket.html#socket.AF_INET6>`__
or :const:`psutil.AF_LINK`, which refers to a MAC address.
*address* is the primary address, *netmask* and *broadcast* may be ``None``.
*address* is the primary address and it is always set.
*netmask*, *broadcast* and *ptp* may be ``None``.
*ptp* stands for "point to point" and references the destination address on a
point to point interface (tipically a VPN).
*broadcast* and *ptp* are mutually exclusive.
*netmask*, *broadcast* and *ptp* are not supported on Windows and are set to
``None``.

Example::

>>> import psutil
>>> psutil.net_if_addrs()
{'lo': [snic(family=<AddressFamily.AF_INET: 2>, address='127.0.0.1', netmask='255.0.0.0', broadcast='127.0.0.1'),
snic(family=<AddressFamily.AF_INET6: 10>, address='::1', netmask='ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', broadcast=None),
snic(family=<AddressFamily.AF_LINK: 17>, address='00:00:00:00:00:00', netmask=None, broadcast='00:00:00:00:00:00')],
'wlan0': [snic(family=<AddressFamily.AF_INET: 2>, address='192.168.1.3', netmask='255.255.255.0', broadcast='192.168.1.255'),
snic(family=<AddressFamily.AF_INET6: 10>, address='fe80::c685:8ff:fe45:641%wlan0', netmask='ffff:ffff:ffff:ffff::', broadcast=None),
snic(family=<AddressFamily.AF_LINK: 17>, address='c4:85:08:45:06:41', netmask=None, broadcast='ff:ff:ff:ff:ff:ff')]}
{'lo': [snic(family=<AddressFamily.AF_INET: 2>, address='127.0.0.1', netmask='255.0.0.0', broadcast='127.0.0.1', ptp=None),
snic(family=<AddressFamily.AF_INET6: 10>, address='::1', netmask='ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', broadcast=None, ptp=None),
snic(family=<AddressFamily.AF_LINK: 17>, address='00:00:00:00:00:00', netmask=None, broadcast='00:00:00:00:00:00', ptp=None)],
'wlan0': [snic(family=<AddressFamily.AF_INET: 2>, address='192.168.1.3', netmask='255.255.255.0', broadcast='192.168.1.255', ptp=None),
snic(family=<AddressFamily.AF_INET6: 10>, address='fe80::c685:8ff:fe45:641%wlan0', netmask='ffff:ffff:ffff:ffff::', broadcast=None, ptp=None),
snic(family=<AddressFamily.AF_LINK: 17>, address='c4:85:08:45:06:41', netmask=None, broadcast='ff:ff:ff:ff:ff:ff', ptp=None)]}
>>>

See also `examples/ifconfig.py <https://github.com/giampaolo/psutil/blob/master/examples/ifconfig.py>`__
Expand All @@ -444,8 +452,13 @@ Network
.. note:: you can have more than one address of the same family associated
with each interface (that's why dict values are lists).

.. note:: *netmask*, *broadcast* and *ptp* are not supported on Windows and
are set to ``None``.

*New in 3.0.0*

*Changed in 3.1.2:* *ptp* field was added.

.. function:: net_if_stats()

Return information about each NIC (network interface card) installed on the
Expand Down
2 changes: 2 additions & 0 deletions examples/ifconfig.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def main():
print(" broadcast : %s" % addr.broadcast)
if addr.netmask:
print(" netmask : %s" % addr.netmask)
if addr.ptp:
print(" p2p : %s" % addr.ptp)
print("")


Expand Down
Empty file modified examples/ps.py
100644 → 100755
Empty file.
Empty file modified examples/pstree.py
100644 → 100755
Empty file.
15 changes: 10 additions & 5 deletions psutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1749,17 +1749,22 @@ def net_if_addrs():
"""Return the addresses associated to each NIC (network interface
card) installed on the system as a dictionary whose keys are the
NIC names and value is a list of namedtuples for each address
assigned to the NIC. Each namedtuple includes 4 fields:
assigned to the NIC. Each namedtuple includes 5 fields:
- family
- address
- netmask
- broadcast
- ptp
'family' can be either socket.AF_INET, socket.AF_INET6 or
psutil.AF_LINK, which refers to a MAC address.
'address' is the primary address, 'netmask' and 'broadcast'
may be None.
'address' is the primary address and it is always set.
'netmask' and 'broadcast' and 'ptp' may be None.
'ptp' stands for "point to point" and references the destination
address on a point to point interface (tipically a VPN).
'broadcast' and 'ptp' are mutually exclusive.
Note: you can have more than one address of the same family
associated with each interface.
"""
Expand All @@ -1769,7 +1774,7 @@ def net_if_addrs():
rawlist = _psplatform.net_if_addrs()
rawlist.sort(key=lambda x: x[1]) # sort by family
ret = collections.defaultdict(list)
for name, fam, addr, mask, broadcast in rawlist:
for name, fam, addr, mask, broadcast, ptp in rawlist:
if has_enums:
try:
fam = socket.AddressFamily(fam)
Expand All @@ -1782,7 +1787,7 @@ def net_if_addrs():
# We re-set the family here so that repr(family)
# will show AF_LINK rather than AF_PACKET
fam = _psplatform.AF_LINK
ret[name].append(_common.snic(fam, addr, mask, broadcast))
ret[name].append(_common.snic(fam, addr, mask, broadcast, ptp))
return dict(ret)


Expand Down
2 changes: 1 addition & 1 deletion psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def socktype_to_enum(num):
sconn = namedtuple('sconn', ['fd', 'family', 'type', 'laddr', 'raddr',
'status', 'pid'])
# psutil.net_if_addrs()
snic = namedtuple('snic', ['family', 'address', 'netmask', 'broadcast'])
snic = namedtuple('snic', ['family', 'address', 'netmask', 'broadcast', 'ptp'])
# psutil.net_if_stats()
snicstats = namedtuple('snicstats', ['isup', 'duplex', 'speed', 'mtu'])

Expand Down
4 changes: 2 additions & 2 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,9 +1065,9 @@ def ionice_set(self, ioclass, value):
if not PY3 and not isinstance(value, (int, long)):
msg = "value argument is not an integer (gor %r)" % value
raise TypeError(msg)
if not 0 <= value <= 8:
if not 0 <= value <= 7:
raise ValueError(
"value argument range expected is between 0 and 8")
"value argument range expected is between 0 and 7")

if ioclass in (IOPRIO_CLASS_NONE, None):
if value:
Expand Down
Loading

0 comments on commit 93caf6d

Please sign in to comment.