aboutsummaryrefslogtreecommitdiffstats
path: root/os_net_config
diff options
context:
space:
mode:
Diffstat (limited to 'os_net_config')
-rw-r--r--os_net_config/impl_ifcfg.py5
-rw-r--r--os_net_config/objects.py12
-rw-r--r--os_net_config/tests/test_impl_ifcfg.py15
-rw-r--r--os_net_config/tests/test_objects.py2
4 files changed, 30 insertions, 4 deletions
diff --git a/os_net_config/impl_ifcfg.py b/os_net_config/impl_ifcfg.py
index 4a4caaa..e8dbd46 100644
--- a/os_net_config/impl_ifcfg.py
+++ b/os_net_config/impl_ifcfg.py
@@ -113,6 +113,8 @@ class IfcfgNetConfig(os_net_config.NetConfig):
data += "TYPE=NFVSWITCHIntPort\n"
elif isinstance(base_opt, objects.IbInterface):
data += "TYPE=Infiniband\n"
+ if base_opt.ethtool_opts:
+ data += "ETHTOOL_OPTS=\"%s\"\n" % base_opt.ethtool_opts
elif re.match('\w+\.\d+$', base_opt.name):
data += "VLAN=yes\n"
if base_opt.linux_bond_name:
@@ -262,6 +264,9 @@ class IfcfgNetConfig(os_net_config.NetConfig):
data += "BOOTPROTO=dhcp\n"
elif not base_opt.addresses:
data += "BOOTPROTO=none\n"
+ if isinstance(base_opt, objects.Interface):
+ if base_opt.ethtool_opts:
+ data += "ETHTOOL_OPTS=\"%s\"\n" % base_opt.ethtool_opts
if base_opt.mtu:
data += "MTU=%i\n" % base_opt.mtu
diff --git a/os_net_config/objects.py b/os_net_config/objects.py
index 0e5ce08..8d7ee4c 100644
--- a/os_net_config/objects.py
+++ b/os_net_config/objects.py
@@ -279,7 +279,7 @@ class Interface(_BaseOpts):
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
routes=None, mtu=None, primary=False, nic_mapping=None,
persist_mapping=False, defroute=True, dhclient_args=None,
- dns_servers=None):
+ dns_servers=None, ethtool_opts=None):
addresses = addresses or []
routes = routes or []
dns_servers = dns_servers or []
@@ -287,12 +287,14 @@ class Interface(_BaseOpts):
routes, mtu, primary, nic_mapping,
persist_mapping, defroute,
dhclient_args, dns_servers)
+ self.ethtool_opts = ethtool_opts
@staticmethod
def from_json(json):
name = _get_required_field(json, 'name', 'Interface')
opts = _BaseOpts.base_opts_from_json(json)
- return Interface(name, *opts)
+ ethtool_opts = json.get('ethtool_opts', None)
+ return Interface(name, *opts, ethtool_opts=ethtool_opts)
class Vlan(_BaseOpts):
@@ -931,7 +933,7 @@ class IbInterface(_BaseOpts):
def __init__(self, name, use_dhcp=False, use_dhcpv6=False, addresses=None,
routes=None, mtu=None, primary=False, nic_mapping=None,
persist_mapping=False, defroute=True, dhclient_args=None,
- dns_servers=None):
+ dns_servers=None, ethtool_opts=None):
addresses = addresses or []
routes = routes or []
dns_servers = dns_servers or []
@@ -939,12 +941,14 @@ class IbInterface(_BaseOpts):
addresses, routes, mtu, primary,
nic_mapping, persist_mapping,
defroute, dhclient_args, dns_servers)
+ self.ethtool_opts = ethtool_opts
@staticmethod
def from_json(json):
name = _get_required_field(json, 'name', 'IbInterface')
+ ethtool_opts = json.get('ethtool_opts', None)
opts = _BaseOpts.base_opts_from_json(json)
- return IbInterface(name, *opts)
+ return IbInterface(name, *opts, ethtool_opts=ethtool_opts)
class OvsDpdkPort(_BaseOpts):
diff --git a/os_net_config/tests/test_impl_ifcfg.py b/os_net_config/tests/test_impl_ifcfg.py
index 0c14418..2e79aa1 100644
--- a/os_net_config/tests/test_impl_ifcfg.py
+++ b/os_net_config/tests/test_impl_ifcfg.py
@@ -742,6 +742,21 @@ DHCLIENTARGS=--foobar
"""
self.assertEqual(em1_config, self.get_interface_config('em1'))
+ def test_interface_ethtool_opts(self):
+ interface1 = objects.Interface('em1',
+ ethtool_opts='speed 1000 duplex full')
+ self.provider.add_interface(interface1)
+ em1_config = """# This file is autogenerated by os-net-config
+DEVICE=em1
+ONBOOT=yes
+HOTPLUG=no
+NM_CONTROLLED=no
+PEERDNS=no
+BOOTPROTO=none
+ETHTOOL_OPTS=\"speed 1000 duplex full\"
+"""
+ self.assertEqual(em1_config, self.get_interface_config('em1'))
+
def test_interface_single_dns_server(self):
interface1 = objects.Interface('em1', dns_servers=['1.2.3.4'])
self.provider.add_interface(interface1)
diff --git a/os_net_config/tests/test_objects.py b/os_net_config/tests/test_objects.py
index 4c71265..3911ef3 100644
--- a/os_net_config/tests/test_objects.py
+++ b/os_net_config/tests/test_objects.py
@@ -150,6 +150,7 @@ class TestInterface(base.TestCase):
"name": "em1",
"use_dhcp": false,
"mtu": 1501,
+"ethtool_opts": "speed 1000 duplex full",
"addresses": [{
"ip_netmask": "192.0.2.1/24"
}],
@@ -165,6 +166,7 @@ class TestInterface(base.TestCase):
self.assertFalse(interface.use_dhcp)
self.assertFalse(interface.use_dhcpv6)
self.assertEqual(1501, interface.mtu)
+ self.assertEqual("speed 1000 duplex full", interface.ethtool_opts)
address1 = interface.v4_addresses()[0]
self.assertEqual("192.0.2.1", address1.ip)
self.assertEqual("255.255.255.0", address1.netmask)