API Reference¶
ovs_vsctl.__init__¶
Slightly ovs-vsctl wrapper for Python.
-
class
ovs_vsctl.
VSCtl
(protocol='tcp', addr='127.0.0.1', port=6640)¶ Runner class for ‘ovs-vsctl’ command.
Parameters: - protocol – ‘tcp’, ‘ssl’, and ‘unix’ are available.
- addr – IP address of switch to connect.
- port – (TCP or SSL) port number to connect.
Raise: - ValueError – When the given parameter is invalid.
-
ovsdb_addr
¶ Returns OVSDB server address formatted like ‘–db’ option of ‘ovs-vsctl’ command.
Example:
>>> from ovs_vsctl import VSCtl >>> vsctl = VSCtl('tcp', '127.0.0.1', 6640) >>> vsctl.ovsdb_addr 'tcp:127.0.0.1:6640'
Returns: OVSDB server address.
-
run
(command, table_format='list', data_format='string', parser=None)¶ Executes ovs-vsctl command.
command is an str type and the format is the same as ‘ovs-vsctl` except for omitting ‘ovs-vsctl’ in command format.
For example, if you want to get the list of ports, the command for ‘ovs-vsctl’ should like ‘ovs-vsctl list port’ and command argument for this method should be:
>>> from ovs_vsctl import VSCtl >>> vsctl = VSCtl('tcp', '127.0.0.1', 6640) >>> vsctl.run(command='list port') <subprocess.Popen object at 0x7fbbe9d549e8>
Parameters: - command – Command to execute.
- table_format – Table format. Meaning is the same as ‘–format’ option of ‘ovs-vsctl’ command.
- data_format – Cell format in table. Meaning is the same as ‘–data’ option of ‘ovs-vsctl’ command.
- parser – Parser class for the outputs. If this parameter is specified table_format and data_format is overridden with table_format=’list’ and data_format=’json’.
Returns: Output of ‘ovs-vsctl’ command. If parser is not specified, returns an instance of ‘subprocess.Popen’. If parser is specified, the given parser is applied to parse the outputs.
Raise: - ovs_vsctl.exception.VSCtlCmdExecError – When the given command fails.
- ovs_vsctl.exception.VSCtlCmdParseError – When the given parser fails to parse the outputs.
-
ovs_vsctl.
line_parser
(buf)¶ Parses the given buf as str representation of list of values (e.g. ‘ovs-vsctl list-br’ command).
Parameters: buf – str type value containing values list. Returns: list of parsed values.
-
ovs_vsctl.
list_cmd_parser
(buf)¶ Parser for ‘ovs-vsctl list’ and ‘ovs-vsctl find’ command.
buf must be the str type and the output of ‘ovs-vsctl list’ or ovs-vsctl find’ command with ‘–format=list’ and ‘–data=json’ options.
Parameters: buf – str type output of ‘ovs-vsctl list’ command. Returns: list of Record instances.
-
ovs_vsctl.
find_cmd_parser
(buf)¶ Parser for ‘ovs-vsctl list’ and ‘ovs-vsctl find’ command.
buf must be the str type and the output of ‘ovs-vsctl list’ or ovs-vsctl find’ command with ‘–format=list’ and ‘–data=json’ options.
Parameters: buf – str type output of ‘ovs-vsctl list’ command. Returns: list of Record instances.
-
ovs_vsctl.
get_cmd_parser
(buf)¶ Parser for ‘ovs-vsctl get’ command.
buf must be the str type and the output of ‘ovs-vsctl get’ command.
Assumption: The output is mostly formatted in json, except for ‘uuid’ and ‘key’ of map type value.
Parameters: buf – value of ‘ovs-vsctl get’ command. Returns: python object corresponding to the value type of row.
ovs_vsctl.vsctl¶
APIs for execute ‘ovs-vsctl’ command.
-
class
ovs_vsctl.vsctl.
VSCtl
(protocol='tcp', addr='127.0.0.1', port=6640)¶ Runner class for ‘ovs-vsctl’ command.
Parameters: - protocol – ‘tcp’, ‘ssl’, and ‘unix’ are available.
- addr – IP address of switch to connect.
- port – (TCP or SSL) port number to connect.
Raise: - ValueError – When the given parameter is invalid.
-
ovsdb_addr
¶ Returns OVSDB server address formatted like ‘–db’ option of ‘ovs-vsctl’ command.
Example:
>>> from ovs_vsctl import VSCtl >>> vsctl = VSCtl('tcp', '127.0.0.1', 6640) >>> vsctl.ovsdb_addr 'tcp:127.0.0.1:6640'
Returns: OVSDB server address.
-
run
(command, table_format='list', data_format='string', parser=None)¶ Executes ovs-vsctl command.
command is an str type and the format is the same as ‘ovs-vsctl` except for omitting ‘ovs-vsctl’ in command format.
For example, if you want to get the list of ports, the command for ‘ovs-vsctl’ should like ‘ovs-vsctl list port’ and command argument for this method should be:
>>> from ovs_vsctl import VSCtl >>> vsctl = VSCtl('tcp', '127.0.0.1', 6640) >>> vsctl.run(command='list port') <subprocess.Popen object at 0x7fbbe9d549e8>
Parameters: - command – Command to execute.
- table_format – Table format. Meaning is the same as ‘–format’ option of ‘ovs-vsctl’ command.
- data_format – Cell format in table. Meaning is the same as ‘–data’ option of ‘ovs-vsctl’ command.
- parser – Parser class for the outputs. If this parameter is specified table_format and data_format is overridden with table_format=’list’ and data_format=’json’.
Returns: Output of ‘ovs-vsctl’ command. If parser is not specified, returns an instance of ‘subprocess.Popen’. If parser is specified, the given parser is applied to parse the outputs.
Raise: - ovs_vsctl.exception.VSCtlCmdExecError – When the given command fails.
- ovs_vsctl.exception.VSCtlCmdParseError – When the given parser fails to parse the outputs.
ovs_vsctl.parser¶
Parsers for ‘ovs-vsctl’ command outputs.
-
class
ovs_vsctl.parser.
Record
(**kwargs)¶ Record object of OVSDB table.
Attributes are corresponding to columns of parsed tables.
-
classmethod
parse
(buf)¶ Parses the given buf as str containing a record of rows.
Parameters: buf – Record in str type. Returns: Record instance.
-
classmethod
-
ovs_vsctl.parser.
find_cmd_parser
(buf)¶ Parser for ‘ovs-vsctl list’ and ‘ovs-vsctl find’ command.
buf must be the str type and the output of ‘ovs-vsctl list’ or ovs-vsctl find’ command with ‘–format=list’ and ‘–data=json’ options.
Parameters: buf – str type output of ‘ovs-vsctl list’ command. Returns: list of Record instances.
-
ovs_vsctl.parser.
get_cmd_parser
(buf)¶ Parser for ‘ovs-vsctl get’ command.
buf must be the str type and the output of ‘ovs-vsctl get’ command.
Assumption: The output is mostly formatted in json, except for ‘uuid’ and ‘key’ of map type value.
Parameters: buf – value of ‘ovs-vsctl get’ command. Returns: python object corresponding to the value type of row.
-
ovs_vsctl.parser.
line_parser
(buf)¶ Parses the given buf as str representation of list of values (e.g. ‘ovs-vsctl list-br’ command).
Parameters: buf – str type value containing values list. Returns: list of parsed values.
-
ovs_vsctl.parser.
list_cmd_parser
(buf)¶ Parser for ‘ovs-vsctl list’ and ‘ovs-vsctl find’ command.
buf must be the str type and the output of ‘ovs-vsctl list’ or ovs-vsctl find’ command with ‘–format=list’ and ‘–data=json’ options.
Parameters: buf – str type output of ‘ovs-vsctl list’ command. Returns: list of Record instances.
-
ovs_vsctl.parser.
show_cmd_parser
(buf)¶ Parser for ‘ovs-vsctl show’ command.
Currently, parses ONLY ‘ovs_version’ column.
Parameters: buf – str type output of ‘ovs-vsctl show’ command. Returns: dict type value of ‘ovs-vsctl show’ command.
ovs_vsctl.exception¶
Exception classes.
-
exception
ovs_vsctl.exception.
VSCtlCmdExecError
¶ Raised when ‘ovs-vsctl’ command returns non-zero exit code.
-
exception
ovs_vsctl.exception.
VSCtlCmdParseError
¶ Raised when user specified parser fails to parse the outputs of ‘ovs-vsctl’ command.
ovs_vsctl.utils¶
Utilities.
-
ovs_vsctl.utils.
is_valid_uuid
(uuid)¶ Returns True if the given uuid is valid, otherwise returns False.
Parameters: uuid – str type value to be validated. Returns: True if valid, else False.
-
ovs_vsctl.utils.
run
(args)¶ Wrapper of ‘subprocess.run’.
Parameters: args – Command arguments to execute. Returns: instance of ‘subprocess.Popen’.