# Buggy code
def _nic_profile(profile, hypervisor):
    """
    Gather the nic profile from the config or apply the default based
    on the active hypervisor

    This is the ``default`` profile for KVM/QEMU, which can be
    overridden in the configuration:

    .. code-block:: yaml

        virt:
          nic:
            default:
              eth0:
                bridge: br0
                model: virtio

    The ``model`` parameter is optional, and will default to whatever
    is best suitable for the active hypervisor.
    """
    default = {"eth0": {}}
    if hypervisor in ["esxi", "vmware"]:
        overlay = {"bridge": "DEFAULT", "model": "e1000"}
    elif hypervisor in ["qemu", "kvm"]:
        overlay = {"bridge": "br0", "model": "virtio"}
    else:
        overlay = {}
    nics = __salt__["config.get"]("virt:nic", {}).get(profile, default)
    for key, val in overlay.items():
        for nic in nics:
            if key not in nics[nic]:
                nics[nic][key] = val
    return nics


# Traceback (AttributeError)
[ERROR   ] Error in function _master_opts:
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/salt/master.py", line 1444, in run_func
ret = getattr(self, func)(load)
File "/usr/lib/pymodules/python2.7/salt/master.py", line 891, in _master_opts
envs = self._file_envs()
File "/usr/lib/pymodules/python2.7/salt/fileserver/__init__.py", line 153, in envs
ret.update(self.servers[fstr]())
File "/usr/lib/pymodules/python2.7/salt/fileserver/hgfs.py", line 176, in envs
tags = repo.get_tags()
AttributeError: 'hgclient' object has no attribute 'get_tags'

# Fixed code
def _nic_profile(profile_name, hypervisor, **kwargs):
    default = [{"eth0": {}}]
    vmware_overlay = {"type": "bridge", "source": "DEFAULT", "model": "e1000"}
    kvm_overlay = {"type": "bridge", "source": "br0", "model": "virtio"}
    overlays = {
        "kvm": kvm_overlay,
        "qemu": kvm_overlay,
        "esxi": vmware_overlay,
        "vmware": vmware_overlay,
    }

    # support old location
    config_data = __salt__["config.option"]("virt.nic", {}).get(profile_name, None)

    if config_data is None:
        config_data = __salt__["config.get"]("virt:nic", {}).get(profile_name, default)

    interfaces = []

    def append_dict_profile_to_interface_list(profile_dict):
        for interface_name, attributes in profile_dict.items():
            attributes["name"] = interface_name
            interfaces.append(attributes)

    # old style dicts (top-level dicts)
    #
    # virt:
    #    nic:
    #        eth0:
    #            bridge: br0
    #        eth1:
    #            network: test_net
    if isinstance(config_data, dict):
        append_dict_profile_to_interface_list(config_data)

    # new style lists (may contain dicts)
    #
    # virt:
    #   nic:
    #     - eth0:
    #         bridge: br0
    #     - eth1:
    #         network: test_net
    #
    # virt:
    #   nic:
    #     - name: eth0
    #       bridge: br0
    #     - name: eth1
    #       network: test_net
    elif isinstance(config_data, list):
        for interface in config_data:
            if isinstance(interface, dict):
                if len(interface.keys()) == 1:
                    append_dict_profile_to_interface_list(interface)
                else:
                    interfaces.append(interface)

    def _normalize_net_types(attributes):
        """
        Guess which style of definition:

            bridge: br0

             or

            network: net0

             or

            type: network
            source: net0
        """
        for type_ in ["bridge", "network"]:
            if type_ in attributes:
                attributes["type"] = type_
                # we want to discard the original key
                attributes["source"] = attributes.pop(type_)

        attributes["type"] = attributes.get("type", None)
        attributes["source"] = attributes.get("source", None)

    def _apply_default_overlay(attributes):
        for key, value in overlays[hypervisor].items():
            if key not in attributes or not attributes[key]:
                attributes[key] = value

    def _assign_mac(attributes):
        dmac = "{0}_mac".format(attributes["name"])
        if dmac in kwargs:
            attributes["mac"] = kwargs[dmac]
        else:
            attributes["mac"] = salt.utils.gen_mac()

    for interface in interfaces:
        _normalize_net_types(interface)
        _assign_mac(interface)
        if hypervisor in overlays:
            _apply_default_overlay(interface)

    return interfaces