本文整理汇总了Python中netjsonconfig.OpenWrt.render方法的典型用法代码示例。如果您正苦于以下问题:Python OpenWrt.render方法的具体用法?Python OpenWrt.render怎么用?Python OpenWrt.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netjsonconfig.OpenWrt
的用法示例。
在下文中一共展示了OpenWrt.render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_server_bridge_routed
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_server_bridge_routed(self):
c = OpenWrt({
"openvpn": [{
"ca": "ca.pem",
"cert": "cert.pem",
"dev": "tap0",
"dev_type": "tap",
"dh": "dh.pem",
"enabled": True,
"key": "key.pem",
"mode": "server",
"name": "routed",
"proto": "udp",
"server": "10.8.0.0 255.255.0.0",
"tls_server": True
}]
})
expected = self._tabs("""package openvpn
config openvpn 'routed'
option ca 'ca.pem'
option cert 'cert.pem'
option dev 'tap0'
option dev_type 'tap'
option dh 'dh.pem'
option enabled '1'
option key 'key.pem'
option mode 'server'
option proto 'udp'
option server '10.8.0.0 255.255.0.0'
option tls_server '1'
""")
self.assertEqual(c.render(), expected)
示例2: test_rules
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_rules(self):
o = OpenWrt({
"ip_rules": [
{
"in": "eth0",
"out": "eth1",
"src": "192.168.1.0/24",
"dest": "192.168.2.0/24",
"tos": 2,
"mark": "0x0/0x1",
"invert": True,
"lookup": "0",
"action": "blackhole"
},
{
"src": "192.168.1.0/24",
"dest": "192.168.3.0/24",
"goto": 0
},
{
"in": "vpn",
"dest": "fdca:1234::/64",
"action": "prohibit"
},
{
"in": "vpn",
"src": "fdca:1235::/64",
"action": "prohibit"
}
]
})
expected = self._tabs("""package network
config rule
option action 'blackhole'
option dest '192.168.2.0/24'
option in 'eth0'
option invert '1'
option lookup '0'
option mark '0x0/0x1'
option out 'eth1'
option src '192.168.1.0/24'
option tos '2'
config rule
option dest '192.168.3.0/24'
option goto '0'
option src '192.168.1.0/24'
config rule6
option action 'prohibit'
option dest 'fdca:1234::/64'
option in 'vpn'
config rule6
option action 'prohibit'
option in 'vpn'
option src 'fdca:1235::/64'
""")
self.assertEqual(o.render(), expected)
示例3: test_radio_list_option
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_radio_list_option(self):
o = OpenWrt({
"radios": [
{
"name": "radio0",
"phy": "phy0",
"driver": "mac80211",
"protocol": "802.11n",
"channel": 1,
"channel_width": 20,
"ht_capab": ["SMPS-STATIC", "SHORT-GI-20"]
}
]
})
expected = self._tabs("""package wireless
config wifi-device 'radio0'
option channel '1'
list ht_capab 'SMPS-STATIC'
list ht_capab 'SHORT-GI-20'
option htmode 'HT20'
option hwmode '11g'
option phy 'phy0'
option type 'mac80211'
""")
self.assertEqual(o.render(), expected)
示例4: test_file_inclusion
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_file_inclusion(self):
o = OpenWrt({
"files": [
{
"path": "/etc/crontabs/root",
"mode": "0644",
"contents": '* * * * * echo "test" > /etc/testfile\n'
'* * * * * echo "test2" > /etc/testfile2'
},
{
"path": "/etc/dummy.conf",
"mode": "0644",
"contents": "testing!"
}
]
})
output = o.render()
self.assertNotIn('package files', output)
self.assertIn('* * * * * echo', output)
# ensure the additional files are there present in the tar.gz archive
tar = tarfile.open(fileobj=o.generate(), mode='r')
self.assertEqual(len(tar.getmembers()), 2)
# first file
crontab = tar.getmember('etc/crontabs/root')
contents = tar.extractfile(crontab).read().decode()
self.assertEqual(contents, o.config['files'][0]['contents'])
self.assertEqual(crontab.mtime, 0)
self.assertEqual(crontab.mode, 420)
# second file
dummy = tar.getmember('etc/dummy.conf')
contents = tar.extractfile(dummy).read().decode()
self.assertEqual(contents, o.config['files'][1]['contents'])
self.assertEqual(dummy.mode, 420)
tar.close()
示例5: test_radio_mac80211b
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_radio_mac80211b(self):
o = OpenWrt({
"radios": [
{
"name": "radio0",
"phy": "phy0",
"driver": "mac80211",
"protocol": "802.11b",
"channel": 3,
"channel_width": 20,
"tx_power": 3
}
]
})
expected = self._tabs("""package wireless
config wifi-device 'radio0'
option channel '3'
option htmode 'NONE'
option hwmode '11b'
option phy 'phy0'
option txpower '3'
option type 'mac80211'
""")
self.assertEqual(o.render(), expected)
示例6: test_radio_ac_and_custom_attrs
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_radio_ac_and_custom_attrs(self):
o = OpenWrt({
"radios": [
{
"name": "radio0",
"phy": "phy0",
"driver": "mac80211",
"protocol": "802.11ac",
"channel": 132,
"channel_width": 80,
"tx_power": 8,
"diversity": True,
"country_ie": True,
"empty_setting": ""
}
]
})
expected = self._tabs("""package wireless
config wifi-device 'radio0'
option channel '132'
option country_ie '1'
option diversity '1'
option htmode 'VHT80'
option hwmode '11a'
option phy 'phy0'
option txpower '8'
option type 'mac80211'
""")
self.assertEqual(o.render(), expected)
示例7: test_macaddr_override
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_macaddr_override(self):
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"mac": "E8:94:F6:33:8C:00",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "open"
}
}
]
})
expected = self._tabs("""package network
config interface 'wlan0'
option ifname 'wlan0'
option proto 'none'
package wireless
config wifi-iface 'wifi_wlan0'
option device 'radio0'
option ifname 'wlan0'
option macaddr 'E8:94:F6:33:8C:00'
option mode 'ap'
option network 'wlan0'
option ssid 'open'
""")
self.assertEqual(o.render(), expected)
示例8: test_led_1
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_led_1(self):
o = OpenWrt({
"led": [
{
"name": "USB1",
"sysfs": "tp-link:green:usb1",
"trigger": "usbdev",
"dev": "1-1.1",
"interval": 50,
},
{
"name": "WLAN2G",
"sysfs": "tp-link:blue:wlan2g",
"trigger": "phy0tpt"
}
]
})
expected = self._tabs("""package system
config led 'led_usb1'
option dev '1-1.1'
option interval '50'
option name 'USB1'
option sysfs 'tp-link:green:usb1'
option trigger 'usbdev'
config led 'led_wlan2g'
option name 'WLAN2G'
option sysfs 'tp-link:blue:wlan2g'
option trigger 'phy0tpt'
""")
self.assertEqual(o.render(), expected)
示例9: test_wds_ap
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_wds_ap(self):
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"wds": True,
"ssid": "MyWdsAp"
}
}
]
})
expected = self._tabs("""package network
config interface 'wlan0'
option ifname 'wlan0'
option proto 'none'
package wireless
config wifi-iface 'wifi_wlan0'
option device 'radio0'
option ifname 'wlan0'
option mode 'ap'
option network 'wlan0'
option ssid 'MyWdsAp'
option wds '1'
""")
self.assertEqual(o.render(), expected)
示例10: test_interface_custom_attrs
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_interface_custom_attrs(self):
o = OpenWrt({
"interfaces": [
{
"name": "mobile0",
"type": "wireless",
"mtu": 1400,
"custom_attr": "yes",
"empty": "",
"addresses": [
{
"proto": "3g",
"family": "ipv4"
}
]
}
]
})
expected = self._tabs("""package network
config interface 'mobile0'
option custom_attr 'yes'
option ifname 'mobile0'
option mtu '1400'
option proto '3g'
""")
self.assertEqual(o.render(), expected)
示例11: test_custom_proto
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_custom_proto(self):
o = OpenWrt({
"interfaces": [
{
"name": "ppp0",
"type": "other",
"proto": "ppp",
"device": "/dev/usb/modem1",
"username": "user1",
"password": "pwd0123",
"keepalive": 3,
"ipv6": True
}
]
})
expected = self._tabs("""package network
config interface 'ppp0'
option device '/dev/usb/modem1'
option ifname 'ppp0'
option ipv6 '1'
option keepalive '3'
option password 'pwd0123'
option proto 'ppp'
option username 'user1'
""")
self.assertEqual(o.render(), expected)
示例12: test_loopback
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_loopback(self):
o = OpenWrt({
"interfaces": [
{
"name": "lo",
"type": "loopback",
"addresses": [
{
"address": "127.0.0.1",
"mask": 8,
"proto": "static",
"family": "ipv4"
}
]
}
]
})
expected = self._tabs("""package network
config interface 'lo'
option ifname 'lo'
option ipaddr '127.0.0.1/8'
option proto 'static'
""")
self.assertEqual(o.render(), expected)
示例13: test_multiple_dhcp
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_multiple_dhcp(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"addresses": [
{
"proto": "dhcp",
"family": "ipv4"
},
{
"proto": "dhcp",
"family": "ipv6"
}
]
}
]
})
expected = self._tabs("""package network
config interface 'eth0'
option ifname 'eth0'
option proto 'dhcp'
config interface 'eth0_2'
option ifname 'eth0'
option proto 'dhcpv6'
""")
self.assertEqual(o.render(), expected)
示例14: test_network_dash_conversion
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_network_dash_conversion(self):
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "open",
"network": ["eth0-1"],
}
}
]
})
expected = self._tabs("""package network
config interface 'wlan0'
option ifname 'wlan0'
option proto 'none'
package wireless
config wifi-iface 'wifi_wlan0'
option device 'radio0'
option ifname 'wlan0'
option mode 'ap'
option network 'eth0_1'
option ssid 'open'
""")
self.assertEqual(o.render(), expected)
示例15: test_address_list_option
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import render [as 别名]
def test_address_list_option(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"addresses": [
{
"proto": "dhcp",
"family": "ipv4",
"reqopts": ["43", "54"]
}
]
}
]
})
expected = self._tabs("""package network
config interface 'eth0'
option ifname 'eth0'
option proto 'dhcp'
list reqopts '43'
list reqopts '54'
""")
self.assertEqual(o.render(), expected)