feat(chv): 架构与代码质量 9.5+ 提升——长函数清零、WarmPool facade、#215 对齐、审计计数、只读 VM 字段、ADR-8~11
This commit is contained in:
1 parent
c908a0147a
commit
42de20da68
15 files changed
+840
-345
No files matched your search
+40
-35
@@ -170,45 +170,21 @@ def _timeout_fragment(params: dict, env: dict) -> dict:
|
||||
}
|
||||
|
||||
|
||||
def build_chv_config(params: dict, env: dict):
|
||||
"""把显式构造参数(params,None=未给)与环境变量(env,
|
||||
默认为 os.environ 的调用方传入 dict)解析成 ChvConfig。
|
||||
def _assemble_chv_config(base: dict, ssh: dict, quota: dict,
|
||||
timeouts: dict):
|
||||
"""把基础字段 + SSH/配额/超时三个片段组装成 ChvConfig。
|
||||
|
||||
显式参数只有 __init__ 本来就有的那些;max_vms、磁盘模式、
|
||||
磁盘配额、egress、快照、预热池目标数本来就没有显式参数,
|
||||
仍只走环境变量(与 #216 一致,不悄悄加新参数面)。
|
||||
片段化(feat-chv-arch95):SSH 面、配额面、超时面分别
|
||||
由 _ssh_fragment/_quota_fragment/_timeout_fragment 解析,
|
||||
错误文案与校验顺序逐字一致;build_chv_config 只组装。"""
|
||||
env = env if env is not None else {}
|
||||
binary = params.get("binary") or env.get("CHV_BINARY") \
|
||||
or "cloud-hypervisor"
|
||||
kernel = params.get("kernel") or env.get("CHV_KERNEL")
|
||||
rootfs = params.get("rootfs") or params.get("image") \
|
||||
or env.get("CHV_ROOTFS") or env.get("CHV_IMAGE")
|
||||
cpus = str(params.get("cpus") or env.get("CHV_CPU") or "2")
|
||||
memory = params.get("memory") or env.get("CHV_MEM") or "2G"
|
||||
state_dir = params.get("state_dir") or env.get("CHV_STATE_DIR") \
|
||||
or os.path.join(os.path.expanduser("~"),
|
||||
".local", "share", "codex-app-server", "chv-vms")
|
||||
kvm_path = params.get("kvm_path") \
|
||||
if params.get("kvm_path") is not None else "/dev/kvm"
|
||||
cpuinfo_path = params.get("cpuinfo_path") \
|
||||
if params.get("cpuinfo_path") is not None else "/proc/cpuinfo"
|
||||
ch_remote = params.get("ch_remote") or env.get("CHV_REMOTE") \
|
||||
or "ch-remote"
|
||||
model = params.get("model")
|
||||
ssh = _ssh_fragment(params, env)
|
||||
quota = _quota_fragment(env)
|
||||
timeouts = _timeout_fragment(params, env)
|
||||
纯移动:字段名与取值逐字不变,build_chv_config 只解析。"""
|
||||
return ChvConfig(
|
||||
binary=binary, kernel=kernel, rootfs=rootfs, cpus=cpus,
|
||||
memory=memory, state_dir=state_dir, ssh_key=ssh["ssh_key"],
|
||||
ssh_user=ssh["ssh_user"], ssh_port=ssh["ssh_port"],
|
||||
binary=base["binary"], kernel=base["kernel"],
|
||||
rootfs=base["rootfs"], cpus=base["cpus"],
|
||||
memory=base["memory"], state_dir=base["state_dir"],
|
||||
ssh_key=ssh["ssh_key"], ssh_user=ssh["ssh_user"],
|
||||
ssh_port=ssh["ssh_port"],
|
||||
guest_host_py=ssh["guest_host_py"], cmdline=ssh["cmdline"],
|
||||
net=ssh["net"], net_json=ssh["net_json"],
|
||||
kvm_path=kvm_path, cpuinfo_path=cpuinfo_path,
|
||||
ch_remote=ch_remote, model=model,
|
||||
kvm_path=base["kvm_path"], cpuinfo_path=base["cpuinfo_path"],
|
||||
ch_remote=base["ch_remote"], model=base["model"],
|
||||
max_vms=quota["max_vms"], disk_mode=quota["disk_mode"],
|
||||
disk_gb=quota["disk_gb"], ssh_host=ssh["ssh_host"],
|
||||
ssh_forward=ssh["ssh_forward"],
|
||||
@@ -228,3 +204,32 @@ def build_chv_config(params: dict, env: dict):
|
||||
snapshot_retention_days=quota["snapshot_retention_days"],
|
||||
snapshot_dir=quota["snapshot_dir"],
|
||||
allow_remote_snapshot=quota["allow_remote_snapshot"])
|
||||
|
||||
|
||||
def build_chv_config(params: dict, env: dict):
|
||||
"""把显式构造参数与环境变量解析成 ChvConfig(见
|
||||
_assemble_chv_config 的组装段;片段化与校验顺序不变)。"""
|
||||
env = env if env is not None else {}
|
||||
base = {
|
||||
"binary": params.get("binary") or env.get("CHV_BINARY")
|
||||
or "cloud-hypervisor",
|
||||
"kernel": params.get("kernel") or env.get("CHV_KERNEL"),
|
||||
"rootfs": params.get("rootfs") or params.get("image")
|
||||
or env.get("CHV_ROOTFS") or env.get("CHV_IMAGE"),
|
||||
"cpus": str(params.get("cpus") or env.get("CHV_CPU") or "2"),
|
||||
"memory": params.get("memory") or env.get("CHV_MEM") or "2G",
|
||||
"state_dir": params.get("state_dir")
|
||||
or env.get("CHV_STATE_DIR")
|
||||
or os.path.join(os.path.expanduser("~"),
|
||||
".local", "share", "codex-app-server", "chv-vms"),
|
||||
"kvm_path": params.get("kvm_path")
|
||||
if params.get("kvm_path") is not None else "/dev/kvm",
|
||||
"cpuinfo_path": params.get("cpuinfo_path")
|
||||
if params.get("cpuinfo_path") is not None else "/proc/cpuinfo",
|
||||
"ch_remote": params.get("ch_remote") or env.get("CHV_REMOTE")
|
||||
or "ch-remote",
|
||||
"model": params.get("model"),
|
||||
}
|
||||
return _assemble_chv_config(
|
||||
base, _ssh_fragment(params, env), _quota_fragment(env),
|
||||
_timeout_fragment(params, env))
|
||||
Reference in new issue
Block a user