]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - addons/ethtool.py
3 # Copyright 2014 Cumulus Networks, Inc. All rights reserved.
4 # Author: Roopa Prabhu, roopa@cumulusnetworks.com
8 from ipaddr
import IPNetwork
10 from ifupdown
.iface
import *
11 from ifupdownaddons
.modulebase
import moduleBase
12 from ifupdownaddons
.iproute2
import iproute2
13 except ImportError, e
:
14 raise ImportError (str(e
) + "- required module not found")
16 class ethtool(moduleBase
):
17 """ ifupdown2 addon module to configure ethtool attributes """
19 _modinfo
= {'mhelp' : 'ethtool configuration module for interfaces',
22 {'help' : 'set link speed',
23 'example' : ['link-speed 1000']},
25 {'help': 'set link duplex',
26 'example' : ['link-duplex full'],
27 'validvals' : ['half', 'full'],
30 {'help': 'set autonegotiation',
31 'example' : ['link-autoneg on'],
32 'validvals' : ['on', 'off'],
35 def __init__(self
, *args
, **kargs
):
36 moduleBase
.__init
__(self
, *args
, **kargs
)
39 def _post_up(self
, ifaceobj
):
40 if not self
.ipcmd
.link_exists(ifaceobj
.name
):
43 attrval
= ifaceobj
.get_attr_value_first('link-speed')
45 cmd
+= ' speed %s' %attrval
46 attrval
= ifaceobj
.get_attr_value_first('link-duplex')
48 cmd
+= ' duplex %s' %attrval
49 attrval
= ifaceobj
.get_attr_value_first('link-autoneg')
51 cmd
+= ' autoneg %s' %attrval
54 cmd
= 'ethtool -s %s %s' %(ifaceobj
.name
, cmd
)
55 self
.exec_command(cmd
)
57 ifaceobj
.status
= ifaceStatus
.ERROR
58 self
.log_warn('%s: %s' %(ifaceobj
.name
, str(e
)))
60 def _query_check(self
, ifaceobj
, ifaceobjcurr
):
63 def _query_running(self
, ifaceobjrunning
):
66 _run_ops
= {'post-up' : _post_up
,
67 'query-checkcurr' : _query_check
,
68 'query-running' : _query_running
}
71 """ returns list of ops supported by this module """
72 return self
._run
_ops
.keys()
74 def _init_command_handlers(self
):
76 self
.ipcmd
= iproute2(**self
.get_flags())
78 def run(self
, ifaceobj
, operation
, query_ifaceobj
=None):
79 """ run ethtool configuration on the interface object passed as
83 **ifaceobj** (object): iface object
85 **operation** (str): any of 'post-up', 'query-checkcurr',
88 **query_ifaceobj** (object): query check ifaceobject. This is only
89 valid when op is 'query-checkcurr'. It is an object same as
90 ifaceobj, but contains running attribute values and its config
91 status. The modules can use it to return queried running state
92 of interfaces. status is success if the running state is same
93 as user required state in ifaceobj. error otherwise.
95 op_handler
= self
._run
_ops
.get(operation
)
98 self
._init
_command
_handlers
()
99 if operation
== 'query-checkcurr':
100 op_handler(self
, ifaceobj
, query_ifaceobj
)
102 op_handler(self
, ifaceobj
)