diff options
author | George Kraft <george.kraft@calxeda.com> | 2012-12-04 12:21:33 -0600 |
---|---|---|
committer | George Kraft <george.kraft@calxeda.com> | 2012-12-04 12:21:33 -0600 |
commit | 33f3f06e1cb6ce0ee29c3458e555e10eacb6a81c (patch) | |
tree | 1da89a01334da0b14e78729d6199d46d56c8a69d | |
parent | 16d6e215658380205b3189ed6f5556ebb0ccaf15 (diff) | |
download | cxmanage-33f3f06e1cb6ce0ee29c3458e555e10eacb6a81c.tar.gz |
CXMAN-161: Node: Make get_sensors return a dict instead of a list
This makes it easier to access sensors by their names.
-rw-r--r-- | cxmanage_api/node.py | 2 | ||||
-rw-r--r-- | cxmanage_test/node_test.py | 6 | ||||
-rwxr-xr-x | scripts/cxmanage | 8 |
3 files changed, 6 insertions, 10 deletions
diff --git a/cxmanage_api/node.py b/cxmanage_api/node.py index 2aa6b19..7b7bef7 100644 --- a/cxmanage_api/node.py +++ b/cxmanage_api/node.py @@ -263,7 +263,7 @@ class Node(object): else: raise NoSensorError("No sensors containing \"%s\" were " + "found" % name) - return sensors + return dict((x.sensor_name, x) for x in sensors) def get_firmware_info(self): """Gets firmware info from the node. diff --git a/cxmanage_test/node_test.py b/cxmanage_test/node_test.py index f53f4e4..96b48fd 100644 --- a/cxmanage_test/node_test.py +++ b/cxmanage_test/node_test.py @@ -107,10 +107,8 @@ class NodeTest(unittest.TestCase): self.assertEqual(node.bmc.executed, ["sdr_list"]) self.assertEqual(len(result), 2) - self.assertEqual(result[0].sensor_name, "Node Power") - self.assertTrue(result[0].sensor_reading.endswith("Watts")) - self.assertEqual(result[1].sensor_name, "Board Temp") - self.assertTrue(result[1].sensor_reading.endswith("degrees C")) + self.assertTrue(result["Node Power"].sensor_reading.endswith("Watts")) + self.assertTrue(result["Board Temp"].sensor_reading.endswith("degrees C")) def test_is_updatable(self): """ Test node.is_updatable method """ diff --git a/scripts/cxmanage b/scripts/cxmanage index 1f54615..a8307c3 100755 --- a/scripts/cxmanage +++ b/scripts/cxmanage @@ -685,11 +685,10 @@ def sensor_command(args): results, errors = _run_command(args, nodes, "get_sensors", args.sensor_name) - # Get sensor names + # Get sensor names across all nodes sensor_names = [] for node in results: - for sensor in results[node]: - sensor_name = sensor.sensor_name + for sensor_name in results[node]: if not sensor_name in sensor_names: sensor_names.append(sensor_name) @@ -702,8 +701,7 @@ def sensor_command(args): for node in nodes: if node in results: try: - sensor = [x for x in results[node] - if x.sensor_name == sensor_name][0] + sensor = results[node][sensor_name] reading = sensor.sensor_reading.replace( "(+/- 0) ", "") |