def _server_bonds(self, key='name'):
    host_ifaces = mf['server_interfaces']
    mlag_bonds = self._mlag_bonds()
    servers = inventory.hosts('server')
    is_rack_exist = True
    is_bond_exist = True
    _server_bonds = {}
    for (host, iface) in host_ifaces.items():
        if (host in servers):
            for (idx, bond) in enumerate(iface['bonds']):
                rack = ('rack' + str(bond['rack']))
                try:
                    mlag_bonds[rack]
                except KeyError:
                    is_rack_exist = False
                try:
                    vids = mlag_bonds[rack][bond['name']]['vids']
                except KeyError:
                    is_bond_exist = False
                if (not is_rack_exist):
                    raise AnsibleError('rack not found: {} ({}) in {}'.format(rack, list(mlag_bonds.keys()), host))
                elif (not is_bond_exist):
                    bonds = list(mlag_bonds[rack].keys())
                    raise AnsibleError('bond not found: {} ({}) in {}'.format(bond['name'], bonds, host))
                bond.update({'vids': vids, 'index': idx})
            _groupby = collections.defaultdict(list)
            for (k, v) in itertools.groupby(iface['bonds'], (lambda x: x[key])):
                list_v = list(v)
                if ((key == 'slaves') or (key == 'vids')):
                    for item in filter.uncluster(k):
                        _groupby[item].extend(list_v)
                else:
                    _groupby[k].extend(list_v)
                _server_bonds[host] = _groupby
        else:
            raise AnsibleError(('%s not found in inventory file, check the master.yml in server_interfaces' % host))
    return _server_bonds
def _server_bonds(self, key='name'):
    host_ifaces = mf['server_interfaces']
    mlag_bonds = self._mlag_bonds()
    servers = inventory.hosts('server')
    is_rack_exist = True
    is_bond_exist = True
    _server_bonds = {}
    for (host, iface) in host_ifaces.items():
        if (host in servers):
            for (idx, bond) in enumerate(iface['bonds']):
                rack = ('rack' + str(bond['rack']))
                try:
                    mlag_bonds[rack]
                except KeyError:
                    is_rack_exist = False
                try:
                    vids = mlag_bonds[rack][bond['name']]['vids']
                except KeyError:
                    is_bond_exist = False
                if (not is_rack_exist):
                    raise AnsibleError('rack not found: {} ({}) in {}'.format(rack, list(mlag_bonds.keys()), host))
                elif (not is_bond_exist):
                    bonds = list(mlag_bonds[rack].keys())
                    raise AnsibleError('bond not found: {} ({}) in {}'.format(bond['name'], bonds, host))
                bond.update({'vids': vids, 'index': idx})
            _groupby = collections.defaultdict(list)
            for (k, v) in itertools.groupby(iface['bonds'], (lambda x: x[key])):
                list_v = list(v)
                if ((key == 'slaves') or (key == 'vids')):
                    for item in filter.uncluster(k):
                        _groupby[item].extend(list_v)
                else:
                    _groupby[k].extend(list_v)
                _server_bonds[host] = _groupby
        else:
            raise AnsibleError(('%s not found in inventory file, check the master.yml in server_interfaces' % host))
    return _server_bonds