Skip to content

Commit 25157b3

Browse files
committed
0.2.8
1 parent 2ccc5fe commit 25157b3

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# dockerifaces
2+
3+
collect network interconnect information between host and containers (gest)
4+
5+
### Requires
6+
this package require 'docker' and 'ifaceinfo', this tow package are installed automatically when you install dockerifaces
7+
8+
9+
### How to use it
10+
#### install
11+
```python
12+
pip install dockerifaces
13+
```
14+
15+
#### import
16+
```python
17+
from dockerifaces import DockerInterfaces
18+
_containersNetworks = DockerInterfaces()
19+
```

dockerifaces/dockerifaces.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
#
1313
class DockerInterfaces():
1414
def __init__(self, ifaceinfo=''):
15-
self.__dockerClient = docker.from_env()
15+
try:
16+
self.__dockerClient = docker.from_env()
17+
except ConnectionError as ConnError:
18+
print('Connexion error' + ConnError)
19+
raise ValueError('Docker is not ruuning.')
1620
# manage the ifaceinfo is provided or not
1721
if ifaceinfo == '':
1822
self.__ifaceinfoprovided = False
@@ -187,12 +191,15 @@ def __containers_collect_data(self):
187191
_iflink = _container.exec_run('cat /sys/class/net/' + iface + '/iflink')
188192
_ifaddr = _container.exec_run('cat /sys/class/net/' + iface + '/address')
189193
_ifoperstate = _container.exec_run('cat /sys/class/net/' + iface + '/operstate')
194+
# get interface statistics :)
195+
#_statistics = _container.exec_run('echo "{"; for i in $(ls /sys/class/net/' + iface + '/statistics); do echo "\"$i\": $(cat $i), "; done; echo "}"')
190196
_containersinfos[_container.short_id][iface] = {
191-
'name' : iface,
192-
'ifindex' : self.__convert_value(_ifindex.output.decode()) if _ifindex.exit_code == 0 else -1,
193-
'iflink' : self.__convert_value(_iflink.output.decode()) if _iflink.exit_code == 0 else -1,
194-
'address' : self.__convert_value(_ifaddr.output.decode().replace('\n', '')) if _ifaddr.exit_code == 0 else 'unknown',
195-
'operstate' : self.__convert_value(_ifoperstate.output.decode().replace('\n', '')) if _ifaddr.exit_code == 0 else 'unknown'
197+
'name' : iface,
198+
'ifindex' : self.__convert_value(_ifindex.output.decode()) if _ifindex.exit_code == 0 else -1,
199+
'iflink' : self.__convert_value(_iflink.output.decode()) if _iflink.exit_code == 0 else -1,
200+
'address' : self.__convert_value(_ifaddr.output.decode().replace('\n', '')) if _ifaddr.exit_code == 0 else 'unknown',
201+
'operstate' : self.__convert_value(_ifoperstate.output.decode().replace('\n', '')) if _ifaddr.exit_code == 0 else 'unknown'
202+
#'statistics' : _statistics
196203
}
197204
return _containersinfos
198205

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#from distutils.core import setup
33

44
setup(name='dockerifaces',
5-
version='0.2.7',
5+
version='0.2.8',
66
description='Use this package to find the virtual network of container -> connected to which virtual host network',
77
url='https://github.com/atam84/dockerinterfaces',
88
author='Mohamed Amine TAMDY',

0 commit comments

Comments
 (0)