def apply_network_profile(name, network_profile, nic_opts=None, path=None):
    '''
    .. versionadded:: 2015.5.0

    Apply a network profile to a container

    network_profile
        profile name or default values (dict)

    nic_opts
        values to override in defaults (dict)
        indexed by nic card names

    path
        path to the container parent

        .. versionadded:: 2015.8.0

    CLI Examples:

    .. code-block:: bash

        salt 'minion' lxc.apply_network_profile web1 centos
        salt 'minion' lxc.apply_network_profile web1 centos \\
                nic_opts="{'eth0': {'mac': 'xx:xx:xx:xx:xx:xx'}}"
        salt 'minion' lxc.apply_network_profile web1 \\
                "{'eth0': {'mac': 'xx:xx:xx:xx:xx:yy'}}"
                nic_opts="{'eth0': {'mac': 'xx:xx:xx:xx:xx:xx'}}"

    The special case to disable use of ethernet nics:

    .. code-block:: bash

        salt 'minion' lxc.apply_network_profile web1 centos \\
                "{eth0: {disable: true}}"
    '''
    cpath = get_root_path(path)
    cfgpath = os.path.join(cpath, name, 'config')

    before = []
    with salt.utils.files.fopen(cfgpath, 'r') as fp_:
        for line in fp_:
            before.append(line)

    lxcconfig = _LXCConfig(name=name, path=path)
    old_net = lxcconfig._filter_data('lxc.network')

    network_params = {}
    for param in _network_conf(
        conf_tuples=old_net,
        network_profile=network_profile, nic_opts=nic_opts
    ):
        network_params.update(param)
    if network_params:
        edit_conf(cfgpath, out_format='commented', **network_params)

    after = []
    with salt.utils.files.fopen(cfgpath, 'r') as fp_:
        for line in fp_:
            after.append(line)

    diff = ''
    for line in difflib.unified_diff(before,
                                     after,
                                     fromfile='before',
                                     tofile='after'):
        diff += line
    return diff
def apply_network_profile ( name , network_profile , nic_opts = None , path = None ) : cpath = get_root_path ( path ) cfgpath = os . path . join ( cpath , name , 'config' ) before = [ ] with salt . utils . files . fopen ( cfgpath , 'r' ) as fp_ : for line in fp_ : before . append ( line ) lxcconfig = _LXCConfig ( name = name , path = path ) old_net = lxcconfig . _filter_data ( 'lxc.network' ) network_params = { } for param in _network_conf ( conf_tuples = old_net , network_profile = network_profile , nic_opts = nic_opts ) : network_params . update ( param ) if network_params : edit_conf ( cfgpath , out_format = 'commented' , ** network_params ) after = [ ] with salt . utils . files . fopen ( cfgpath , 'r' ) as fp_ : for line in fp_ : after . append ( line ) diff = '' for line in difflib . unified_diff ( before , after , fromfile = 'before' , tofile = 'after' ) : diff += line return diff
.. versionadded:: 2015.5.0

    Apply a network profile to a container

    network_profile
        profile name or default values (dict)

    nic_opts
        values to override in defaults (dict)
        indexed by nic card names

    path
        path to the container parent

        .. versionadded:: 2015.8.0

    CLI Examples:

    .. code-block:: bash

        salt 'minion' lxc.apply_network_profile web1 centos
        salt 'minion' lxc.apply_network_profile web1 centos \\
                nic_opts="{'eth0': {'mac': 'xx:xx:xx:xx:xx:xx'}}"
        salt 'minion' lxc.apply_network_profile web1 \\
                "{'eth0': {'mac': 'xx:xx:xx:xx:xx:yy'}}"
                nic_opts="{'eth0': {'mac': 'xx:xx:xx:xx:xx:xx'}}"

    The special case to disable use of ethernet nics:

    .. code-block:: bash

        salt 'minion' lxc.apply_network_profile web1 centos \\
                "{eth0: {disable: true}}"