[moblab] Add UI functionality to Set/Update host attributes.
Ui demo at moblab 100.96.59.141
BUG=chromium:732505
TEST=unit test and local moblab testing.
Change-Id: Icdc3e532b50fbf9b1a2440f423a00bd74a1ac232
Reviewed-on: https://chromium-review.googlesource.com/583711
Commit-Ready: Keith Haddow <[email protected]>
Tested-by: Keith Haddow <[email protected]>
Reviewed-by: Keith Haddow <[email protected]>
Reviewed-by: Michael Tang <[email protected]>
diff --git a/frontend/afe/moblab_rpc_interface.py b/frontend/afe/moblab_rpc_interface.py
index 91645b5..f0f4fde 100644
--- a/frontend/afe/moblab_rpc_interface.py
+++ b/frontend/afe/moblab_rpc_interface.py
@@ -349,6 +349,7 @@
return match.group('bucket')
return None
+
def _is_valid_boto_key(key_id, key_secret, directory):
try:
_run_bucket_performance_test(key_id, key_secret, directory)
@@ -356,6 +357,7 @@
return(False, str(e))
return(True, None)
+
def _validate_cloud_storage_info(cloud_storage_info):
"""Checks if the cloud storage information is valid.
@@ -471,6 +473,9 @@
for host in hosts:
labels = [label.name for label in host.label_list]
labels.sort()
+ for host_attribute in host.hostattribute_set.all():
+ labels.append("ATTR:(%s=%s)" % (host_attribute.attribute,
+ host_attribute.value))
configured_duts[host.hostname] = ', '.join(labels)
return rpc_utils.prepare_for_serialization(
@@ -560,6 +565,37 @@
return (True, 'Removed label %s from DUT %s' % (label_name, ipaddress))
+@rpc_utils.moblab_only
+def set_host_attrib(ipaddress, attribute, value):
+ """ RPC handler to set an attribute of a host.
+
+ @param ipaddress: IP address of the DUT.
+ @param attribute: string name of attribute
+ @param value: string, or None to delete an attribute
+
+ @return: True if the command succeeds without an exception
+ """
+ host_obj = models.Host.smart_get(ipaddress)
+ host_obj.set_or_delete_attribute(attribute, value)
+ return (True, 'Updated attribute %s to %s on DUT %s' % (
+ attribute, value, ipaddress))
+
+
+@rpc_utils.moblab_only
+def delete_host_attrib(ipaddress, attribute):
+ """ RPC handler to delete an attribute of a host.
+
+ @param ipaddress: IP address of the DUT.
+ @param attribute: string name of attribute
+
+ @return: True if the command succeeds without an exception
+ """
+ host_obj = models.Host.smart_get(ipaddress)
+ host_obj.set_or_delete_attribute(attribute, None)
+ return (True, 'Deleted attribute %s from DUT %s' % (
+ attribute, ipaddress))
+
+
def _get_connected_dut_labels(requested_label, only_first_label=True):
""" Query the DUT's attached to the moblab and return a filtered list
of labels.