@cryptotaxi247 / infra / commits / 37d2d672

Stop looking up plan info in the config file, use the remote metadata only

Graham Christensen committed Jun 3, 2022 at 10:50 UTC 37d2d672ac80d41323167fe0ca3b8645e7230b9e
1 file changed +10 -25
hydra-packet-importer/import.py
+10 -25
@@ -13,9 +13,12 @@ DeviceKeys = List[Dict[str, Any]]
13
14
15 class Metadata(TypedDict):
16 + user: Optional[str]
17 features: List[str]
18 + mandatory_features: List[str]
19 max_jobs: int
20 system_types: List[str]
21 + speed_factor: Optional[int]
22
23
24 class RemoteBuilder(TypedDict):
@@ -26,7 +29,6 @@ class RemoteBuilder(TypedDict):
29 class Builder(TypedDict):
30 hostname: str
31 address: str
29 - type: str
32 remote_builder_info: RemoteBuilder
33
34
@@ -88,7 +90,6 @@ def get_builders(manager: Any) -> List[Builder]:
90 {
91 "hostname": device["hostname"],
92 "address": "{}.packethost.net".format(device["short_id"]),
91 - "type": device["plan"]["name"],
93 "remote_builder_info": remote_builder_info,
94 }
95 )
@@ -155,39 +156,23 @@ def main(config: Dict[str, Any]) -> None:
156 for builder in get_builders(manager):
157 found += 1
158 debug("# {} ({})".format(builder["hostname"], builder["address"]))
158 - if builder["type"] not in config["plans"]:
159 - debug(
160 - "# Skipping {} (type {}) as it has no configured plan".format(
161 - builder["hostname"], builder["type"]
162 - )
163 - )
164 - continue
159
160 builder_info = builder["remote_builder_info"]
167 - default_stats = config["plans"][builder["type"]]
168 - if builder["hostname"] in config["name_overrides"]:
169 - specific_stats = config["name_overrides"][builder["hostname"]]
170 - else:
171 - specific_stats = {}
172 - lookup = lambda key: specific_stats.get(
173 - key, builder.get(key, default_stats.get(key))
174 - )
175 -
176 - lookup_default = (
177 - lambda key, default: default if not lookup(key) else lookup(key)
178 - )
161
162 # root@address system,list /var/lib/ssh.key maxJobs speedFactor feature,list mandatory,features public-host-key
163 rows.append(
164 " ".join(
165 [
184 - "{user}@{host}".format(user=lookup("user"), host=lookup("address")),
166 + "{user}@{host}".format(
167 + user=builder_info["metadata"].get("user", "root"),
168 + host=builder["hostname"],
169 + ),
170 ",".join(builder_info["metadata"]["system_types"]),
186 - str(lookup("ssh_key")),
171 + str(config["ssh_key"]),
172 str(builder_info["metadata"]["max_jobs"]),
188 - str(lookup("speed_factor")),
173 + str(builder_info["metadata"].get("speed_factor", 1)),
174 ",".join(builder_info["metadata"]["features"]),
190 - ",".join(lookup_default("mandatory_features", ["-"])),
175 + ",".join(builder_info["metadata"].get("mandatory_features", ["-"])),
176 base64.b64encode(builder_info["ssh_key"].encode()).decode("utf-8"),
177 ]
178 )