Take trap statement inside the if clause
[domino.git] / domino-cli.py
1 #!/usr/bin/env python
2
3 #Copyright 2016 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 import getopt
16
17 sys.path.insert(0, glob.glob('./lib')[0])
18
19 from dominoCLI import DominoClientCLI
20 from dominoCLI.ttypes import *
21 from dominoCLI.constants import *
22
23 from thrift import Thrift
24 from thrift.transport import TSocket
25 from thrift.transport import TTransport
26 from thrift.protocol import TBinaryProtocol
27
28 #Load configuration parameters
29 from domino_conf import *
30
31 def main(argv, cli_port):
32   #cli_port = DOMINO_CLI_PORT
33
34   try:
35     # Make socket
36     # NOTE that domino-cli.py and DominoClient.py are assumed to be run in the same machine
37     transport = TSocket.TSocket('localhost', int(cli_port))
38     # Buffering is critical. Raw sockets are very slow
39     transport = TTransport.TBufferedTransport(transport)
40     # Wrap in a protocol
41     protocol = TBinaryProtocol.TBinaryProtocol(transport)
42
43     # Create a client to use the protocol encoder
44     client = DominoClientCLI.Client(protocol)
45
46     # Connect!
47     transport.open()
48
49     CLImsg = CLIMessage()
50     CLImsg.CLI_input = argv
51     CLIrespmsg = client.d_CLI(CLImsg)
52
53   except Thrift.TException, tx:
54     print '%s' % (tx.message)
55
56 if __name__ == "__main__":
57    if len(sys.argv) >= 2:
58      main(sys.argv[2:], sys.argv[1])
59    else:
60      print 'domino-cli.py <cliport> ...'
61      sys.exit(2)