本文整理汇总了Python中trigger.netdevices.NetDevices.all方法的典型用法代码示例。如果您正苦于以下问题:Python NetDevices.all方法的具体用法?Python NetDevices.all怎么用?Python NetDevices.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类trigger.netdevices.NetDevices
的用法示例。
在下文中一共展示了NetDevices.all方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestNetDevicesWithAcls
# 需要导入模块: from trigger.netdevices import NetDevices [as 别名]
# 或者: from trigger.netdevices.NetDevices import all [as 别名]
class TestNetDevicesWithAcls(unittest.TestCase):
"""
Test NetDevices with ``settings.WITH_ACLs set`` to ``True``.
"""
def setUp(self):
self.nd = NetDevices()
self.nodename = self.nd.keys()[0]
self.device = self.nd.values()[0]
self.device.explicit_acls = set(['test1-abc-only'])
def test_basics(self):
"""Basic test of NetDevices functionality."""
self.assertEqual(len(self.nd), 1)
self.assertEqual(self.device.nodeName, self.nodename)
self.assertEqual(self.device.manufacturer, 'JUNIPER')
def test_aclsdb(self):
"""Test acls.db handling."""
self.assertTrue('test1-abc-only' in self.device.explicit_acls)
def test_autoacls(self):
"""Test autoacls.py handling."""
self.assertTrue('router-protect.core' in self.device.implicit_acls)
def test_find(self):
"""Test the find() method."""
self.assertEqual(self.nd.find(self.nodename), self.device)
nodebasename = self.nodename[:self.nodename.index('.')]
self.assertEqual(self.nd.find(nodebasename), self.device)
self.assertRaises(KeyError, lambda: self.nd.find(self.nodename[0:3]))
def test_all(self):
"""Test the all() method."""
expected = [self.device]
self.assertEqual(expected, self.nd.all())
def test_search(self):
"""Test the search() method."""
expected = [self.device]
self.assertEqual(expected, self.nd.search(self.nodename))
self.assertEqual(expected, self.nd.search('17', field='onCallID'))
self.assertEqual(expected, self.nd.search('juniper', field='vendor'))
def test_match(self):
"""Test the match() method."""
expected = [self.device]
self.assertEqual(expected, self.nd.match(nodename=self.nodename))
self.assertEqual(expected, self.nd.match(vendor='juniper'))
self.assertNotEqual(expected, self.nd.match(vendor='cisco'))
def tearDown(self):
NetDevices._Singleton = None
示例2: get_bulk_acls
# 需要导入模块: from trigger.netdevices import NetDevices [as 别名]
# 或者: from trigger.netdevices.NetDevices import all [as 别名]
def get_bulk_acls():
"""
Returns a dict of acls with an applied count over settings.AUTOLOAD_BULK_THRESH
"""
from trigger.netdevices import NetDevices
nd = NetDevices()
all_acls = defaultdict(int)
for dev in nd.all():
for acl in dev.acls:
all_acls[acl] += 1
bulk_acls = {}
for acl, count in all_acls.items():
if count >= settings.AUTOLOAD_BULK_THRESH and acl != '':
bulk_acls[acl] = count
return bulk_acls
示例3: TestNetDevicesWithAcls
# 需要导入模块: from trigger.netdevices import NetDevices [as 别名]
# 或者: from trigger.netdevices.NetDevices import all [as 别名]
class TestNetDevicesWithAcls(unittest.TestCase):
"""
Test NetDevices with ``settings.WITH_ACLs set`` to ``True``.
"""
def setUp(self):
self.nd = NetDevices()
self.device = self.nd[DEVICE_NAME]
self.device2 = self.nd[DEVICE2_NAME]
self.nodename = self.device.nodeName
self.device.explicit_acls = set(['test1-abc-only'])
def test_basics(self):
"""Basic test of NetDevices functionality."""
self.assertEqual(len(self.nd), 2)
self.assertEqual(self.device.nodeName, self.nodename)
self.assertEqual(self.device.manufacturer, 'JUNIPER')
def test_aclsdb(self):
"""Test acls.db handling."""
self.assertTrue('test1-abc-only' in self.device.explicit_acls)
def test_autoacls(self):
"""Test autoacls.py handling."""
self.assertTrue('router-protect.core' in self.device.implicit_acls)
def test_find(self):
"""Test the find() method."""
self.assertEqual(self.nd.find(self.nodename), self.device)
nodebasename = self.nodename[:self.nodename.index('.')]
self.assertEqual(self.nd.find(nodebasename), self.device)
self.assertRaises(KeyError, lambda: self.nd.find(self.nodename[0:3]))
def test_all(self):
"""Test the all() method."""
expected = [self.device, self.device2]
self.assertEqual(sorted(expected), sorted(self.nd.all()))
def test_search(self):
"""Test the search() method."""
expected = [self.device]
self.assertEqual([self.device], self.nd.search(self.nodename))
self.assertEqual(self.nd.all(), self.nd.search('17', field='onCallID'))
def test_match(self):
"""Test the match() method."""
self.assertEqual([self.device], self.nd.match(nodename=self.nodename))
self.assertEqual(self.nd.all(), self.nd.match(vendor='juniper'))
self.assertEqual([], self.nd.match(vendor='cisco'))
def test_multiple_filter_match(self):
"""Test that passing multiple kwargs filters properly."""
# There should be only one Juniper router.
self.assertEqual(
self.nd.match(nodename='test1-abc'),
self.nd.match(vendor='juniper', devicetype='router')
)
# And only one Juniper switch.
self.assertEqual(
self.nd.match(nodename='test2-abc'),
self.nd.match(vendor='juniper', devicetype='switch')
)
def test_match_with_null_value(self):
"""Test the match() method when attr value is ``None``."""
self.device.site = None # Zero it out!
expected = [self.device]
# None raw
self.assertEqual(expected, self.nd.match(site=None))
# "None" string
self.assertEqual(expected, self.nd.match(site='None'))
# Case-insensitive attr *and* value
self.assertEqual(expected, self.nd.match(SITE='NONE'))
def tearDown(self):
_reset_netdevices()