#!/usr/bin/env python
# Copyright (c) 2019 Arista Networks, Inc.  All rights reserved.
# Arista Networks, Inc. Confidential and Proprietary.

import socket
import sys
import telnetlib

# pylint: disable-msg=bare-except

cmd = ' '.join( sys.argv[1:] )
prompt = 'GateD-.*>'
try:
   t = telnetlib.Telnet( 'localhost', 616 )
   t.expect( [ prompt ] )
   t.write( cmd + '\r\n' )
   full_prompt = 'GateD-%s>' % socket.gethostname()
   ( _, _, output ) = t.expect( [ prompt ] )
   print output.strip( full_prompt ).strip()
except:
   print 'Failed to run %s' % cmd
