text
stringlengths
0
828
if value.isdigit():
result[key] = int(value)
return result"
1996,"def _parse_ip_stats_link_show(raw_result):
""""""
Parse the 'ip -s link show dev <dev>' command raw output.
:param str raw_result: vtysh raw result string.
:rtype: dict
:return: The parsed result of the show interface command in a \
dictionary of the form:
::
{
'rx_bytes': 0,
'rx_packets': 0,
'rx_errors': 0,
'rx_dropped': 0,
'rx_overrun': 0,
'rx_mcast': 0,
'tx_bytes': 0,
'tx_packets': 0,
'tx_errors': 0,
'tx_dropped': 0,
'tx_carrier': 0,
'tx_collisions': 0,
}
""""""
show_re = (
r'.+?RX:.*?\n'
r'\s*(?P<rx_bytes>\d+)\s+(?P<rx_packets>\d+)\s+(?P<rx_errors>\d+)\s+'
r'(?P<rx_dropped>\d+)\s+(?P<rx_overrun>\d+)\s+(?P<rx_mcast>\d+)'
r'.+?TX:.*?\n'
r'\s*(?P<tx_bytes>\d+)\s+(?P<tx_packets>\d+)\s+(?P<tx_errors>\d+)\s+'
r'(?P<tx_dropped>\d+)\s+(?P<tx_carrier>\d+)\s+(?P<tx_collisions>\d+)'
)
re_result = match(show_re, raw_result, DOTALL)
result = None
if (re_result):
result = re_result.groupdict()
for key, value in result.items():
if value is not None:
if value.isdigit():
result[key] = int(value)
return result"
1997,"def interface(enode, portlbl, addr=None, up=None, shell=None):
""""""
Configure a interface.
All parameters left as ``None`` are ignored and thus no configuration
action is taken for that parameter (left ""as-is"").
:param enode: Engine node to communicate with.
:type enode: topology.platforms.base.BaseNode
:param str portlbl: Port label to configure. Port label will be mapped to
real port automatically.
:param str addr: IPv4 or IPv6 address to add to the interface:
- IPv4 address and netmask to assign to the interface in the form
``'192.168.20.20/24'``.
- IPv6 address and subnets to assign to the interface in the form
``'2001::1/120'``.
:param bool up: Bring up or down the interface.
:param str shell: Shell name to execute commands.
If ``None``, use the Engine Node default shell.
""""""
assert portlbl
port = enode.ports[portlbl]
if addr is not None:
assert ip_interface(addr)
cmd = 'ip addr add {addr} dev {port}'.format(addr=addr, port=port)
response = enode(cmd, shell=shell)
assert not response
if up is not None:
cmd = 'ip link set dev {port} {state}'.format(
port=port, state='up' if up else 'down'
)
response = enode(cmd, shell=shell)
assert not response"
1998,"def remove_ip(enode, portlbl, addr, shell=None):
""""""
Remove an IP address from an interface.
All parameters left as ``None`` are ignored and thus no configuration
action is taken for that parameter (left ""as-is"").
:param enode: Engine node to communicate with.
:type enode: topology.platforms.base.BaseNode
:param str portlbl: Port label to configure. Port label will be mapped to
real port automatically.
:param str addr: IPv4 or IPv6 address to remove from the interface:
- IPv4 address to remove from the interface in the form