Skip to content

Commit

Permalink
interface_addr_and_mask property + test added to snmp.OpenWRT backend :)
Browse files Browse the repository at this point in the history
  • Loading branch information
bucciarellialessandro committed May 12, 2014
1 parent b28b940 commit 2e89037
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions netengine/backends/snmp/openwrt.py
Expand Up @@ -15,6 +15,8 @@ class OpenWRT(SNMP):
"""
OpenWRT SNMP backend
"""

_interface_dict = {}

def __str__(self):
""" print a human readable object description """
Expand Down Expand Up @@ -225,6 +227,28 @@ def interfaces_to_dict(self):
})
results.append(result)
return results

@property
def interface_addr_and_mask(self):
interface_name = self.get_interfaces()
for i in range(0, len(interface_name)):
self._interface_dict[self._value_to_retrieve()[i]] = interface_name[i]
interface_ip_address = self.next("1.3.6.1.2.1.4.20.1.1")[3]
interface_index = self.next("1.3.6.1.2.1.4.20.1.2")[3]
interface_netmask = self.next("1.3.6.1.2.1.4.20.1.3")[3]
results = []
for i in range(0, len(interface_ip_address)):
a = interface_ip_address[i][0][1].asNumbers()
ip_address = '.'.join(str(a[i]) for i in range(0, len(a)))
b = interface_netmask[i][0][1].asNumbers()
netmask = '.'.join(str(b[i]) for i in range(0, len(b)))
result = self._dict({
"name" : self._interface_dict[int(interface_index[i][0][1])],
"address" : ip_address,
"netmask" : netmask
})
results.append(result)
return results

@property
def RAM_total(self):
Expand Down
3 changes: 3 additions & 0 deletions tests/snmp/openwrt.py
Expand Up @@ -55,6 +55,9 @@ def test_interfaces_state(self):
def test_interfaces_to_dict(self):
self.assertTrue(type(self.device.interfaces_to_dict) == list)

def test_interface_addr_and_mask(self):
self.assertTrue(type(self.interface_addr_and_mask) == list)

def test_RAM_total(self):
self.assertTrue(type(self.device.RAM_total) == int)

Expand Down

4 comments on commit 2e89037

@nemesifier
Copy link
Member

Choose a reason for hiding this comment

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

optimus 👍

@nemesifier
Copy link
Member

Choose a reason for hiding this comment

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

next step: add stuff to the to_dict method

@bucciarellialessandro
Copy link
Contributor Author

@bucciarellialessandro bucciarellialessandro commented on 2e89037 May 13, 2014 via email

Choose a reason for hiding this comment

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

@nemesifier
Copy link
Member

Choose a reason for hiding this comment

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

your next next step: smettere di rosicare :-) :-P

Please sign in to comment.