3d870e5d591f742980b9ad3d7e049502ffdf74ac
[pyi2ncommon] / src / cnfline / build_nic.py
1 # The software in this package is distributed under the GNU General
2 # Public License version 2 (with a special exception described below).
3 #
4 # A copy of GNU General Public License (GPL) is included in this distribution,
5 # in the file COPYING.GPL.
6 #
7 # As a special exception, if other files instantiate templates or use macros
8 # or inline functions from this file, or you compile this file and link it
9 # with other works to produce a work based on this file, this file
10 # does not by itself cause the resulting work to be covered
11 # by the GNU General Public License.
12 #
13 # However the source code for this file must still be made available
14 # in accordance with section (3) of the GNU General Public License.
15 #
16 # This exception does not invalidate any other reasons why a work based
17 # on this file might be covered by the GNU General Public License.
18 #
19 # Copyright (c) 2016-2018 Intra2net AG <info@intra2net.com>
20
21 from .build_cnfvar import BuildCnfVar
22 """Class to create user cnfvar objects on the fly"""
23
24
25 class BuildNIC(BuildCnfVar):
26
27     def __init__(self, data='', instance=0, line_no=1):
28         BuildCnfVar.__init__(self, 'NIC', instance, '', line_no)
29
30         # the bare defaults the UI adds upon
31         # creation of new groups
32         defaults = {
33             'NIC_COMMENT': data,
34             'NIC_DRIVER': 'virtio_net',
35             'NIC_LAN_DNS_RELAYING_ALLOWED': "0",
36             'NIC_LAN_EMAIL_RELAYING_ALLOWED': "0",
37             'NIC_LAN_FIREWALL_RULESET_REF': "1",
38             'NIC_LAN_IP': "192.168.1.1",
39             'NIC_LAN_NAT_INTO': "0",
40             'NIC_LAN_NETMASK': "255.255.255.0",
41             'NIC_LAN_PROXY_PROFILE_REF': "-1",
42             'NIC_MAC': '02:00:00:00:20:00',
43             'NIC_TYPE': 'DSLROUTER',
44         }
45
46         self.add_defaults(defaults)
47
48     def comment(self, comment):
49         self.update_cnf('NIC_COMMENT', 0, comment)
50         return self
51
52     def nic_type(self, nic_type):
53         self.update_cnf('NIC_TYPE', 0, nic_type)
54         return self
55
56     def lan_ip(self, lan_ip):
57         self.update_cnf('NIC_LAN_IP', 0, lan_ip)
58         return self
59
60     def add_group_member_ref(self, group_ref):
61         self.add_cnf('USER_GROUP_MEMBER_REF', -1, group_ref)
62         return self