本文整理汇总了Python中cyder.cydhcp.network.models.Network.update_network方法的典型用法代码示例。如果您正苦于以下问题:Python Network.update_network方法的具体用法?Python Network.update_network怎么用?Python Network.update_network使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cyder.cydhcp.network.models.Network
的用法示例。
在下文中一共展示了Network.update_network方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_objects
# 需要导入模块: from cyder.cydhcp.network.models import Network [as 别名]
# 或者: from cyder.cydhcp.network.models.Network import update_network [as 别名]
def create_objects(nvars):
# There needs to be major exception handling here. Things can go pretty
# wrong.
ip_type = nvars.get('ip_type', None)
network_str = nvars.get('network_str', None)
network = Network(network_str=network_str, ip_type=ip_type)
network.update_network()
site_pk = nvars.get('site_pk', '')
if not site_pk:
site = None
else:
site = Site.objects.get(pk=site_pk)
network.site = site
if nvars.get('vlan_action', '') == "new":
vlan_name = nvars.get('vlan_name', None)
vlan_number = nvars.get('vlan_number', None)
vlan = Vlan(name=vlan_name, number=vlan_number)
elif nvars.get('vlan_action', '') == "existing":
vlan_number = nvars.get('vlan_pk', '')
if not vlan_number:
raise ValidationError("You selected to use an existing vlan. "
"Pleasechoose a vlan.")
vlan = Vlan.objects.get(pk=vlan_number)
else:
vlan = None
network.vlan = vlan
return site, network, vlan
示例2: V6RangeTests
# 需要导入模块: from cyder.cydhcp.network.models import Network [as 别名]
# 或者: from cyder.cydhcp.network.models.Network import update_network [as 别名]
class V6RangeTests(TestCase):
def setUp(self):
self.d = Domain(name="com")
self.s = Network(network_str="1234:1234:1234::/16", ip_type='6')
self.s.update_network()
self.s.save()
self.s1 = Network(network_str="1234:1134:1234::/32", ip_type='6')
self.s1.update_network()
self.s1.save()
self.s2 = Network(network_str="fff::/4", ip_type='6')
self.s2.update_network()
self.s2.save()
self.s3 = Network(network_str="ffff::/4", ip_type='6')
self.s3.update_network()
self.s3.save()
def do_add(self, start_str, end_str, default_domain, network, \
rtype, ip_type):
r = Range(start_str=start_str, end_str=end_str, network=network,
ip_type=ip_type)
r.__repr__()
r.save()
return r
def test1_create(self):
start_str = "1234:1234:1234:1::"
end_str = "1234:1234:1234:1234:1234:1234::"
default_domain = self.d
network = self.s
rtype = 's'
ip_type = '6'
kwargs = {'start_str': start_str, 'end_str': end_str,
'default_domain': default_domain,
'network': network, 'rtype': rtype, 'ip_type': ip_type}
self.do_add(**kwargs)
def test2_create(self):
start_str = "1234:1234:1234:1234::"
end_str = "1234:1234:1235:1234:1234:1234::"
default_domain = self.d
network = self.s
rtype = 's'
ip_type = '6'
kwargs = {'start_str': start_str, 'end_str': end_str,
'default_domain': default_domain,
'network': network, 'rtype': rtype, 'ip_type': ip_type}
self.do_add(**kwargs)
def test3_create(self):
start_str = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fff0"
end_str = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe"
default_domain = self.d
network = self.s3
rtype = 's'
ip_type = '6'
kwargs = {'start_str': start_str, 'end_str': end_str,
'default_domain': default_domain,
'network': network, 'rtype': rtype, 'ip_type': ip_type}
r = self.do_add(**kwargs)
self.assertEqual(r.start_upper, 0xffffffffffffffff)
self.assertEqual(r.start_lower, 0xfffffffffffffff0)
self.assertEqual(r.end_upper, 0xffffffffffffffff)
self.assertEqual(r.end_lower, 0xfffffffffffffffe)
"""
def test1_bad_create(self):
# start == end
start_str = "1234:1235:1234:1234::"
end_str = "1234:1235:1234:1234::"
default_domain = self.d
network = self.s
rtype = 's'
ip_type = '6'
kwargs = {'start_str': start_str, 'end_str': end_str,
'default_domain': default_domain,
'network': network, 'rtype': rtype, 'ip_type': ip_type}
self.assertRaises(ValidationError, self.do_add, **kwargs)
"""
def test2_bad_create(self):
# start > end
start_str = "1234:1235:1234:1235::"
end_str = "1234:1235:1234:1234::"
default_domain = self.d
network = self.s
rtype = 's'
ip_type = '6'
kwargs = {'start_str': start_str, 'end_str': end_str,
'default_domain': default_domain,
'network': network, 'rtype': rtype, 'ip_type': ip_type}
self.assertRaises(ValidationError, self.do_add, **kwargs)
#.........这里部分代码省略.........
示例3: test_overlap_validation
# 需要导入模块: from cyder.cydhcp.network.models import Network [as 别名]
# 或者: from cyder.cydhcp.network.models.Network import update_network [as 别名]
def test_overlap_validation(self):
n1 = Network(network_str='1::/65', ip_type='6')
n1.update_network()
n1.save()
self.assertFalse(n1 in get_total_overlap(n1))
self.assertFalse(n1 in get_partial_overlap(n1))
n2 = Network(network_str='1::/66', ip_type='6')
n2.update_network()
self.assertEqual(n1.start_upper, n2.start_upper)
self.assertEqual(n1.end_upper, n2.end_upper)
self.assertFalse(n1 in get_total_overlap(n2))
self.assertTrue(n1 in get_partial_overlap(n2))
n2 = Network(network_str='1::/64', ip_type='6')
n2.update_network()
self.assertEqual(n1.start_upper, n2.start_upper)
self.assertEqual(n1.end_upper, n2.end_upper)
self.assertTrue(n1 in get_total_overlap(n2))
self.assertTrue(n1 in get_partial_overlap(n2))
n2 = Network(network_str='1:0:0:0:8000::/65', ip_type='6')
n2.update_network()
self.assertEqual(n1.start_upper, n2.start_upper)
self.assertEqual(n1.end_upper, n2.end_upper)
self.assertFalse(n1 in get_total_overlap(n2))
self.assertFalse(n1 in get_partial_overlap(n2))
n1 = Network(network_str='2::/16', ip_type='6')
n1.update_network()
n1.save()
self.assertFalse(n1 in get_total_overlap(n1))
self.assertFalse(n1 in get_partial_overlap(n1))
n2 = Network(network_str='2::/17', ip_type='6')
n2.update_network()
self.assertEqual(n1.start_upper, n2.start_upper)
self.assertNotEqual(n1.end_upper, n2.end_upper)
self.assertFalse(n1 in get_total_overlap(n2))
self.assertTrue(n1 in get_partial_overlap(n2))
n2 = Network(network_str='2::/15', ip_type='6')
n2.update_network()
self.assertEqual(n1.start_upper, n2.start_upper)
self.assertNotEqual(n1.end_upper, n2.end_upper)
self.assertTrue(n1 in get_total_overlap(n2))
self.assertTrue(n1 in get_partial_overlap(n2))
n2 = Network(network_str='3::/16', ip_type='6')
n2.update_network()
self.assertNotEqual(n1.start_upper, n2.start_upper)
self.assertNotEqual(n1.end_upper, n2.end_upper)
self.assertFalse(n1 in get_total_overlap(n2))
self.assertFalse(n1 in get_partial_overlap(n2))
示例4: V4RangeTests
# 需要导入模块: from cyder.cydhcp.network.models import Network [as 别名]
# 或者: from cyder.cydhcp.network.models.Network import update_network [as 别名]
class V4RangeTests(TestCase):
def setUp(self):
self.d = Domain(name="com")
self.d.save()
Domain(name="arpa").save()
Domain(name="in-addr.arpa").save()
Domain(name="10.in-addr.arpa").save()
self.s = Network(network_str="10.0.0.0/16", ip_type='4')
self.s.update_network()
self.s.save()
self.s1 = Network(network_str="10.2.1.0/24", ip_type='4')
self.s1.update_network()
self.s1.save()
def do_add(self, start_str, end_str, default_domain, \
network, rtype, ip_type):
r = Range(start_str=start_str, end_str=end_str, network=network,
ip_type=ip_type)
r.__repr__()
r.save()
return r
def test1_create(self):
start_str = "10.0.0.1"
end_str = "10.0.0.55"
default_domain = self.d
network = self.s
rtype = 's'
ip_type = '4'
kwargs = {'start_str': start_str, 'end_str': end_str,
'default_domain': default_domain, 'network': network,
'rtype': rtype, 'ip_type': ip_type}
self.do_add(**kwargs)
def test2_create(self):
start_str = "10.0.1.1"
end_str = "10.0.1.55"
default_domain = self.d
network = self.s
rtype = 's'
ip_type = '4'
kwargs = {'start_str': start_str, 'end_str': end_str,
'default_domain': default_domain, 'network': network,
'rtype': rtype, 'ip_type': ip_type}
self.do_add(**kwargs)
def test1_bad_create(self):
# start == end
start_str = "10.0.0.0"
end_str = "10.1.0.0"
default_domain = self.d
network = self.s
rtype = 's'
ip_type = '4'
kwargs = {'start_str': start_str, 'end_str': end_str,
'default_domain': default_domain, 'network': network,
'rtype': rtype, 'ip_type': ip_type}
self.assertRaises(ValidationError, self.do_add, **kwargs)
def test2_bad_create(self):
# start > end
start_str = "10.0.0.2"
end_str = "10.0.0.1"
default_domain = self.d
network = self.s
rtype = 's'
ip_type = '4'
kwargs = {'start_str': start_str, 'end_str': end_str,
'default_domain': default_domain, 'network': network,
'rtype': rtype, 'ip_type': ip_type}
self.assertRaises(ValidationError, self.do_add, **kwargs)
def test3_bad_create(self):
# outside of network
start_str = "11.0.0.2"
end_str = "10.0.0.88"
default_domain = self.d
network = self.s
rtype = 's'
ip_type = '4'
kwargs = {'start_str': start_str, 'end_str': end_str,
'default_domain': default_domain, 'network': network,
'rtype': rtype, 'ip_type': ip_type}
self.assertRaises(ValidationError, self.do_add, **kwargs)
def test4_bad_create(self):
# outside of network
start_str = "10.2.0.0"
end_str = "10.2.1.88"
default_domain = self.d
network = self.s1
rtype = 's'
ip_type = '4'
#.........这里部分代码省略.........
示例5: sif
# 需要导入模块: from cyder.cydhcp.network.models import Network [as 别名]
# 或者: from cyder.cydhcp.network.models.Network import update_network [as 别名]
except ObjectDoesNotExist, e:
continue
queries, s_misc = sif(site)
range_queries += queries
misc = misc.union(s_misc)
for network_str in network_fs:
try:
# Guess which network type they are searching by looking for ':'
if network_str.find(':') > -1:
network = ipaddr.IPv6Address(
network_str=network_str, ip_type='6')
network.update_network()
else:
network = Network(network_str=network_str, ip_type='4')
network.update_network()
except ValidationError, e:
continue
except ipaddr.AddressValueError, e:
continue
queries, n_misc = nif(network)
range_queries += queries
misc = misc.union(n_misc)
for vlan_str in vlan_fs:
try:
vlan = Vlan.objects.get(name=vlan_str)
except ObjectDoesNotExist, e:
try:
vlan = Vlan.objects.get(name=vlan_str)
except ObjectDoesNotExist, e: