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
19 dir = pkg_resources.resource_filename('lib','.')
22 sys.path.insert(0, glob.glob(dir)[0])
24 from dominoCLI import DominoClientCLI
25 from dominoCLI.ttypes import *
26 from dominoCLI.constants import *
28 from thrift import Thrift
29 from thrift.transport import TSocket
30 from thrift.transport import TTransport
31 from thrift.protocol import TBinaryProtocol
33 #Load configuration parameters
34 from domino_conf import *
37 #cli_port = DOMINO_CLI_PORT
38 if len(sys.argv) >= 2:
39 cli_port = sys.argv[1]
41 print 'domino-cli.py <cliport> ...'
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)
50 protocol = TBinaryProtocol.TBinaryProtocol(transport)
52 # Create a client to use the protocol encoder
53 client = DominoClientCLI.Client(protocol)
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)
66 if __name__ == "__main__":