コード例 #1
0
    def mac_del(self, ip):
        """Del ip-mac association"""
        from mac_assoc import MacAssoc
        macs = MacAssoc(self.conf['mac_assoc']['arptype'])
        macs.ip = ip
        result = dict()

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

        result['data'] = (('arptype', macs.arptype),
                          ('ip', macs.ip),
                          )

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

            result['result'] = True
            #"OK: del association from '%s' for ip: '%s'" % (macs.arptype, macs.ip)
        else:
            result['result'] = False
            result['data'] = (('ip', macs.ip),
                              ('error:', 'not found in {0}'.format(macs.ethers)),
                              )
            #"ERROR: del association from '%s' for ip: '%s'" % (macs.arptype, macs.ip)

        result['status'] = True
        return result
コード例 #2
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