David K. Bainbridge | a677d4e | 2016-09-11 20:01:32 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import sys |
| 4 | import json |
| 5 | import ethtool |
| 6 | import shlex |
| 7 | |
| 8 | # read the argument string from the arguments file |
| 9 | args_file = sys.argv[1] |
| 10 | args_data = file(args_file).read() |
| 11 | |
| 12 | ignore=["tun", "bridge", "bonding", "veth"] |
| 13 | bus_ignore=["", "N/A", "tap"] |
| 14 | |
| 15 | # parse the task options |
| 16 | arguments = shlex.split(args_data) |
| 17 | for arg in arguments: |
| 18 | # ignore any arguments without an equals in it |
| 19 | if "=" in arg: |
| 20 | (key, value) = arg.split("=") |
| 21 | # if setting the time, the key 'time' |
| 22 | # will contain the value we want to set the time to |
| 23 | |
| 24 | all = {} |
| 25 | for i in ethtool.get_devices(): |
| 26 | o = { "name": i } |
| 27 | try: |
| 28 | module = ethtool.get_module(i) |
| 29 | businfo = ethtool.get_businfo(i) |
| 30 | if module in ignore or businfo in bus_ignore: |
| 31 | continue |
| 32 | all[i] = { |
| 33 | "name": i, |
| 34 | "module" : module, |
| 35 | } |
| 36 | except: |
| 37 | pass |
| 38 | |
| 39 | print json.dumps({ |
| 40 | "changed" : False, |
| 41 | "ansible_facts" : { |
| 42 | "netinfo" : all, |
| 43 | }, |
| 44 | }) |