def arp(self): for entry in self.api('/ip/arp/print'): if 'mac-address' not in entry: continue else: yield { 'interface': entry['interface'], 'mac': cast_mac(entry['mac-address']), 'ip': cast_ip(entry['address']), 'age': float(-1), }
def convert_arp_table(table): for entry in table: if 'mac-address' not in entry: continue yield { 'interface': entry['interface'], 'mac': cast_mac(entry['mac-address']), 'ip': cast_ip(entry['address']), 'age': float(-1), }
def arp(self): for entry in self.api('/ip/arp/print'): if 'mac-address' not in entry: continue else: yield { 'interface': entry['interface'], 'mac': cast_mac(entry['mac-address']), 'ip': cast_ip(entry['address']), 'age': float(-1), }
def get_interfaces(self): interfaces = {} for entry in self.api('/interface/print'): interfaces[entry['name']] = { 'is_up': entry['running'], 'is_enabled': not entry['disabled'], 'description': entry.get('comment', ''), 'last_flapped': -1.0, 'speed': -1, 'mac_address': cast_mac(entry['mac-address']) if entry.get('mac-address') else u'', } return interfaces
def get_interfaces(self): interfaces = {} for entry in self.api('/interface/print'): interfaces[entry['name']] = { 'is_up': entry['running'], 'is_enabled': not entry['disabled'], 'description': entry.get('comment', ''), 'last_flapped': -1.0, 'speed': -1, 'mac_address': cast_mac(entry['mac-address']) if entry.get('mac-address') else u'', } return interfaces
def get_ipv6_neighbors_table(self): ipv6_neighbors_table = [] for entry in self.api('/ipv6/neighbor/print'): if 'mac-address' not in entry: continue ipv6_neighbors_table.append({ 'interface': entry['interface'], 'mac': cast_mac(entry['mac-address']), 'ip': cast_ip(entry['address']), 'age': float(-1), 'state': entry['status'] }) return ipv6_neighbors_table
def get_arp_table(self): arp_table = [] for entry in self.api('/ip/arp/print'): if 'mac-address' not in entry: continue arp_table.append( { 'interface': entry['interface'], 'mac': cast_mac(entry['mac-address']), 'ip': cast_ip(entry['address']), 'age': float(-1), } ) return arp_table
def get_mac_address_table(self): """ Return the MAC address table. Sample output: [ { "active": true, "interface": "10GE1/0/1", "last_move": -1.0, "mac": "00:00:00:00:00:33", "moves": -1, "static": false, "vlan": 100 }, { "active": false, "interface": "10GE1/0/2", "last_move": -1.0, "mac": "00:00:00:00:00:01", "moves": -1, "static": true, "vlan": 200 } ] """ mac_address_table = [] command = '/interface bridge host print terse' output = self._send_command(command) for host in parse_terse_output(output): mac_address_table.append({ 'mac': cast_mac(host.get('mac-address')), 'interface': host.get('interface'), 'vlan': -1, 'static': True if 'D' not in host.get('_flags') else False, 'active': True if 'X' not in host.get('_flags') else False, 'moves': -1, 'last_move': -1.0 }) return mac_address_table
def get_ipv6_neighbors_table(self): ipv6_neighbors_table = [] for entry in self.api('/ipv6/neighbor/print'): if 'mac-address' not in entry: continue ipv6_neighbors_table.append( { 'interface': entry['interface'], 'mac': cast_mac(entry['mac-address']), 'ip': cast_ip(entry['address']), 'age': float(-1), 'state': entry['status'] } ) return ipv6_neighbors_table
def get_interfaces(self, dynamic=False): """ Get interface details (last_flapped is not implemented). """ interfaces = {} command = '/interface print terse' if not dynamic: command += ' where !dynamic' output = self._send_command(command) if not output: return {} new_interfaces = parse_terse_output(output) for interface in new_interfaces: ifname = interface.get('name') if interface.get('mac-address'): mac_address = cast_mac(interface.get('mac-address')) else: mac_address = '' interfaces.update({ ifname: { 'description': interface.get('comment'), 'is_enabled': True if interface.get('_flags') and 'X' not in interface.get('_flags') else False, 'is_up': True if interface.get('_flags') and 'R' not in interface.get('_flags') else False, 'last_flapped': -1.0, 'mac_address': mac_address, 'speed': -1.0 } }) return interfaces
def get_arp_table(self, vrf=""): """ Get arp table information. Return a list of dictionaries having the following set of keys: * interface (string) * mac (string) * ip (string) * age (float) (not support) Sample output: [ { 'interface' : 'ether1', 'mac' : '5c:5e:ab:da:3c:f0', 'ip' : '172.17.17.1', 'age' : -1 }, { 'interface': 'ether1', 'mac' : '66:0e:94:96:e0:ff', 'ip' : '172.17.17.2', 'age' : -1 } ] """ arp_table = [] output = self._send_command('/ip arp print terse') arps = parse_terse_output(output) for arp in arps: if arp.get('mac-address'): arp_table.append({ 'interface': arp.get('interface'), 'mac': cast_mac(arp.get('mac-address')), 'ip': arp.get('address'), 'age': -1.0, }) return arp_table