1
# Copyright (C) 2013-2014 Canonical Ltd.
3
# Author: Scott Moser <scott.moser@canonical.com>
4
# Author: Blake Rouse <blake.rouse@canonical.com>
6
# Curtin is free software: you can redistribute it and/or modify it under
7
# the terms of the GNU Affero General Public License as published by the
8
# Free Software Foundation, either version 3 of the License, or (at your
9
# option) any later version.
11
# Curtin is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
16
# You should have received a copy of the GNU Affero General Public License
17
# along with Curtin. If not, see <http://www.gnu.org/licenses/>.
21
from .udev import generate_udev_rule
24
def filter_by_type(match_type):
25
return lambda iface: match_type == iface['type']
28
def filter_by_name(match_name):
29
return lambda iface: match_name == iface['name']
32
filter_by_physical = filter_by_type('physical')
35
class Renderer(object):
38
def _render_persistent_net(network_state):
39
"""Given state, emit udev rules to map mac to ifname."""
40
# TODO(harlowja): this seems shared between eni renderer and
41
# this, so move it to a shared location.
42
content = six.StringIO()
43
for iface in network_state.iter_interfaces(filter_by_physical):
44
# for physical interfaces write out a persist net udev rule
45
if 'name' in iface and iface.get('mac_address'):
46
content.write(generate_udev_rule(iface['name'],
47
iface['mac_address']))
48
return content.getvalue()