Jun 5, 2013 11:07 AM
How to get all devices of an ip-network?
-
Like (0)
Hi,
following piece of code:
net=context.getSubNetworks():
for dev in net.getSubDevices():
loc=dev. getLocationName()
leads to following error:
Type: <type 'exceptions.TypeError'>
Value: getSubDevices() takes at most 2 arguments (3 given)
Traceback (most recent call last): File "/opt/zenoss/lib/python/ZPublisher/Publish.py",
line 126, in publish request, bind=1) File "/opt/zenoss/lib/python/ZPublisher/mapply.py",
line 77, in mapply if debug is not None: return debug(object,args,context) File "/opt/zenoss/lib/python/ZPublisher/Publish.py",
line 46, in call_object result=apply(object,args) # Type s<cr> to step into published object.
File "/opt/zenoss/lib/python/Shared/DC/Scripts/Bindings.py",
line 322, in __call__ return self._bindAndExec(args, kw, None)
File "/opt/zenoss/lib/python/Shared/DC/Scripts/Bindings.py",
line 359, in _bindAndExec return self._exec(bound_data, args, kw)
File "/opt/zenoss/lib/python/Products/PythonScripts/PythonScript.py",
line 344, in _exec result = f(*args, **kw) File "Script (Python)",
line 22, in getNetworklistWithLocations File "Script (Python)",
line 12, in findLocation File "/opt/zenoss/Products/ZenModel/IpNetwork.py",
line 482, in getSubDevices return DeviceOrganizer.getSubDevices(self, filter, "ipaddresses")
TypeError: getSubDevices() takes at most 2 arguments (3 given)
I assume a bug in the Method getSubDevices of the class ipnetwork. The source of this method is:
def getSubDevices(self, filter=None):
#481 """get all the devices under and instance of a DeviceGroup"""
482 return DeviceOrganizer.getSubDevices(self, filter, "ipaddresses")
but DeviceOrganizer.getSubDevices only accepts 2 parameters - exception seems correct :
def getSubDevices(self, devfilter=None):
# 96 """
97 Get all the devices under an instance of a DeviceOrganizer
# 98
# 99 @param devfilter: Filter function applied to returned list
#100 @type devfilter: function
#101 @return: Devices
#102 @rtype: list
How can I get a list of all device objects within an ipnetwork with zenoss 4.2.3?
Thank you in advance!
greetings,
christian
Hi,
could figure it out by myself:
this doesn't work because getSubDevices in class ipnetworks doesn't work:
net=context.getSubNetworks():
for dev in net.getSubDevices():
loc=dev. getLocationName()
The primary root cause is: there are no objects of type "device" linked from an ipnetwork but objects of type ipaddress - and ipaddresses are linked to interfaces - and interfaces are linked to devices. So I have to trace this chain to get a location for an ipnetwork:
ipnetwork -> ipadress -> interface -> device -> location
def findLocation(net):
location="unknown"
for ipaddress in net.ipaddresses.objectValuesGen():
dev=ipaddress.device()
if dev:
location=dev.getLocationName()
return location
regards,
Christian
Follow Us On Twitter »
|
Latest from the Zenoss Blog » | Community | Products | Services Resources | Customers Partners | About Us | ||
Copyright © 2005-2011 Zenoss, Inc.
|
||||||||