]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - addons/loopback.py
3 # This should be pretty simple and might not really even need to exist.
4 # The key is that we need to call link_create with a type of "dummy"
5 # since that will translate to 'ip link add loopbackX type dummy'
6 # The config file should probably just indicate that the type is
9 from ifupdown
.iface
import *
10 from ifupdownaddons
.modulebase
import moduleBase
11 from ifupdownaddons
.iproute2
import iproute2
14 class loopback(moduleBase
):
15 _modinfo
= {'mhelp' : 'configure extra loopback module based on ' +
18 def __init__(self
, *args
, **kargs
):
19 moduleBase
.__init
__(self
, *args
, **kargs
)
22 def _is_loopback_by_name(self
, ifacename
):
23 return 'loop' in ifacename
25 def _up(self
, ifaceobj
):
26 if self
._is
_loopback
_by
_name
(ifaceobj
.name
):
27 self
.ipcmd
.link_create(ifaceobj
.name
, 'dummy')
29 def _down(self
, ifaceobj
):
30 if not self
.PERFMODE
and not self
.ipcmd
.link_exists(ifaceobj
.name
):
33 self
.ipcmd
.link_delete(ifaceobj
.name
)
37 def _query_check(self
, ifaceobj
, ifaceobjcurr
):
38 if not self
.ipcmd
.link_exists(ifaceobj
.name
):
39 ifaceobjcurr
.status
= ifaceStatus
.NOTFOUND
42 _run_ops
= {'pre-up' : _up
,
44 'query-checkcurr' : _query_check
}
47 return self
._run
_ops
.keys()
49 def _init_command_handlers(self
):
51 self
.ipcmd
= iproute2(**self
.get_flags())
53 def run(self
, ifaceobj
, operation
, query_ifaceobj
=None):
54 op_handler
= self
._run
_ops
.get(operation
)
57 if (operation
!= 'query-running' and
58 not self
._is
_loopback
_by
_name
(ifaceobj
.name
)):
60 self
._init
_command
_handlers
()
61 if operation
== 'query-checkcurr':
62 op_handler(self
, ifaceobj
, query_ifaceobj
)
64 op_handler(self
, ifaceobj
)