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.
14 import sys, glob, getopt
17 sys.path.insert(0, glob.glob('./lib')[0])
19 from dominoCLI import DominoClientCLI
20 from dominoCLI.ttypes import *
21 from dominoCLI.constants import *
23 from thrift import Thrift
24 from thrift.transport import TSocket
25 from thrift.transport import TTransport
26 from thrift.protocol import TBinaryProtocol
28 #Load configuration parameters
29 from domino_conf import *
31 def main(argv, cli_port):
32 #cli_port = DOMINO_CLI_PORT
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)
41 protocol = TBinaryProtocol.TBinaryProtocol(transport)
43 # Create a client to use the protocol encoder
44 client = DominoClientCLI.Client(protocol)
50 CLImsg.CLI_input = argv
51 CLIrespmsg = client.d_CLI(CLImsg)
52 if CLIrespmsg.CLI_response is not None:
53 print CLIrespmsg.CLI_response
54 except Thrift.TException, tx:
55 print '%s' % (tx.message)
57 if __name__ == "__main__":
58 if len(sys.argv) >= 2:
59 main(sys.argv[2:], sys.argv[1])
61 print 'domino-cli.py <cliport> ...'