Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to access Open vSwitch database server through unix socker

Shulou Source: shulou.com Published: 2022-05-31 17:13:58 09月21日 Update

This article is about how to access Open vSwitch database server through unix socker, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

To interact with openvswitch, you can ovsdb-client list-dbs through commands, or manipulate ovsdb through api.

Ovsdb Protocol reference https://tools.ietf.org/html/rfc7047 (The Open vSwitch Database Management Protocol)

Here is an example of interacting with ovsdb through the unix sockert,json-rpc protocol

Import socketimport sysimport jsondef is_json (myjson): try: json.loads (myjson) except ValueError: return False return Truesock = socket.socket (socket.AF_UNIX, socket.SOCK_STREAM) server_address ='/ var/run/openvswitch/db.sock'try: sock.connect (server_address) except socket.error, msg: print (msg) sys.exit (1) try: message = {"method": "list_dbs" "params": [], "id": 0 } sock.sendall (json.dumps (message)) josn_result = "" while True: data = sock.recv (1024) if len (data) > 0: josn_result + = data if is_json (josn_result): break print (josn_result) finally: sock.close () above is how to access Open vSwitch database server through unix socker The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: More knowledge articles practical examples can be passed commands that is work meetings articles ways look knowledge points industry details information information channels follow parts channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Docker Microsoft OPPO Reno MariaDB