def trill_links(self): """dict: trill link details Examples: >>> import pyswitch.device >>> switches = ['10.24.39.231'] >>> auth = ('admin', 'password') >>> for switch in switches: ... conn = (switch, '22') ... with pyswitch.device.Device(conn=conn, auth=auth) as dev: ... output = dev.fabric_service.trill_links """ get_links_info = ('show_linkinfo_rpc', {}) results = self._callback(get_links_info, handler='get') util = Util(results.data) result = [] for item in util.findlist(util.root, './/show-link-info'): src_rbridge_id = util.find(item, './/linkinfo-rbridgeid') src_switch_wwn = util.find(item, './/linkinfo-wwn') for link in util.findlist(item, './/linkinfo-isl'): dest_rbridge_id = util.find(link, './/linkinfo-isllink-destdomain') src_interface = util.find( link, './/linkinfo-isllink-srcport-interface') dest_interface = util.find( link, './/linkinfo-isllink-destport-interface') link_cost = util.find(link, './/linkinfo-isl-linkcost') link_cost_count = util.find(link, './/linkinfo-isllink-costcount') item_results = { 'source-rbridgeid': src_rbridge_id, 'source-switch-wwn': src_switch_wwn, 'dest-rbridgeid': dest_rbridge_id, 'source-interface': src_interface, 'dest-interface': dest_interface, 'link-cost': link_cost, 'link-costcount': link_cost_count } result.append(item_results) return result
def vcs_nodes(self): """dict: vcs node details >>> import pyswitch.device >>> switches = ['10.24.39.231'] >>> auth = ('admin', 'password') >>> for switch in switches: ... conn = (switch, '22') ... with pyswitch.device.Device(conn=conn, auth=auth) as dev: ... output = dev.vcs.vcs_nodes """ show_vcs = ('show_vcs_rpc', {}) results = self._callback(show_vcs, handler='get') util = Util(results.data) result = [] for nodes in util.findlist(util.root, './/vcs-nodes'): for item in util.findlist(nodes, './/vcs-node-info'): serial_number = util.find(item, './/node-serial-num') node_status = util.find(item, './/node-status') vcs_id = util.find(item, './/node-vcs-id') rbridge_id = util.find(item, './/node-rbridge-id') switch_mac = util.find(item, './/node-switch-mac') switch_wwn = util.find(item, './/node-switch-wwn') switch_name = util.find(item, './/node-switchname') node_is_principal = util.find(item, './/node-is-principal') switch_ip = '' for switch_ip_addr in util.findlist( item, './/node-public-ip-addresses'): switch_ip = util.find(switch_ip_addr, './/node-public-ip-address') break item_results = {'node-serial-num': serial_number, 'node-status': node_status, 'node-vcs-id': vcs_id, 'node-rbridge-id': rbridge_id, 'node-switch-mac': switch_mac, 'node-switch-wwn': switch_wwn, 'node-switch-ip': switch_ip, 'node-switchname': switch_name, 'node-is-principal': node_is_principal} result.append(item_results) return result
def mac_table(self): """list[dict]: the MAC table of the device. Examples: >>> import pyswitch.device >>> switches = ['10.24.39.231'] >>> auth = ('admin', 'password') >>> for switch in switches: ... conn = (switch, '22') ... with pyswitch.device.Device(conn=conn, auth=auth) as dev: ... output = dev.mac_table """ table = [] config = ('get_mac_address_table_rpc', {}) rest_root = self._callback(config, handler='get') util = Util(rest_root.data) for entry in util.findlist(util.root, './/mac-address-table'): address = util.find(entry, './/mac-address') vlan = util.find(entry, './/vlanid') mac_type = util.find(entry, './/mac-type') state = util.find(entry, './/mac-state') interface = util.findNode(entry, './/forwarding-interface') interface_type = util.find(interface, './/interface-type') interface_name = util.find(interface, './/interface-name') interface = '%s%s' % (interface_type, interface_name) table.append( dict(mac_address=address, interface_type=interface_type, interface_name=interface_name, interface=interface, state=state, vlan=vlan, type=mac_type)) return table
def arp(self): """dict: arp details Examples: >>> import pyswitch.device >>> switches = ['10.24.39.231'] >>> auth = ('admin', 'password') >>> for switch in switches: ... conn = (switch, '22') ... with pyswitch.device.Device(conn=conn, auth=auth) as dev: ... output = dev.services.arp """ config = ('get_arp_rpc', {}) results = self._callback(config, handler='get') util = Util(results.data) result = [] for item in util.findlist(util.root, './/arp-entry'): ip_address = util.find(item, './/ip-address') mac_address = util.find(item, './/mac-address') interface_type = util.find(item, './/interface-type') interface_name = util.find(item, './/interface-name') is_resolved = util.find(item, './/is-resolved') age = util.find(item, './/age') entry_type = util.find(item, './/entry-type') item_results = { 'ip-address': ip_address, 'mac-address': mac_address, 'interface-type': interface_type, 'interface-name': interface_name, 'is-resolved': is_resolved, 'age': age, 'entry-type': entry_type } result.append(item_results) return result
def neighbors(self, **kwargs): """list[dict]: A list of dictionary items describing the operational state of LLDP. Examples: >>> import pyswitch.device >>> switches = ['10.24.39.231'] >>> auth = ('admin', 'password') >>> for switch in switches: ... conn = (switch, '22') ... with pyswitch.device.Device(conn=conn, auth=auth) as dev: ... output = dev.lldp.neighbors() """ result = [] has_more = '' last_ifindex = '' rbridge_id = None if 'rbridge_id' in kwargs: rbridge_id = kwargs.pop('rbridge_id') while (has_more == '') or (has_more == 'true'): request_lldp = self.get_lldp_neighbors_request( last_ifindex, rbridge_id) lldp_result = self._callback(request_lldp, handler='get') util = Util(lldp_result.data) has_more = util.find(util.root, './/has-more') for item in util.findlist(util.root, './/lldp-neighbor-detail'): local_int_name = util.findText(item, './/local-interface-name') local_int_mac = util.findText(item, './/local-interface-mac') last_ifindex = util.findText(item, './/local-interface-ifindex') remote_int_name = util.findText(item, './/remote-interface-name') remote_int_mac = util.findText(item, './/remote-interface-mac') remote_chas_id = util.findText(item, './/remote-chassis-id') remote_sys_name = util.findText(item, './/remote-system-name') remote_sys_desc = util.findText( item, './/remote-system-description') remote_mgmt_addr = util.findText( item, './/remote-management-address') if 'Fo ' in local_int_name: local_int_name = local_int_name.replace( 'Fo ', 'FortyGigabitEthernet ') if 'Te ' in local_int_name: local_int_name = local_int_name.replace( 'Te ', 'TenGigabitEthernet ') if 'Eth ' in local_int_name: local_int_name = local_int_name.replace( 'Eth ', 'Ethernet ') item_results = { 'local-int-name': local_int_name, 'local-int-mac': local_int_mac, 'remote-int-name': remote_int_name, 'remote-int-mac': remote_int_mac, 'remote-chassis-id': remote_chas_id, 'remote-system-name': remote_sys_name, 'remote-system-description': remote_sys_desc, 'remote-management-address': remote_mgmt_addr } result.append(item_results) return result