[autotest] Add in host attr and locking rpcs/methods.

Add in get_hosts_by_attributes(attribute, value) RPC which returns a list
of hosts that share the same value for the specified host attribute.

Added a {lock,unlock}_hosts method on the AFE.

BUG=chromium:599533
TEST=locally on moblab
afe = frontend_wrappers.RetryingAFE(timeout_min=5, delay_sec=10)
print afe.get_hosts_by_attribute(
        attribute='servo_host',
        value='100.107.151.237')

Change-Id: Id288697ebd2f11dad04ba6a477a35b45e39f9830
Reviewed-on: https://chromium-review.googlesource.com/388674
Commit-Ready: Kevin Cheng <kevcheng@chromium.org>
Tested-by: Kevin Cheng <kevcheng@chromium.org>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index cf392a8..d7c433c 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -1727,3 +1727,18 @@
 
 def get_server_time():
     return datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
+
+
+def get_hosts_by_attribute(attribute, value):
+    """
+    Get the list of valid hosts that share the same host attribute value.
+
+    @param attribute: String of the host attribute to check.
+    @param value: String of the value that is shared between hosts.
+
+    @returns List of hostnames that all have the same host attribute and
+             value.
+    """
+    hosts = models.HostAttribute.query_objects({'attribute': attribute,
+                                                'value': value})
+    return [row.host.hostname for row in hosts if row.host.invalid == 0]