Update user guide
[domino.git] / domino-cli.py
1 #!/usr/bin/env python
2
3 #Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #   Unless required by applicable law or agreed to in writing, software
9 #   distributed under the License is distributed on an "AS IS" BASIS,
10 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 #   See the License for the specific language governing permissions and
12 #   limitations under the License.
13
14 import sys, glob, getopt
15
16 sys.path.insert(0, glob.glob('./lib')[0])
17
18 from dominoCLI import DominoClientCLI
19 from dominoCLI.ttypes import *
20 from dominoCLI.constants import *
21
22 from thrift import Thrift
23 from thrift.transport import TSocket
24 from thrift.transport import TTransport
25 from thrift.protocol import TBinaryProtocol
26
27 #Load configuration parameters
28 from domino_conf import *
29
30 def main(argv):
31 #  try:
32 #    if argv[0] == 'heartbeat':
33 #      print 'Heartbeat input'
34 #  except IndexError as ex:
35 #    print 'Insufficient number of arguments entered'
36 #  except:
37 #    print('Error: %s', sys.exc_info()[0])
38
39   try:
40     # Make socket
41     transport = TSocket.TSocket('localhost', DOMINO_CLI_PORT)
42     # Buffering is critical. Raw sockets are very slow
43     transport = TTransport.TBufferedTransport(transport)
44     # Wrap in a protocol
45     protocol = TBinaryProtocol.TBinaryProtocol(transport)
46
47     # Create a client to use the protocol encoder
48     client = DominoClientCLI.Client(protocol)
49
50     # Connect!
51     transport.open()
52
53     CLImsg = CLIMessage()
54     CLImsg.CLI_input = argv
55     CLIrespmsg = client.d_CLI(CLImsg)
56     print CLIrespmsg.CLI_response
57
58   except Thrift.TException, tx:
59     print '%s' % (tx.message)
60
61 if __name__ == "__main__":
62    main(sys.argv[1:])