def get_interface_mode(interface, module):
 command = ('show interface ' + interface)
 intf_type = get_interface_type(interface)
 body = execute_show_command(command, module)
 mode = 'unknown'
 interface_table = {}
 try:
  interface_table = body[0]['TABLE_interface']['ROW_interface']
 except (KeyError, AttributeError, IndexError):
  return mode
 if interface_table:
  if (intf_type in ['ethernet', 'portchannel']):
   mode = str(interface_table.get('eth_mode', 'layer3'))
   if (mode in ['access', 'trunk']):
    mode = 'layer2'
   if (mode == 'routed'):
    mode = 'layer3'
  elif ((intf_type == 'loopback') or (intf_type == 'svi')):
   mode = 'layer3'
 return mode

def get_interface_mode ( interface , module ) : command = ( 'show interface ' + interface ) intf_type = get_interface_type ( interface ) body = execute_show_command ( command , module ) mode = 'unknown' interface_table = { } try : interface_table = body [ 0 ] [ 'TABLE_interface' ] [ 'ROW_interface' ] except ( KeyError , AttributeError , IndexError ) : return mode if interface_table : if ( intf_type in [ 'ethernet' , 'portchannel' ] ) : mode = str ( interface_table . get ( 'eth_mode' , 'layer3' ) ) if ( mode in [ 'access' , 'trunk' ] ) : mode = 'layer2' if ( mode == 'routed' ) : mode = 'layer3' elif ( ( intf_type == 'loopback' ) or ( intf_type == 'svi' ) ) : mode = 'layer3' return mode
gets current mode of interface: layer2 or layer3 args: device : this is the device object of an nx-api enabled device using the device class within device .