def get_hosts(multiple_labels=[], exclude_only_if_needed_labels=False, **filter_data): """\ multiple_labels: match hosts in all of the labels given. Should be a list of label names. exclude_only_if_needed_labels: exclude hosts with at least one "only_if_needed" label applied. """ hosts = rpc_utils.get_host_query(multiple_labels, exclude_only_if_needed_labels, filter_data) hosts = list(hosts) models.Host.objects.populate_relationships(hosts, models.Label, 'label_list') models.Host.objects.populate_relationships(hosts, models.AclGroup, 'acl_list') models.Host.objects.populate_relationships(hosts, models.HostAttribute, 'attribute_list') host_dicts = [] for host_obj in hosts: host_dict = host_obj.get_object_dict() host_dict['labels'] = [label.name for label in host_obj.label_list] host_dict['platform'], host_dict['atomic_group'] = (rpc_utils. find_platform_and_atomic_group(host_obj)) host_dict['acls'] = [acl.name for acl in host_obj.acl_list] host_dict['attributes'] = dict((attribute.attribute, attribute.value) for attribute in host_obj.attribute_list) host_dicts.append(host_dict) return rpc_utils.prepare_for_serialization(host_dicts)
def get_connected_dut_info(): """ RPC handler to get informaiton about the DUTs connected to the moblab. @return: A serialized JSON RPC object. """ # Make a list of the connected DUT's leases = _get_dhcp_dut_leases() connected_duts = _test_all_dut_connections(leases) # Get a list of the AFE configured DUT's hosts = list(rpc_utils.get_host_query((), False, True, {})) models.Host.objects.populate_relationships(hosts, models.Label, 'label_list') configured_duts = {} 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({ 'configured_duts': configured_duts, 'connected_duts': connected_duts })
def get_hosts(multiple_labels=(), exclude_only_if_needed_labels=False, exclude_atomic_group_hosts=False, valid_only=True, **filter_data): """ @param multiple_labels: match hosts in all of the labels given. Should be a list of label names. @param exclude_only_if_needed_labels: Exclude hosts with at least one "only_if_needed" label applied. @param exclude_atomic_group_hosts: Exclude hosts that have one or more atomic group labels associated with them. """ hosts = rpc_utils.get_host_query(multiple_labels, exclude_only_if_needed_labels, exclude_atomic_group_hosts, valid_only, filter_data) hosts = list(hosts) models.Host.objects.populate_relationships(hosts, models.Label, 'label_list') models.Host.objects.populate_relationships(hosts, models.AclGroup, 'acl_list') models.Host.objects.populate_relationships(hosts, models.HostAttribute, 'attribute_list') host_dicts = [] for host_obj in hosts: host_dict = host_obj.get_object_dict() host_dict['labels'] = [label.name for label in host_obj.label_list] host_dict['platform'], host_dict['atomic_group'] = (rpc_utils. find_platform_and_atomic_group(host_obj)) host_dict['acls'] = [acl.name for acl in host_obj.acl_list] host_dict['attributes'] = dict((attribute.attribute, attribute.value) for attribute in host_obj.attribute_list) host_dicts.append(host_dict) return rpc_utils.prepare_for_serialization(host_dicts)
def get_num_hosts(multiple_labels=(), exclude_only_if_needed_labels=False, exclude_atomic_group_hosts=False, valid_only=True, **filter_data): """ Same parameters as get_hosts(). @returns The number of matching hosts. """ hosts = rpc_utils.get_host_query(multiple_labels, exclude_only_if_needed_labels, exclude_atomic_group_hosts, valid_only, filter_data) return hosts.count()
def _get_connected_dut_board_models(): """ Get the boards and their models of attached DUTs @return: A de-duped list of dut board/model attached to the moblab format: [ { "board": "carl", "model": "bruce" }, { "board": "veyron_minnie", "model": "veyron_minnie" } ] """ hosts = list(rpc_utils.get_host_query((), False, True, {})) if not hosts: return [] models.Host.objects.populate_relationships(hosts, models.Label, 'label_list') model_board_map = dict() for host in hosts: model = '' board = '' for label in host.label_list: if 'model:' in label.name: model = label.name.replace('model:', '') elif 'board:' in label.name: board = label.name.replace('board:', '') model_board_map[model] = board board_models_list = [] for model in sorted(model_board_map.keys()): board_models_list.append({ 'model': model, 'board': model_board_map[model] }) return board_models_list
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. @param requested_label: the label name you are requesting. @param only_first_label: if the device has the same label name multiple times only return the first label value in the list. @return: A de-duped list of requested dut labels attached to the moblab. """ hosts = list(rpc_utils.get_host_query((), False, True, {})) if not hosts: return [] models.Host.objects.populate_relationships(hosts, models.Label, 'label_list') labels = set() for host in hosts: for label in host.label_list: if requested_label in label.name: labels.add(label.name.replace(requested_label, '')) if only_first_label: break return list(labels)
def get_num_hosts(multiple_labels=[], exclude_only_if_needed_labels=False, **filter_data): hosts = rpc_utils.get_host_query(multiple_labels, exclude_only_if_needed_labels, filter_data) return hosts.count()