blob: e7eb276afababbc3f858d9c75dbb648597d08a5c [file] [log] [blame]
# Copyright 2019 Fairphone B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Utilities for dumping information from a LAVA instance.
This module helps creating configuration files in a format expected by
configure_lava.
"""
from typing import Dict, List, Union
import yaml
from lava_interface import Lavacli
def dump_devices(lavacli_identity: str, dump_all: bool = False) -> None:
"""List devices of the LAVA instance and their meta data."""
lavacli = Lavacli(identity=lavacli_identity)
lavacli_args = ["list", "--yaml"]
if dump_all:
lavacli_args.append("--all")
devices_per_type: Dict["str", List[Dict[str, Union[str, List[str]]]]] = {}
for device in lavacli.devices_cmd_yaml(*lavacli_args):
hostname = device["hostname"]
device_details = lavacli.devices_cmd_yaml("show", hostname, "--yaml")
serial = lavacli.devices_cmd(
"dict", "get", hostname, "adb_serial_number"
).strip()
device_dict = {
"hostname": hostname,
"lava-worker": device_details["worker"],
"tags": device_details["tags"],
"template_args": {"device_serial": serial},
}
devices_per_type.setdefault(device["type"], []).append(device_dict)
stream = yaml.dump(
devices_per_type, default_flow_style=False, line_break=False
)
print(stream.replace("\n- ", "\n\n- "))