本文整理汇总了Python中cyder.cydhcp.network.models.Network类的典型用法代码示例。如果您正苦于以下问题:Python Network类的具体用法?Python Network怎么用?Python Network使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Network类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_objects
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: do_basic_add_network
def do_basic_add_network(self, network, prefixlen, ip_type, name=None,
vlan=None, site=None):
n = Network(network_str=network + "/" + prefixlen, ip_type=ip_type,
site=site, vlan=vlan)
n.clean()
n.save()
return n
示例3: do_basic_add
def do_basic_add(self, network, prefixlen, ip_type,
ame=None, number=None, site=None):
s = Network(network_str=network + "/" + prefixlen,
ip_type=ip_type, site=site)
s.clean()
s.save()
self.assertTrue(s)
return s
示例4: test_check_valid_ranges_v4_valid
def test_check_valid_ranges_v4_valid(self):
n = Network(network_str='10.0.0.0/8')
n.full_clean()
n.save()
r = Range(ip_type='4', start_str='10.4.0.2', end_str='10.4.255.254',
network=n)
r.full_clean()
r.save()
n.network_str = '10.4.0.0/16'
n.full_clean()
n.save()
示例5: setUp
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()
示例6: test_check_valid_ranges_v4_start_low_end_high
def test_check_valid_ranges_v4_start_low_end_high(self):
n = Network(network_str='10.0.0.0/8')
n.full_clean()
n.save()
r = Range(ip_type='4', start_str='10.3.0.2', end_str='10.5.255.254',
network=n)
r.full_clean()
r.save()
n.network_str = '10.4.0.0/16'
with self.assertRaises(ValidationError):
n.full_clean()
n.save()
示例7: setUp
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()
示例8: test1_create_ipv4_interface_from_domain
def test1_create_ipv4_interface_from_domain(self):
v, _ = Vlan.objects.get_or_create(name="private", number=3)
s, _ = Site.objects.get_or_create(name="phx1")
d, _ = Domain.objects.get_or_create(name="phx1.mozilla.com")
d, _ = Domain.objects.get_or_create(name="private.phx1.mozilla.com")
d, _ = Domain.objects.get_or_create(name="arpa")
d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
d, _ = Domain.objects.get_or_create(name="13.in-addr.arpa")
n = Network(network_str="13.0.0.0/8", ip_type="4")
n.clean()
n.site = s
n.vlan = v
n.save()
r = Range(start_str="13.0.0.0", end_str="13.0.0.2",
network=n, ip_type='4')
r.clean()
r.save()
intr, errors = create_ipv4_intr_from_domain(
label="foo", domain_name="private.phx1", system=self.system,
mac="11:22:33:44:55:66")
self.assertEqual(errors, None)
self.assertTrue(isinstance(intr, StaticInterface))
示例9: test8_create_ipv4_interface
def test8_create_ipv4_interface(self):
v, _ = Vlan.objects.get_or_create(name="8db", number=3)
s, _ = Site.objects.get_or_create(name="8scl3")
s1, _ = Site.objects.get_or_create(name="8dmz", parent=s)
d, _ = Domain.objects.get_or_create(name="8scl3.mozilla.com")
d, _ = Domain.objects.get_or_create(name="8dmz.8scl3.mozilla.com")
d, _ = Domain.objects.get_or_create(name="8db.8dmz.8scl3.mozilla.com")
d, _ = Domain.objects.get_or_create(name="arpa")
d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
d, _ = Domain.objects.get_or_create(name="15.in-addr.arpa")
n = Network(network_str="15.0.0.0/8", ip_type="4")
n.clean()
n.site = s1
n.vlan = v
n.save()
r = Range(start_str="15.0.0.0", end_str="15.0.0.2",
network=n)
r.clean()
r.save()
intr, errors = create_ipv4_interface(
"foo", "8db", "8dmz.8scl3", self.system,
"11:22:33:44:55:66", "mozilla.com")
self.assertEqual(errors, None)
self.assertTrue(isinstance(intr, StaticInterface))
示例10: test2_create_ipv4_interface_from_domain
def test2_create_ipv4_interface_from_domain(self):
v, _ = Vlan.objects.get_or_create(name="private", number=3)
s, _ = Site.objects.get_or_create(name="phx1")
s1, _ = Site.objects.get_or_create(name="corp", parent=s)
d, _ = Domain.objects.get_or_create(name="phx1.mozilla.com")
d1, _ = Domain.objects.get_or_create(name="corp.phx1.mozilla.com")
d2, _ = Domain.objects.get_or_create(
name="private.corp.phx1.mozilla.com")
d, _ = Domain.objects.get_or_create(name="arpa")
d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
d, _ = Domain.objects.get_or_create(name="14.in-addr.arpa")
n = Network(network_str="14.0.0.0/8", ip_type="4")
n.clean()
n.site = s1
n.vlan = v
n.save()
r = Range(start_str="14.0.0.0", end_str="14.0.0.2",
network=n)
r.clean()
r.save()
intr, errors = create_ipv4_intr_from_domain(
"foo", "private.corp.phx1", self.system,
"11:22:33:44:55:66")
self.assertEqual(errors, None)
self.assertTrue(isinstance(intr, StaticInterface))
示例11: setUp
def setUp(self):
self.system = System()
self.system.save()
d1 = create_fake_zone("oregonstate.com", suffix="")
soa = d1.soa
self.soa = soa
v, _ = Vlan.objects.get_or_create(name="private", number=3)
s, _ = Site.objects.get_or_create(name="phx1")
s1, _ = Site.objects.get_or_create(name="corp", parent=s)
d, _ = Domain.objects.get_or_create(name="phx1.oregonstate.com")
d.soa = soa
d.save()
d1, _ = Domain.objects.get_or_create(name="corp.phx1.oregonstate.com")
d1.soa = soa
d1.save()
d2, _ = Domain.objects.get_or_create(
name="private.corp.phx1.oregonstate.com")
d2.soa = soa
d2.save()
d, _ = Domain.objects.get_or_create(name="arpa")
d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
d, _ = Domain.objects.get_or_create(name="15.in-addr.arpa")
n = Network(network_str="15.0.0.0/8", ip_type="4")
n.clean()
n.site = s1
n.vlan = v
n.save()
r = Range(start_str="15.0.0.0", end_str="15.0.0.10",
network=n, ip_type='4')
r.clean()
r.save()
示例12: test6_create_ipv4_interface
def test6_create_ipv4_interface(self):
v, _ = Vlan.objects.get_or_create(name="6db", number=3)
s, _ = Site.objects.get_or_create(name="6scl3")
d, _ = Domain.objects.get_or_create(name="6scl3.mozilla.com")
d, _ = Domain.objects.get_or_create(name="6db.6scl3.mozilla.com")
d, _ = Domain.objects.get_or_create(name="arpa")
d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
d, _ = Domain.objects.get_or_create(name="11.in-addr.arpa")
n = Network(network_str="11.0.0.0/8", ip_type="4")
n.clean()
n.site = s
n.vlan = v
n.save()
r = Range(start_str="11.0.0.0", end_str="11.0.0.2",
network=n, ip_type='4')
r.clean()
r.save()
s = StaticInterface(label="fab", domain=d, ip_type="4",
ip_str="11.0.0.0", system=self.system,
mac="00:00:00:00:00:00")
s.clean()
s.save()
s = StaticInterface(label="fab", domain=d, ip_type="4",
ip_str="11.0.0.1", system=self.system,
mac="00:00:00:00:00:00")
s.clean()
s.save()
s = StaticInterface(label="fab", domain=d, ip_type="4",
ip_str="11.0.0.2", system=self.system,
mac="00:00:00:00:00:00")
s.clean()
s.save()
intr, errors = create_ipv4_interface(
"foo", "6db", "6scl3", self.system,
"11:22:33:44:55:66", "mozilla.com")
self.assertEqual(intr, None)
self.assertTrue("vlan" not in errors)
self.assertTrue("site" not in errors)
self.assertTrue("domain" not in errors)
self.assertTrue("network" not in errors)
self.assertTrue("range" not in errors)
self.assertTrue("ip" in errors)
示例13: test5_create_ipv4_interface
def test5_create_ipv4_interface(self):
v, _ = Vlan.objects.get_or_create(name="5db", number=3)
s, _ = Site.objects.get_or_create(name="5scl3")
d, _ = Domain.objects.get_or_create(name="5scl3.mozilla.com")
d, _ = Domain.objects.get_or_create(name="5db.5scl3.mozilla.com")
n = Network(network_str="10.0.0.0/8", ip_type="4")
n.clean()
n.site = s
n.vlan = v
n.save()
intr, errors = create_ipv4_interface(
"foo", "5db", "5scl3", self.system,
"11:22:33:44:55:66", "mozilla.com")
self.assertEqual(intr, None)
self.assertTrue("vlan" not in errors)
self.assertTrue("site" not in errors)
self.assertTrue("domain" not in errors)
self.assertTrue("network" not in errors)
self.assertTrue("range" in errors)
示例14: setUp
def setUp(self):
self.system = System()
Domain.objects.get_or_create(name="com")
d1, _ = Domain.objects.get_or_create(name="mozilla.com")
soa, _ = SOA.objects.get_or_create(
primary="fo.bar", contact="foo.bar.com",
comment="foo bar")
self.s = soa
d1.soa = soa
d1.save()
v, _ = Vlan.objects.get_or_create(name="private", number=3)
s, _ = Site.objects.get_or_create(name="phx1")
s1, _ = Site.objects.get_or_create(name="corp", parent=s)
d, _ = Domain.objects.get_or_create(name="phx1.mozilla.com")
d.soa = soa
d.save()
d1, _ = Domain.objects.get_or_create(name="corp.phx1.mozilla.com")
d1.soa = soa
d1.save()
d2, _ = Domain.objects.get_or_create(
name="private.corp.phx1.mozilla.com")
d2.soa = soa
d2.save()
d, _ = Domain.objects.get_or_create(name="arpa")
d, _ = Domain.objects.get_or_create(name="in-addr.arpa")
d, _ = Domain.objects.get_or_create(name="ipv6.arpa")
d, _ = Domain.objects.get_or_create(name="15.in-addr.arpa")
d, _ = Domain.objects.get_or_create(name="2.in-addr.arpa")
n = Network(network_str="15.0.0.0/8", ip_type="4")
n.clean()
n.site = s1
n.vlan = v
n.save()
r = Range(start_str="15.0.0.0", end_str="15.0.0.10",
network=n)
r.clean()
r.save()
示例15: sif
site = Site.objects.get(name=site_str)
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)