-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplified Ifconfig and IpAddress objects
- Loading branch information
Showing
7 changed files
with
635 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import json | ||
|
||
import iproute4mac.ifconfig as ifconfig | ||
import iproute4mac.libc as libc | ||
import iproute4mac.utils as utils | ||
|
||
from difflib import unified_diff | ||
|
||
from iproute4mac import OPTION | ||
from iproute4mac.utils import matches, strcmp, next_arg | ||
|
||
|
||
def usage(): | ||
utils.stderr("""\ | ||
Usage: ip debug { address | neigh | route }""") | ||
exit(libc.EXIT_ERROR) | ||
|
||
|
||
def debug_address(argv=[]): | ||
old_options = utils.options_override({"show_details": True, "json": True, "pretty": True}) | ||
interfaces = ifconfig.Ifconfig() | ||
utils.options_restore(old_options) | ||
ip_ifconfig = str(interfaces) | ||
os_ifconfig = ifconfig.run() | ||
|
||
diff = unified_diff(ip_ifconfig.splitlines(), os_ifconfig.splitlines(), n=1000) | ||
print("\n".join(list(diff))) | ||
|
||
|
||
def debug_neigh(argv=[]): | ||
pass | ||
|
||
|
||
def debug_route(argv=[]): | ||
pass | ||
|
||
|
||
def all(): | ||
debug_address() | ||
debug_neigh() | ||
debug_route() | ||
|
||
|
||
def do_debug(argv): | ||
if not argv: | ||
return all() | ||
|
||
cmd = argv.pop(0) | ||
if matches(cmd, "address"): | ||
return debug_address(argv) | ||
elif matches(cmd, "neighbor", "neighbour"): | ||
return debug_neigh(argv) | ||
elif matches(cmd, "route"): | ||
return debug_route(argv) | ||
elif matches(cmd, "help"): | ||
return usage() | ||
|
||
utils.stderr(f'Command "{cmd}" is unknown, try "ip debug help".') | ||
exit(libc.EXIT_ERROR) |
Oops, something went wrong.