1 # Copyright (c) 2012 Nicira Networks.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
24 def connect_to_target(target):
25 error, str_result = ovs.unixctl.socket_name_from_target(target)
27 ovs.util.ovs_fatal(error, str_result)
29 socket_name = str_result
31 error, client = ovs.unixctl.UnixctlClient.create(socket_name)
33 ovs.util.ovs_fatal(error, "cannot connect to \"%s\"" % socket_name)
39 parser = argparse.ArgumentParser(description="Python Implementation of"
41 parser.add_argument("-t", "--target", default="ovs-vswitchd",
42 help="pidfile or socket to contact")
44 parser.add_argument("command", metavar="COMMAND",
45 help="Command to run.")
46 parser.add_argument("argv", metavar="ARG", nargs="*",
47 help="Arguments to the command.")
48 args = parser.parse_args()
52 client = connect_to_target(target)
53 err_no, error, result = client.transact(args.command, args.argv)
57 ovs.util.ovs_fatal(err_no, "%s: transaction error" % target)
58 elif error is not None:
59 sys.stderr.write(error)
60 ovs.util.ovs_error(0, "%s: server returned an error" % target)
63 assert result is not None
64 sys.stdout.write(result)
67 if __name__ == '__main__':