]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/addons/usercmds.py
3 # Copyright 2014-2017 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
10 from ifupdown2
.ifupdown
.utils
import utils
12 from ifupdown2
.ifupdownaddons
.modulebase
import moduleBase
14 from ifupdown
.utils
import utils
16 from ifupdownaddons
.modulebase
import moduleBase
19 class usercmds(moduleBase
):
20 """ ifupdown2 addon module to configure user specified commands """
22 _modinfo
= {'mhelp' : 'user commands for interfaces',
25 {'help' : 'run command before bringing the interface up',
28 {'help' : 'run command at interface bring up',
31 {'help' : 'run command after interface bring up',
34 {'help' : 'run command before bringing the interface down',
37 {'help' : 'run command at interface down',
40 {'help' : 'run command after bringing interface down',
43 def _run_command(self
, ifaceobj
, op
):
44 cmd_list
= ifaceobj
.get_attr_value(op
)
46 os
.environ
['IFACE'] = ifaceobj
.name
if ifaceobj
.name
else ''
47 os
.environ
['LOGICAL'] = ifaceobj
.name
if ifaceobj
.name
else ''
48 os
.environ
['METHOD'] = ifaceobj
.addr_method
if ifaceobj
.addr_method
else ''
49 os
.environ
['ADDRFAM'] = ','.join(ifaceobj
.addr_family
) if ifaceobj
.addr_family
else ''
52 utils
.exec_user_command(cmd
)
54 if not self
.ignore_error(str(e
)):
55 self
.logger
.warn('%s: %s %s' % (ifaceobj
.name
, op
,
59 def _query_check(self
, ifaceobj
, ifaceobjcurr
):
67 for cmd
in ifaceobj
.config
.get(ops
, []):
68 ifaceobjcurr
.update_config_with_status(ops
, cmd
, -1)
70 _run_ops
= {'pre-up' : _run_command
,
71 'pre-down' : _run_command
,
73 'post-up' : _run_command
,
74 'down' : _run_command
,
75 'post-down' : _run_command
,
76 'query-checkcurr': _query_check
}
79 """ returns list of ops supported by this module """
80 return self
._run
_ops
.keys()
82 def run(self
, ifaceobj
, operation
, query_ifaceobj
=None, **extra_args
):
86 **ifaceobj** (object): iface object
88 **operation** (str): list of ops
91 **query_ifaceobj** (object): query check ifaceobject. This is only
92 valid when op is 'query-checkcurr'. It is an object same as
93 ifaceobj, but contains running attribute values and its config
94 status. The modules can use it to return queried running state
95 of interfaces. status is success if the running state is same
96 as user required state in ifaceobj. error otherwise.
98 op_handler
= self
._run
_ops
.get(operation
)
101 if operation
== 'query-checkcurr':
102 op_handler(self
, ifaceobj
, query_ifaceobj
)
104 op_handler(self
, ifaceobj
, operation
)