def server_bonds(self):
    server_bonds = self._server_bonds()
    mlag_bonds = self._mlag_bonds()
    bonds = []
    for host in server_bonds:
        for (bond, v) in server_bonds[host].items():
            if (len(v) > 1):
                msg = 'multiple bond assignment: {} in {}'
                raise AnsibleError(msg.format(bond, host))
            for item in v:
                rack = ('rack' + str(item['rack']))
                if (item['name'] not in mlag_bonds[rack]):
                    racks = list(mlag_bonds[rack].keys())
                    raise AnsibleError('bond not found: {} ({}) in {}'.format(item['name'], racks, host))
                item.update({'host': host})
            bonds.extend(v)
        for (slave, v) in self._server_bonds(key='slaves')[host].items():
            if (len(v) > 1):
                bonds = [i['name'] for i in v]
                msg = 'multiple bond slaves assignment: {} ({}) in {}'
                raise AnsibleError(msg.format(slave, bonds, host))
        for (vid, v) in self._server_bonds(key='vids')[host].items():
            if (len(v) > 1):
                msg = 'multiple bond vlans assignment: {} ({}) in {}'
                bonds = [i['name'] for i in v]
                raise AnsibleError(msg.format(('vlan' + vid), bonds, host))
    for (k, v) in itertools.groupby(bonds, (lambda x: x['rack'])):
        list_v = list(v)
        y = collections.defaultdict(list)
        for item in list_v:
            y[item['name']].append(item)
        for (bond, _v) in y.items():
            if (len(_v) > 1):
                hosts = [i['host'] for i in _v]
                msg = 'multiple bond assigment with the same rack: {} in ({})'
                raise AnsibleError(msg.format(bond, hosts))
    return server_bonds
def server_bonds(self):
    server_bonds = self._server_bonds()
    mlag_bonds = self._mlag_bonds()
    bonds = []
    for host in server_bonds:
        for (bond, v) in server_bonds[host].items():
            if (len(v) > 1):
                msg = 'multiple bond assignment: {} in {}'
                raise AnsibleError(msg.format(bond, host))
            for item in v:
                rack = ('rack' + str(item['rack']))
                if (item['name'] not in mlag_bonds[rack]):
                    racks = list(mlag_bonds[rack].keys())
                    raise AnsibleError('bond not found: {} ({}) in {}'.format(item['name'], racks, host))
                item.update({'host': host})
            bonds.extend(v)
        for (slave, v) in self._server_bonds(key='slaves')[host].items():
            if (len(v) > 1):
                bonds = [i['name'] for i in v]
                msg = 'multiple bond slaves assignment: {} ({}) in {}'
                raise AnsibleError(msg.format(slave, bonds, host))
        for (vid, v) in self._server_bonds(key='vids')[host].items():
            if (len(v) > 1):
                msg = 'multiple bond vlans assignment: {} ({}) in {}'
                bonds = [i['name'] for i in v]
                raise AnsibleError(msg.format(('vlan' + vid), bonds, host))
    for (k, v) in itertools.groupby(bonds, (lambda x: x['rack'])):
        list_v = list(v)
        y = collections.defaultdict(list)
        for item in list_v:
            y[item['name']].append(item)
        for (bond, _v) in y.items():
            if (len(_v) > 1):
                hosts = [i['host'] for i in _v]
                msg = 'multiple bond assigment with the same rack: {} in ({})'
                raise AnsibleError(msg.format(bond, hosts))
    return server_bonds