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