~cloud-init-dev/cloud-init/trunk

« back to all changes in this revision

Viewing changes to cloudinit/net/renderer.py

support network rendering to sysconfig (for centos and RHEL)

This intends to add support for rendering of network data under sysconfig
distributions (centos and rhel).  The end result will be support for
network configuration via ConfigDrive or NoCloud on these OS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#   Copyright (C) 2013-2014 Canonical Ltd.
 
2
#
 
3
#   Author: Scott Moser <scott.moser@canonical.com>
 
4
#   Author: Blake Rouse <blake.rouse@canonical.com>
 
5
#
 
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.
 
10
#
 
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
 
14
#   more details.
 
15
#
 
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/>.
 
18
 
 
19
import six
 
20
 
 
21
from .udev import generate_udev_rule
 
22
 
 
23
 
 
24
def filter_by_type(match_type):
 
25
    return lambda iface: match_type == iface['type']
 
26
 
 
27
 
 
28
def filter_by_name(match_name):
 
29
    return lambda iface: match_name == iface['name']
 
30
 
 
31
 
 
32
filter_by_physical = filter_by_type('physical')
 
33
 
 
34
 
 
35
class Renderer(object):
 
36
 
 
37
    @staticmethod
 
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()