Example #1
0
    def mac_add(self, ip, mac):
        """Add ip-mac association"""
        from mac_assoc import MacAssoc
        result = dict()

        macs = MacAssoc(self.conf['mac_assoc']['arptype'])

        macs.ip = ip
        macs.mac = mac

        try:
            status = macs.set()
        except Exception as e:
            result['status'] = False
            result['data'] = (('error:', e.message), )
            return result

        result['data'] = (('arptype', macs.arptype),
                          ('ip', macs.ip),
                          ('mac', macs.mac),
                          )
        if status:
            try:
                macs.ethers_to_arp()
            except Exception as e:
                result['status'] = False
                result['data'] = (('error:', e.message), )
                return result

            result['result'] = True
        else:
            result['result'] = False
            #"ERROR: set association from '%s' for ip: '%s', mac: '%s'" % (macs.arptype, macs.ip, macs.mac)

        result['status'] = True
        return result