forked from bn222/cluster-deployment-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarvell.py
94 lines (77 loc) · 2.93 KB
/
marvell.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
import shlex
from clustersConfig import ClustersConfig
from clustersConfig import NodeConfig
from bmc import BmcConfig
import dhcpConfig
import common
import host
def marvell_bmc_rsh(bmc: BmcConfig) -> host.Host:
# For Marvell DPU, we require that our "BMC" is the host on has the DPU
# plugged in.
#
# We also assume, that the user name is "core" and that we can SSH into
# that host with public key authentication. We ignore the `bmc.user`
# setting. The reason for that is so that dpu-operator's
# "hack/cluster-config/config-dpu.yaml" (which should work with IPU and
# Marvell DPU) does not need to specify different BMC user name and
# passwords. If you solve how to express the BMC authentication in the
# cluster config in a way that is suitable for IPU and Marvell DPU at the
# same time (e.g. via Jinja2 templates), we can start honoring
# bmc.user/bmc.password.
rsh = host.RemoteHost(bmc.url)
rsh.ssh_connect("core")
return rsh
def is_marvell(bmc: BmcConfig) -> bool:
rsh = marvell_bmc_rsh(bmc)
return "177d:b900" in rsh.run("lspci -nn -d :b900").out
def _pxeboot_marvell_dpu(name: str, bmc: BmcConfig, mac: str, ip: str, iso: str) -> None:
rsh = marvell_bmc_rsh(bmc)
ip_addr = f"{ip}/24"
ip_gateway, _ = dhcpConfig.get_subnet_range(ip, "255.255.255.0")
# An empty entry means to use the host's "id_ed25519.pub". We want that.
ssh_keys = [""]
for _, pub_key_content, _ in common.iterate_ssh_keys():
ssh_keys.append(pub_key_content)
ssh_key_options = [f"--ssh-key={shlex.quote(s)}" for s in ssh_keys]
image = os.environ.get("CDA_MARVELL_TOOLS_IMAGE", "quay.io/sdaniele/marvell-tools:latest")
r = rsh.run(
"sudo "
"podman "
"run "
"--pull always "
"--rm "
"--replace "
"--privileged "
"--pid host "
"--network host "
"--user 0 "
"--name marvell-tools "
"-i "
"-v /:/host "
"-v /dev:/dev "
f"{shlex.quote(image)} "
"./pxeboot.py "
f"--dpu-name={shlex.quote(name)} "
"--host-mode=coreos "
f"--nm-secondary-cloned-mac-address={shlex.quote(mac)} "
f"--nm-secondary-ip-address={shlex.quote(ip_addr)} "
f"--nm-secondary-ip-gateway={shlex.quote(ip_gateway)} "
"--yum-repos=rhel-nightly "
"--default-extra-packages "
f"{' '.join(ssh_key_options)} "
f"{shlex.quote(iso)} "
"2>&1"
)
if not r.success():
raise RuntimeError(f"Failure to to pxeboot: {r}")
def MarvellIsoBoot(cc: ClustersConfig, node: NodeConfig, iso: str) -> None:
assert node.ip is not None
assert node.bmc is not None
_pxeboot_marvell_dpu(node.name, node.bmc, node.mac, node.ip, iso)
dhcpConfig.configure_iso_network_port(cc.network_api_port, node.ip)
dhcpConfig.configure_dhcpd(node)
def main() -> None:
pass
if __name__ == "__main__":
main()