Fri, Aug 10, 2012 at 12:49:09PM CEST, rpazdera(a)redhat.com wrote:
> From: Radek Pazdera <rpazdera(a)redhat.com>
>
> scan_netdevs function was moved from NetConfigDevNames to NetUtils,
> because it will be needed by code outside of the NetConfig module
> as well to detect devices.
>
> Signed-off-by: Radek Pazdera <rpazdera(a)redhat.com>
> ---
> Common/NetUtils.py | 19 +++++++++++++++++++
> NetConfig/NetConfigDevNames.py | 19 +------------------
> 2 files changed, 20 insertions(+), 18 deletions(-)
>
> diff --git a/Common/NetUtils.py b/Common/NetUtils.py
> index 7e642b6..42ee6f0 100644
> --- a/Common/NetUtils.py
> +++ b/Common/NetUtils.py
> @@ -11,6 +11,7 @@ rpazdera(a)redhat.com (Radek Pazdera)
> """
>
> import logging
> +import os
> import re
> import socket
> import subprocess
> @@ -18,6 +19,24 @@ import subprocess
> def normalize_hwaddr(hwaddr):
> return hwaddr.upper().rstrip("\n")
>
> +def scan_netdevs():
> + sys_dir = "/sys/class/net"
> + scan = []
> + for root, dirs, files in os.walk(sys_dir):
> + if "lo" in dirs:
> + dirs.remove("lo")
> + for d in dirs:
> + dev_path = os.path.join(sys_dir, d)
> + addr_path = os.path.join(dev_path, "address")
> + if not os.path.isfile(addr_path):
> + continue
> + handle = open(addr_path, "rb")
> + addr = handle.read()
> + handle.close()
> + addr = normalize_hwaddr(addr)
> + scan.append({"name": d, "hwaddr": addr})
> + return scan
> +
> def get_corespond_local_ip(query_ip):
> """
> Get ip address in local system which can communicate with query_ip.
> diff --git a/NetConfig/NetConfigDevNames.py b/NetConfig/NetConfigDevNames.py
> index 3f3e0fd..0f246d9 100644
> --- a/NetConfig/NetConfigDevNames.py
> +++ b/NetConfig/NetConfigDevNames.py
> @@ -14,24 +14,7 @@ import logging
> import os
> from NetConfigCommon import get_option
> from Common.NetUtils import normalize_hwaddr
> -
> -def scan_netdevs():
> - sys_dir = "/sys/class/net"
> - scan = []
> - for root, dirs, files in os.walk(sys_dir):
> - if "lo" in dirs:
> - dirs.remove("lo")
> - for d in dirs:
> - dev_path = os.path.join(sys_dir, d)
> - addr_path = os.path.join(dev_path, "address")
> - if not os.path.isfile(addr_path):
> - continue
> - handle = open(addr_path, "rb")
> - addr = handle.read()
> - handle.close()
> - addr = normalize_hwaddr(addr)
> - scan.append({"name": d, "hwaddr": addr})
> - return scan
> +from Common.NetUtils import scan_netdevs
>
> class NetConfigDevNames:
> def __init__(self):
> --
> 1.7.7.6
>
> _______________________________________________
> LNST-developers mailing list
> LNST-developers(a)lists.fedorahosted.org
>
https://lists.fedorahosted.org/mailman/listinfo/lnst-developers
You could probably do this in:
[PATCH 04/12] NetConfigDevNames: Separating scan_netdevs method