]>
git.proxmox.com Git - mirror_ifupdown2.git/blob - ifupdown2/addons/ethtool.py
579fdfae7c4a58b445219cf89f46ab6c4b53d262
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
):
62 Advertised auto-negotiation: No
65 ethtool_attrs
= self
.dict_key_subset(ifaceobj
.config
,
70 speed
= ifaceobj
.get_attr_value_first('link-speed')
72 running_speed
= self
.read_file_oneline(
73 '/sys/class/net/%s/speed' %ifaceobj
.name
)
74 if running_speed
and running_speed
!= speed
:
75 ifaceobjcurr
.update_config_with_status('link-speed',
78 ifaceobjcurr
.update_config_with_status('link-speed',
80 duplex
= ifaceobj
.get_attr_value_first('link-duplex')
82 running_duplex
= self
.read_file_oneline(
83 '/sys/class/net/%s/duplex' %ifaceobj
.name
)
84 if running_duplex
and running_duplex
!= duplex
:
85 ifaceobjcurr
.update_config_with_status('link-duplex',
88 ifaceobjcurr
.update_config_with_status('link-duplex',
94 def _query_running(self
, ifaceobjrunning
):
97 _run_ops
= {'post-up' : _post_up
,
98 'query-checkcurr' : _query_check
,
99 'query-running' : _query_running
}
102 """ returns list of ops supported by this module """
103 return self
._run
_ops
.keys()
105 def _init_command_handlers(self
):
107 self
.ipcmd
= iproute2(**self
.get_flags())
109 def run(self
, ifaceobj
, operation
, query_ifaceobj
=None, **extra_args
):
110 """ run ethtool configuration on the interface object passed as
114 **ifaceobj** (object): iface object
116 **operation** (str): any of 'post-up', 'query-checkcurr',
119 **query_ifaceobj** (object): query check ifaceobject. This is only
120 valid when op is 'query-checkcurr'. It is an object same as
121 ifaceobj, but contains running attribute values and its config
122 status. The modules can use it to return queried running state
123 of interfaces. status is success if the running state is same
124 as user required state in ifaceobj. error otherwise.
126 op_handler
= self
._run
_ops
.get(operation
)
129 self
._init
_command
_handlers
()
130 if operation
== 'query-checkcurr':
131 op_handler(self
, ifaceobj
, query_ifaceobj
)
133 op_handler(self
, ifaceobj
)