当前位置: 首页>>代码示例>>Python>>正文


Python netjsonconfig.OpenWrt类代码示例

本文整理汇总了Python中netjsonconfig.OpenWrt的典型用法代码示例。如果您正苦于以下问题:Python OpenWrt类的具体用法?Python OpenWrt怎么用?Python OpenWrt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OpenWrt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_radio_list_option

    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)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:26,代码来源:test_radio.py

示例2: test_radio_ac_and_custom_attrs

    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)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:30,代码来源:test_radio.py

示例3: test_radio_mac80211b

    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)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:25,代码来源:test_radio.py

示例4: test_macaddr_override

    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)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:32,代码来源:test_wireless.py

示例5: test_wifi_iface_list_option

    def test_wifi_iface_list_option(self):
        o = OpenWrt({
            "interfaces": [
                {
                    "name": "wlan0",
                    "type": "wireless",
                    "wireless": {
                        "radio": "radio0",
                        "mode": "access_point",
                        "ssid": "open",
                        "basic_rate": ["6000", "9000"]
                    }
                }
            ]
        })
        expected = self._tabs("""package network

config interface 'wlan0'
    option ifname 'wlan0'
    option proto 'none'

package wireless

config wifi-iface 'wifi_wlan0'
    list basic_rate '6000'
    list basic_rate '9000'
    option device 'radio0'
    option ifname 'wlan0'
    option mode 'ap'
    option network 'wlan0'
    option ssid 'open'
""")
        self.assertEqual(o.render(), expected)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:33,代码来源:test_wireless.py

示例6: test_wds_ap

    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)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:32,代码来源:test_wireless.py

示例7: test_led_1

    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)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:32,代码来源:test_system.py

示例8: test_server_bridge_routed

    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)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:33,代码来源:test_openvpn.py

示例9: test_rules

    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)
开发者ID:gonrin,项目名称:netjsonconfig,代码行数:60,代码来源:test_network.py

示例10: test_interface_custom_attrs

    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)
开发者ID:gonrin,项目名称:netjsonconfig,代码行数:27,代码来源:test_network.py

示例11: test_default_addresses

    def test_default_addresses(self):
        """
        the following configuration dictionary caused empty output up to 0.4.0
        """
        o = OpenWrt({
            "interfaces": [
                {
                    "type": "bridge",
                    "network": "lan",
                    "addresses": [],
                    "name": "br-lan",
                    "bridge_members": [
                        "eth0",
                        "eth1"
                    ]
                }
            ]
        })
        expected = self._tabs("""package network

config interface 'lan'
    option ifname 'eth0 eth1'
    option proto 'none'
    option type 'bridge'
""")
        self.assertEqual(o.render(), expected)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:26,代码来源:test_network.py

示例12: test_multiple_dhcp

    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)
开发者ID:gonrin,项目名称:netjsonconfig,代码行数:30,代码来源:test_network.py

示例13: test_loopback

    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)
开发者ID:gonrin,项目名称:netjsonconfig,代码行数:25,代码来源:test_network.py

示例14: test_address_list_option

    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)
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:25,代码来源:test_network.py

示例15: test_file_inclusion

 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()
开发者ID:openwisp,项目名称:netjsonconfig,代码行数:34,代码来源:test_backend.py


注:本文中的netjsonconfig.OpenWrt类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。