Reconfigure a container.

    This only applies to a few property

    name
        Name of the container.
    utsname
        utsname of the container.

        .. versionadded:: 2016.3.0

    rootfs
        rootfs of the container.

        .. versionadded:: 2016.3.0

    cpu
        Select a random number of cpu cores and assign it to the cpuset, if the
        cpuset option is set then this option will be ignored
    cpuset
        Explicitly define the cpus this container will be bound to
    cpushare
        cgroups cpu shares.
    autostart
        autostart container on reboot
    memory
        cgroups memory limit, in MB.
        (0 for nolimit, None for old default 1024MB)
    gateway
        the ipv4 gateway to use
        the default does nothing more than lxcutils does
    bridge
        the bridge to use
        the default does nothing more than lxcutils does
    nic
        Network interfaces profile (defined in config or pillar).

    nic_opts
        Extra options for network interfaces, will override

        ``{"eth0": {"mac": "aa:bb:cc:dd:ee:ff", "ipv4": "10.1.1.1", "ipv6": "2001:db8::ff00:42:8329"}}``

        or

        ``{"eth0": {"mac": "aa:bb:cc:dd:ee:ff", "ipv4": "10.1.1.1/24", "ipv6": "2001:db8::ff00:42:8329"}}``

    path
        path to the container parent

        .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt-call -lall mc_lxc_fork.reconfigure foobar nic_opts="{'eth1': {'mac': '00:16:3e:dd:ee:44'}}" memory=4

def reconfigure(name,
                cpu=None,
                cpuset=None,
                cpushare=None,
                memory=None,
                profile=None,
                network_profile=None,
                nic_opts=None,
                bridge=None,
                gateway=None,
                autostart=None,
                utsname=None,
                rootfs=None,
                path=None,
                **kwargs):
    '''
    Reconfigure a container.

    This only applies to a few property

    name
        Name of the container.
    utsname
        utsname of the container.

        .. versionadded:: 2016.3.0

    rootfs
        rootfs of the container.

        .. versionadded:: 2016.3.0

    cpu
        Select a random number of cpu cores and assign it to the cpuset, if the
        cpuset option is set then this option will be ignored
    cpuset
        Explicitly define the cpus this container will be bound to
    cpushare
        cgroups cpu shares.
    autostart
        autostart container on reboot
    memory
        cgroups memory limit, in MB.
        (0 for nolimit, None for old default 1024MB)
    gateway
        the ipv4 gateway to use
        the default does nothing more than lxcutils does
    bridge
        the bridge to use
        the default does nothing more than lxcutils does
    nic
        Network interfaces profile (defined in config or pillar).

    nic_opts
        Extra options for network interfaces, will override

        ``{"eth0": {"mac": "aa:bb:cc:dd:ee:ff", "ipv4": "10.1.1.1", "ipv6": "2001:db8::ff00:42:8329"}}``

        or

        ``{"eth0": {"mac": "aa:bb:cc:dd:ee:ff", "ipv4": "10.1.1.1/24", "ipv6": "2001:db8::ff00:42:8329"}}``

    path
        path to the container parent

        .. versionadded:: 2015.8.0

    CLI Example:

    .. code-block:: bash

        salt-call -lall mc_lxc_fork.reconfigure foobar nic_opts="{'eth1': {'mac': '00:16:3e:dd:ee:44'}}" memory=4

    '''
    changes = {}
    cpath = get_root_path(path)
    path = os.path.join(cpath, name, 'config')
    ret = {'name': name,
           'comment': 'config for {0} up to date'.format(name),
           'result': True,
           'changes': changes}
    profile = get_container_profile(copy.deepcopy(profile))
    kw_overrides = copy.deepcopy(kwargs)

    def select(key, default=None):
        kw_overrides_match = kw_overrides.pop(key, _marker)
        profile_match = profile.pop(key, default)
        # let kwarg overrides be the preferred choice
        if kw_overrides_match is _marker:
            return profile_match
        return kw_overrides_match
    if nic_opts is not None and not network_profile:
        network_profile = DEFAULT_NIC

    if autostart is not None:
        autostart = select('autostart', autostart)
    else:
        autostart = 'keep'
    if not utsname:
        utsname = select('utsname', utsname)
    if os.path.exists(path):
        old_chunks = read_conf(path, out_format='commented')
        make_kw = salt.utils.odict.OrderedDict([
            ('utsname', utsname),
            ('rootfs', rootfs),
            ('autostart', autostart),
            ('cpu', cpu),
            ('gateway', gateway),
            ('cpuset', cpuset),
            ('cpushare', cpushare),
            ('network_profile', network_profile),
            ('nic_opts', nic_opts),
            ('bridge', bridge)])
        # match 0 and none as memory = 0 in lxc config is harmful
        if memory:
            make_kw['memory'] = memory
        kw = salt.utils.odict.OrderedDict()
        for key, val in six.iteritems(make_kw):
            if val is not None:
                kw[key] = val
        new_cfg = _config_list(conf_tuples=old_chunks, **kw)
        if new_cfg:
            edit_conf(path, out_format='commented', lxc_config=new_cfg)
        chunks = read_conf(path, out_format='commented')
        if old_chunks != chunks:
            ret['comment'] = '{0} lxc config updated'.format(name)
            if state(name, path=path) == 'running':
                cret = reboot(name, path=path)
                ret['result'] = cret['result']
    return ret