From: Ondrej Lichtner <olichtne(a)redhat.com>
The get_device slave method now returns a list of ALL devices that the
InterfaceManager sees and their data returned by the recently updated
get_if_data method.
This commit also adds a get_device method that returns the result of
get_if_data for one single Device, identified by the interface index in
the kernel.
Additionally this updates the Wizard class as well since it's the only
one that was using the get_devices method. It now uses the
get_devices_by_params method and selects just the DOWN && eth
interfaces.
This is a backwards incompatible change.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/Wizard.py | 14 ++++++++------
lnst/Slave/NetTestSlave.py | 13 +++++++++----
2 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/lnst/Controller/Wizard.py b/lnst/Controller/Wizard.py
index 59c3732..dc82c21 100644
--- a/lnst/Controller/Wizard.py
+++ b/lnst/Controller/Wizard.py
@@ -54,7 +54,7 @@ class Wizard:
machine_interfaces = self._get_machine_interfaces(sock)
sock.close()
- if machine_interfaces == {}:
+ if machine_interfaces == []:
sys.stderr.write("No suitable interfaces found on the host
"
"'%s:%s'\n" % (hostname, port))
elif machine_interfaces is not None:
@@ -81,7 +81,7 @@ class Wizard:
machine_interfaces = self._get_machine_interfaces(sock)
sock.close()
- if machine_interfaces == {}:
+ if machine_interfaces == []:
sys.stderr.write("No suitable interfaces found on the host "
"'%s:%s'\n" % (hostname, port))
elif machine_interfaces is not None:
@@ -144,7 +144,7 @@ class Wizard:
machine_interfaces = self._get_machine_interfaces(sock)
sock.close()
- if machine_interfaces is {}:
+ if machine_interfaces is []:
sys.stderr.write("No suitable interfaces found on the host "
"'%s:%s'\n" % (hostname, port))
continue
@@ -280,7 +280,7 @@ class Wizard:
pool_dir=None, filename=None, mode=None,
port=None, libvirt_domain=None, sec_params=None):
""" Creates slave machine XML file
- @param machine_interfaces Dictionary with machine's interfaces
+ @param machine_interfaces List of machine's interfaces
@param hostname Hostname of the machine
@param pool_dir Path to directory where XML file will be created
@param filename Name of the XML file
@@ -312,7 +312,7 @@ class Wizard:
top_el.appendChild(interfaces_el)
interfaces_added = 0
- for iface in machine_interfaces.itervalues():
+ for iface in machine_interfaces:
if mode == "interactive":
msg = "Do you want to add interface '%s' (%s) to the
"\
"recipe? [Y/n]: " % (iface["name"],
iface["hwaddr"])
@@ -390,7 +390,9 @@ class Wizard:
@param sock Socket used for connecting to machine
@return Dictionary with machine interfaces or None if RPC call fails
"""
- msg = {"type": "command", "method_name":
"get_devices", "args": {}}
+ msg = {"type": "command",
+ "method_name": "get_devices_by_params",
+ "args": [{"ifi_type": 1, "state":
"DOWN"}]}
if not send_data(sock, msg):
sys.stderr.write("Could not send request to slave machine\n")
return None
diff --git a/lnst/Slave/NetTestSlave.py b/lnst/Slave/NetTestSlave.py
index 3b8bf79..1c6f47b 100644
--- a/lnst/Slave/NetTestSlave.py
+++ b/lnst/Slave/NetTestSlave.py
@@ -136,12 +136,17 @@ class SlaveMethods:
devices = self._if_manager.get_devices()
result = {}
for device in devices:
- if device._ifi_type == 1 and device._state == 'DOWN':
- result[device._if_index] = {'name' : device._name,
- 'hwaddr' : device._hwaddr,
- 'driver' : device._driver}
+ result[device._if_index] = device.get_if_data()
return result
+ def get_device(self, if_index):
+ self._if_manager.rescan_devices()
+ device = self._if_manager.get_device(if_index)
+ if device:
+ return device.get_if_data()
+ else:
+ return None
+
def get_devices_by_devname(self, devname):
name_scan = self._if_manager.get_devices()
netdevs = []
--
2.8.2