authoravatarclover caruso<git@paperclover.net>2026-10-21 02:19:43-07:00
committeravatarclover caruso<git@paperclover.net>2026-10-21 02:52:57-07:00
log792a5281167703c9ee7525e7016cb3faf1fc06b5
tree1d65bbfe07ec5ee53fbe90cb63831e381dbde43e
parent48149be04c0e2d6f0d219eb70e07ca7f45d824c9
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Finish the Snow Globe namespace migration

Remove legacy path, release, VM, telemetry and metadata compatibility after migrating retained telemetry to canonical names. Serve source status at /stats and /activity, rename Plausible configuration mounts, and preserve pre-rename releases as archives. Verified Rust, dashboard, deployment and host checks, fresh service previews, and a production telemetry cutover with complete sample and trace validation plus original-store archives. Assisted-by: gpt-6.1-sol

26 files changed, 110 insertions(+), 856 deletions(-)

dashboard/src/apps.rs+1-8
...@@ -136,14 +136,7 @@ async fn paper(app: Arc<App>, path: &str, body: Option<Value>) -> Result<Value>...@@ -136,14 +136,7 @@ async fn paper(app: Arc<App>, path: &str, body: Option<Value>) -> Result<Value>
136 let key = key136 let key = key
137 .as_str()137 .as_str()
138 .ok_or_else(|| Error::new(502, "Paper Clover is unavailable."))?;138 .ok_or_else(|| Error::new(502, "Paper Clover is unavailable."))?;
139 let url = format!(139 let url = format!("https://{host}/{path}");
140 "https://{host}/{}",
141 if path == "scan" {
142 path.into()
143 } else {
144 format!("{}/{path}", namespace::PREVIOUS.as_str())
145 }
146 );
147 let request = if let Some(body) = body {140 let request = if let Some(body) = body {
148 app.http.post(&url).json(&body)141 app.http.post(&url).json(&body)
149 } else {142 } else {
dashboard/src/core.rs+2-4
...@@ -5,12 +5,10 @@ use std::path::Path;...@@ -5,12 +5,10 @@ use std::path::Path;
55
6pub async fn nomad(app: &App, path: &str) -> Result<Value> {6pub async fn nomad(app: &App, path: &str) -> Result<Value> {
7 let value = nomad_raw(app, path).await?;7 let value = nomad_raw(app, path).await?;
8 let mut value = value8 Ok(value
9 .map(|bytes| serde_json::from_slice(&bytes))9 .map(|bytes| serde_json::from_slice(&bytes))
10 .transpose()?10 .transpose()?
11 .unwrap_or(Value::Null);11 .unwrap_or(Value::Null))
12 namespace::nomad(&mut value);
13 Ok(value)
14}12}
15pub async fn nomad_raw(app: &App, path: &str) -> Result<Option<Bytes>> {13pub async fn nomad_raw(app: &App, path: &str) -> Result<Option<Bytes>> {
16 let request = async {14 let request = async {
dashboard/src/main.rs-1
...@@ -11,7 +11,6 @@ mod guest;...@@ -11,7 +11,6 @@ mod guest;
11mod host;11mod host;
12mod index;12mod index;
13mod mcp;13mod mcp;
14mod namespace;
15mod observability;14mod observability;
16mod oidc;15mod oidc;
17mod relay;16mod relay;
dashboard/src/namespace-transition.json deleted-4
...@@ -1,4 +0,0 @@
1{
2 "previous": "studio",
3 "previousHost": "zenith"
4}
dashboard/src/namespace.rs deleted-87
...@@ -1,87 +0,0 @@
1use crate::*;
2use serde_json::Map;
3
4pub static PREVIOUS: std::sync::LazyLock<String> = std::sync::LazyLock::new(|| {
5 serde_json::from_str::<Value>(include_str!("namespace-transition.json")).unwrap()["previous"]
6 .as_str().unwrap().to_owned()
7});
8
9fn keys(values: &mut Map<String, Value>, separator: &str) {
10 let prefix = format!("{}{separator}", PREVIOUS.as_str());
11 let renamed: Vec<_> = values.keys().filter_map(|key| {
12 key.strip_prefix(&prefix).map(|suffix| (key.clone(), format!("snowglobe{separator}{suffix}")))
13 }).collect();
14 for (old, new) in renamed {
15 let value = values.remove(&old).unwrap();
16 values.entry(new).or_insert(value);
17 }
18}
19
20pub fn nomad(value: &mut Value) {
21 match value {
22 Value::Object(values) => {
23 if let Some(meta) = values.get_mut("Meta").and_then(Value::as_object_mut) {
24 keys(meta, "_");
25 }
26 if let Some(tags) = values.get_mut("Tags").and_then(Value::as_array_mut) {
27 let prefix = format!("{}-metrics-path=", PREVIOUS.as_str());
28 for tag in tags {
29 if let Some(path) = tag.as_str().and_then(|tag| tag.strip_prefix(&prefix)) {
30 *tag = json!(format!("snowglobe-metrics-path={path}"));
31 }
32 }
33 }
34 for value in values.values_mut() {
35 nomad(value);
36 }
37 }
38 Value::Array(values) => values.iter_mut().for_each(nomad),
39 _ => {}
40 }
41}
42
43pub fn attributes(values: &mut Map<String, Value>) {
44 keys(values, ".");
45}
46
47pub fn metric_selector(metric: &str, labels: &str) -> String {
48 let previous = metric.replacen("snowglobe_", &format!("{}_", PREVIOUS.as_str()), 1);
49 format!("sum without (__name__) ({metric}{labels}) or sum without (__name__) ({previous}{labels})")
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn persisted_metadata_is_read_once_with_current_values_winning() {
58 let old = PREVIOUS.as_str();
59 let mut value = json!({"Meta": {
60 format!("{old}_name"): "old name", "snowglobe_name": "Snow Globe",
61 format!("{old}_hostname"): "knife.example.test"
62 }, "TaskGroups": [{"Services": [{"Tags": [format!("{old}-metrics-path=/metrics"), "caddy-host=knife.example.test"]}]}],
63 "Config": {"Env": {format!("{}_DOMAIN", old.to_uppercase()): "untouched"}}});
64 nomad(&mut value);
65 assert_eq!(value["Meta"]["snowglobe_name"], "Snow Globe");
66 assert_eq!(value["Meta"]["snowglobe_hostname"], "knife.example.test");
67 assert!(value["Meta"].get(format!("{old}_name")).is_none());
68 assert_eq!(value["TaskGroups"][0]["Services"][0]["Tags"][0], "snowglobe-metrics-path=/metrics");
69 assert_eq!(value["Config"]["Env"][format!("{}_DOMAIN", old.to_uppercase())], "untouched");
70 let normalized = value.clone();
71 nomad(&mut value);
72 assert_eq!(value, normalized);
73 }
74
75 #[test]
76 fn historical_trace_ownership_remains_explicit() {
77 let mut values = Map::from_iter([
78 (format!("{}.service", PREVIOUS.as_str()), json!("private")),
79 (format!("{}.kind", PREVIOUS.as_str()), json!("edge")),
80 ("snowglobe.service".into(), json!("current")),
81 ]);
82 attributes(&mut values);
83 assert_eq!(values["snowglobe.service"], "current");
84 assert_eq!(values["snowglobe.kind"], "edge");
85 assert_eq!(values.len(), 2);
86 }
87}
dashboard/src/telemetry.rs+3-4
...@@ -189,7 +189,7 @@ pub async fn metrics(...@@ -189,7 +189,7 @@ pub async fn metrics(
189 quote(id)189 quote(id)
190 ))190 ))
191 .unwrap_or_default();191 .unwrap_or_default();
192 namespace::metric_selector(metric, &labels)192 format!("{metric}{labels}")
193 };193 };
194 let key = if window.is_some() {194 let key = if window.is_some() {
195 format!("series:{selector}:fixed:{from}:{to}")195 format!("series:{selector}:fixed:{from}:{to}")
...@@ -228,8 +228,8 @@ pub async fn metric_names(app: Arc<App>, id: &str) -> Result<Value> {...@@ -228,8 +228,8 @@ pub async fn metric_names(app: Arc<App>, id: &str) -> Result<Value> {
228 (228 (
229 "match[]",229 "match[]",
230 format!(230 format!(
231 "{{{label}={},__name__!~\"(snowglobe|{})_.*\"}}",231 "{{{label}={},__name__!~\"snowglobe_.*\"}}",
232 serde_json::to_string(id).unwrap(), namespace::PREVIOUS.as_str()232 serde_json::to_string(id).unwrap()
233 ),233 ),
234 )234 )
235 }));235 }));
...@@ -467,7 +467,6 @@ fn span(row: &Value) -> Value {...@@ -467,7 +467,6 @@ fn span(row: &Value) -> Value {
467 .map(|key| (key.into(), value.clone()))467 .map(|key| (key.into(), value.clone()))
468 })468 })
469 .collect();469 .collect();
470 namespace::attributes(&mut attributes);
471 for (from, to) in [470 for (from, to) in [
472 ("http.request.method", "http.request.method"),471 ("http.request.method", "http.request.method"),
473 ("http.response.status_code", "http.response.status_code"),472 ("http.response.status_code", "http.response.status_code"),
nixos/configuration.nix+1-1
...@@ -6,7 +6,7 @@ let...@@ -6,7 +6,7 @@ let
6 proxyToken = "/var/lib/snowglobe/dashboard-proxy.token";6 proxyToken = "/var/lib/snowglobe/dashboard-proxy.token";
7 hostTools = lib.fileset.toSource {7 hostTools = lib.fileset.toSource {
8 root = ../.;8 root = ../.;
9 fileset = lib.fileset.unions [ ../tools/dashboard-host.py ../service/copyparty/manage.py ../service/copyparty/copyparty.conf ../tools/shale-labels.py ../tools/shale-access.py ../config/shale.json ../config/site.pkl ../dashboard/src/host-protocol.json ../tools/vms.py ../tools/mac-vms.py ../tools/vm-ssh.py ../tools/dashboard-run.py ../tools/release.py ../tools/namespace-transition.py ../dashboard/src/namespace-transition.json ../guest/protocol.json ];9 fileset = lib.fileset.unions [ ../tools/dashboard-host.py ../service/copyparty/manage.py ../service/copyparty/copyparty.conf ../tools/shale-labels.py ../tools/shale-access.py ../config/shale.json ../config/site.pkl ../dashboard/src/host-protocol.json ../tools/vms.py ../tools/mac-vms.py ../tools/vm-ssh.py ../tools/dashboard-run.py ../tools/release.py ../guest/protocol.json ];
10 };10 };
11 nativePkl = pkgs.callPackage ./pkl.nix { };11 nativePkl = pkgs.callPackage ./pkl.nix { };
12 hostPython = pkgs.callPackage ./host-python.nix { };12 hostPython = pkgs.callPackage ./host-python.nix { };
service/clover-source-of-truth/build-source.json+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1{1{
2 "source": "../sitegen",2 "source": "../sitegen",
3 "revision": "13f64d71038f5e72ab34dc1f55805e2fee05f368",3 "revision": "4964d828660c6603c009e55b41e06c56b49c4bcf",
4 "dockerfile": "src/source-of-truth.dockerfile",4 "dockerfile": "src/source-of-truth.dockerfile",
5 "include": [5 "include": [
6 "package.json",6 "package.json",
service/plausible/service.pkl+2-2
...@@ -58,8 +58,8 @@ containers {...@@ -58,8 +58,8 @@ containers {
58 }58 }
59 volumes {59 volumes {
60 ["/var/lib/clickhouse"] {}60 ["/var/lib/clickhouse"] {}
61 ["/etc/clickhouse-server/config.d/studio.xml"] { config = "clickhouse.xml" }61 ["/etc/clickhouse-server/config.d/snowglobe.xml"] { config = "clickhouse.xml" }
62 ["/etc/clickhouse-server/users.d/studio.xml"] { config = "clickhouse-users.xml" }62 ["/etc/clickhouse-server/users.d/snowglobe.xml"] { config = "clickhouse-users.xml" }
63 }63 }
64 env {64 env {
65 ["CLICKHOUSE_SKIP_USER_SETUP"] = "1"65 ["CLICKHOUSE_SKIP_USER_SETUP"] = "1"
tools/dashboard-deploy-test.py+1-1
...@@ -170,7 +170,7 @@ class DeploymentBoundary(unittest.TestCase):...@@ -170,7 +170,7 @@ class DeploymentBoundary(unittest.TestCase):
170 output = 'job "fixture" {\n' if argv[-1] == "render" else '"leader"'170 output = 'job "fixture" {\n' if argv[-1] == "render" else '"leader"'
171 return subprocess.CompletedProcess(argv, 0, stdout=output, stderr="")171 return subprocess.CompletedProcess(argv, 0, stdout=output, stderr="")
172172
173 with patch.object(release.subprocess, "run", side_effect=execute), patch.object(release, "host_configuration", return_value="snowglobe"), patch.object(release.transition, "activate"), patch.object(173 with patch.object(release.subprocess, "run", side_effect=execute), patch.object(release, "host_configuration", return_value="snowglobe"), patch.object(
174 Path, "read_text", autospec=True,174 Path, "read_text", autospec=True,
175 side_effect=lambda path: os.uname().nodename + "\n" if path == Path("/etc/hostname") else read_text(path),175 side_effect=lambda path: os.uname().nodename + "\n" if path == Path("/etc/hostname") else read_text(path),
176 ):176 ):
tools/dashboard-logs-test.py+1-1
...@@ -111,7 +111,7 @@ def main():...@@ -111,7 +111,7 @@ def main():
111 port = reservation.getsockname()[1]111 port = reservation.getsockname()[1]
112 origin = f'http://127.0.0.1:{port}'112 origin = f'http://127.0.0.1:{port}'
113 environment = {**os.environ, 'PORT': str(port), 'SNOWGLOBE_DATA_DIR': str(root / 'data'),113 environment = {**os.environ, 'PORT': str(port), 'SNOWGLOBE_DATA_DIR': str(root / 'data'),
114 'SNOWGLOBE_PUBLIC_ORIGIN': 'https://globe.studio.test', 'SNOWGLOBE_NOMAD_TOKEN_FILE': str(root / 'token'),114 'SNOWGLOBE_PUBLIC_ORIGIN': 'https://globe.snowglobe.test', 'SNOWGLOBE_NOMAD_TOKEN_FILE': str(root / 'token'),
115 'NOMAD_ADDR': f'http://127.0.0.1:{fixture.server_port}'}115 'NOMAD_ADDR': f'http://127.0.0.1:{fixture.server_port}'}
116 environment['SNOWGLOBE_PREVIEW'] = '1' if args.preview else '0'116 environment['SNOWGLOBE_PREVIEW'] = '1' if args.preview else '0'
117 for name in ['SNOWGLOBE_PROXY_TOKEN_FILE', 'SNOWGLOBE_INTERNAL_URL', 'SNOWGLOBE_AUTH_REQUIRED', 'SNOWGLOBE_INDEX_POOL', 'SNOWGLOBE_YT_STATE']:117 for name in ['SNOWGLOBE_PROXY_TOKEN_FILE', 'SNOWGLOBE_INTERNAL_URL', 'SNOWGLOBE_AUTH_REQUIRED', 'SNOWGLOBE_INDEX_POOL', 'SNOWGLOBE_YT_STATE']:
tools/dashboard-run.py+4-4
...@@ -160,11 +160,11 @@ def command(action, target, key=None):...@@ -160,11 +160,11 @@ def command(action, target, key=None):
160 version = release.current_release()160 version = release.current_release()
161 if version is None:161 if version is None:
162 raise Error(409, "No release is running. Deploy a release before starting this service.")162 raise Error(409, "No release is running. Deploy a release before starting this service.")
163 return [sys.executable, str(release.transition.layout(release.check_release(version))["script"]), "deploy", target]163 return [sys.executable, str(release.check_release(version) / "tools/snowglobe.py"), "deploy", target]
164 if action == "rollback":164 if action == "rollback":
165 saved = entry(target)165 saved = entry(target)
166 version = saved["release"]166 version = saved["release"]
167 release.check_release(version, legacy=saved.get("legacy") is True)167 release.check_release(version)
168 return [sys.executable, str(Path(__file__).with_name("release.py")), "rollback", version]168 return [sys.executable, str(Path(__file__).with_name("release.py")), "rollback", version]
169 if action == "deploy":169 if action == "deploy":
170 candidate = release.main_release()170 candidate = release.main_release()
...@@ -177,7 +177,7 @@ def command(action, target, key=None):...@@ -177,7 +177,7 @@ def command(action, target, key=None):
177 if not isinstance(version, str):177 if not isinstance(version, str):
178 raise Error(409, "This stage has no release. Stage it again.")178 raise Error(409, "This stage has no release. Stage it again.")
179 root = release.check_release(version)179 root = release.check_release(version)
180 return [sys.executable, str(release.transition.layout(root)["script"]), "destroy", target]180 return [sys.executable, str(root / "tools/snowglobe.py"), "destroy", target]
181181
182182
183def last():183def last():
...@@ -372,7 +372,7 @@ def worker(identity, action, target, key=None):...@@ -372,7 +372,7 @@ def worker(identity, action, target, key=None):
372 try:372 try:
373 argv = command(action, target, key)373 argv = command(action, target, key)
374 output.write(("$ " + " ".join(argv) + "\n").encode())374 output.write(("$ " + " ".join(argv) + "\n").encode())
375 environment = release.transition.environment(Path(argv[1]).parent.parent) if len(argv) > 1 and argv[1].endswith(".py") else None375 environment = None
376 if action in {"stop", "restart"}:376 if action in {"stop", "restart"}:
377 environment = {**os.environ, "NOMAD_TOKEN": read(release.STATE / "nomad.token", missing="").strip()}377 environment = {**os.environ, "NOMAD_TOKEN": read(release.STATE / "nomad.token", missing="").strip()}
378 if not environment["NOMAD_TOKEN"]:378 if not environment["NOMAD_TOKEN"]:
tools/dashboard-stage-test.py+3-1
...@@ -98,6 +98,8 @@ class PreviewProof(unittest.TestCase):...@@ -98,6 +98,8 @@ class PreviewProof(unittest.TestCase):
98 output = ""98 output = ""
99 if args[0] == "pkl":99 if args[0] == "pkl":
100 output = json.dumps(site)100 output = json.dumps(site)
101 elif args[:3] == ("systemctl", "show", "snowglobe-host"):
102 output = "PATH=/bin"
101 elif args[:4] == ("nomad", "acl", "token", "create"):103 elif args[:4] == ("nomad", "acl", "token", "create"):
102 output = json.dumps({"AccessorID": "fixture-accessor", "SecretID": "fixture-nomad-token"})104 output = json.dumps({"AccessorID": "fixture-accessor", "SecretID": "fixture-nomad-token"})
103 elif args[:2] == ("podman", "run"):105 elif args[:2] == ("podman", "run"):
...@@ -113,7 +115,7 @@ class PreviewProof(unittest.TestCase):...@@ -113,7 +115,7 @@ class PreviewProof(unittest.TestCase):
113 def exists(path):115 def exists(path):
114 return str(path).startswith("/run/snowglobe-preview/") and path.name == "host.sock" or original_exists(path)116 return str(path).startswith("/run/snowglobe-preview/") and path.name == "host.sock" or original_exists(path)
115117
116 with patch.object(stage.snowglobe, "STATE", state), patch.object(stage.snowglobe, "REPO", root / "releases/1234567890abcdef"), patch.object(stage.snowglobe, "token"), patch.object(stage.snowglobe, "identity", return_value=os.getuid()), patch.object(stage.snowglobe, "check_staging_pool"), patch.object(stage.snowglobe, "check_http") as check_http, patch.object(stage.snowglobe, "command", side_effect=command), patch.object(stage.subprocess, "run", side_effect=run), patch.object(stage.os, "chown") as chown, patch.object(stage.snowglobe.transition, "host_environment", return_value="PATH=/bin"), patch.object(stage.snowglobe.transition, "stop_preview"), patch.object(Path, "exists", exists), redirect_stdout(io.StringIO()):118 with patch.object(stage.snowglobe, "STATE", state), patch.object(stage.snowglobe, "REPO", root / "releases/1234567890abcdef"), patch.object(stage.snowglobe, "token"), patch.object(stage.snowglobe, "identity", return_value=os.getuid()), patch.object(stage.snowglobe, "check_staging_pool"), patch.object(stage.snowglobe, "check_http") as check_http, patch.object(stage.snowglobe, "command", side_effect=command), patch.object(stage.subprocess, "run", side_effect=run), patch.object(stage.os, "chown") as chown, patch.object(Path, "exists", exists), redirect_stdout(io.StringIO()):
117 stage.stage()119 stage.stage()
118 check_http.assert_called_once_with(jobs[-1]["ID"] + ".fixture.test", "/sign-in", True)120 check_http.assert_called_once_with(jobs[-1]["ID"] + ".fixture.test", "/sign-in", True)
119 task = jobs[-1]["TaskGroups"][0]["Tasks"][0]121 task = jobs[-1]["TaskGroups"][0]["Tasks"][0]
tools/dashboard-stage.py+3-3
...@@ -166,10 +166,10 @@ def stage():...@@ -166,10 +166,10 @@ def stage():
166 *["--env=" + key + "=" + value for key, value in env.items()], image, "--preview-account", capture=True)166 *["--env=" + key + "=" + value for key, value in env.items()], image, "--preview-account", capture=True)
167 snowglobe.write_private(root / "access.json", imported.stdout)167 snowglobe.write_private(root / "access.json", imported.stdout)
168 runtime = "/run/snowglobe-preview/" + identity168 runtime = "/run/snowglobe-preview/" + identity
169 host_environment = snowglobe.transition.host_environment()169 host_environment = snowglobe.command("systemctl", "show", "snowglobe-host", "--property=Environment", "--value", capture=True).stdout
170 host_path = next(value for value in shlex.split(host_environment) if value.startswith("PATH="))170 host_path = next(value for value in shlex.split(host_environment) if value.startswith("PATH="))
171 host_python = snowglobe.command(*nix, "build", "--no-link", "--print-out-paths", "path:" + str(snowglobe.REPO) + "#host-python", capture=True).stdout.strip()171 host_python = snowglobe.command(*nix, "build", "--no-link", "--print-out-paths", "path:" + str(snowglobe.REPO) + "#host-python", capture=True).stdout.strip()
172 snowglobe.transition.stop_preview(identity)172 subprocess.run(["systemctl", "stop", "snowglobe-preview-" + identity], capture_output=True)
173 snowglobe.command("systemd-run", "--collect", "--quiet", "--unit=snowglobe-preview-" + identity,173 snowglobe.command("systemd-run", "--collect", "--quiet", "--unit=snowglobe-preview-" + identity,
174 "--property=Restart=on-failure", "--property=MemoryMax=256M", "--property=TasksMax=32",174 "--property=Restart=on-failure", "--property=MemoryMax=256M", "--property=TasksMax=32",
175 "--setenv=" + host_path, "--setenv=SNOWGLOBE_DOMAIN=" + site["domain"],175 "--setenv=" + host_path, "--setenv=SNOWGLOBE_DOMAIN=" + site["domain"],
...@@ -205,7 +205,7 @@ def stage():...@@ -205,7 +205,7 @@ def stage():
205def destroy(identity):205def destroy(identity):
206 snowglobe.token()206 snowglobe.token()
207 saved = metadata(identity)207 saved = metadata(identity)
208 snowglobe.transition.stop_preview(identity)208 subprocess.run(["systemctl", "stop", "snowglobe-preview-" + identity], capture_output=True)
209 if saved.get("tokenAccessor"):209 if saved.get("tokenAccessor"):
210 revoked = subprocess.run(["nomad", "acl", "token", "delete", saved["tokenAccessor"]], capture_output=True, text=True)210 revoked = subprocess.run(["nomad", "acl", "token", "delete", saved["tokenAccessor"]], capture_output=True, text=True)
211 if revoked.returncode and "400 (Cannot delete nonexistent tokens:" not in revoked.stderr:211 if revoked.returncode and "400 (Cannot delete nonexistent tokens:" not in revoked.stderr:
tools/data.py+6-10
...@@ -4,7 +4,6 @@ from contextlib import closing, contextmanager...@@ -4,7 +4,6 @@ from contextlib import closing, contextmanager
4from datetime import datetime, timezone4from datetime import datetime, timezone
5import hashlib5import hashlib
6import json6import json
7from importlib import import_module
8import os7import os
9from pathlib import Path8from pathlib import Path
10import re9import re
...@@ -15,8 +14,6 @@ import subprocess...@@ -15,8 +14,6 @@ import subprocess
15import time14import time
1615
1716
18transition = import_module("namespace-transition")
19
20ROOT = Path("/opt/snowglobe")17ROOT = Path("/opt/snowglobe")
21STATE = Path("/var/lib/snowglobe")18STATE = Path("/var/lib/snowglobe")
22BACKUPS = STATE / "backups"19BACKUPS = STATE / "backups"
...@@ -265,8 +262,7 @@ def restore(backup_id, service):...@@ -265,8 +262,7 @@ def restore(backup_id, service):
265 path = source / name262 path = source / name
266 if not path.resolve().is_relative_to(source.resolve()) or not path.is_file() or checksum(path) != digest:263 if not path.resolve().is_relative_to(source.resolve()) or not path.is_file() or checksum(path) != digest:
267 raise ValueError("Dashboard backup is missing or changed")264 raise ValueError("Dashboard backup is missing or changed")
268 unit = transition.layout(current_release())["prefix"] + "-dashboard"265 run("systemctl", "stop", "snowglobe-dashboard")
269 run("systemctl", "stop", unit)
270 safety = BACKUPS / ("before-restore-" + datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ") + "-" + secrets.token_hex(3))266 safety = BACKUPS / ("before-restore-" + datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%SZ") + "-" + secrets.token_hex(3))
271 safety.mkdir(mode=0o700)267 safety.mkdir(mode=0o700)
272 files = backup_dashboard(safety / "dashboard")268 files = backup_dashboard(safety / "dashboard")
...@@ -277,8 +273,8 @@ def restore(backup_id, service):...@@ -277,8 +273,8 @@ def restore(backup_id, service):
277 if (root / "pictures").exists():273 if (root / "pictures").exists():
278 shutil.rmtree(root / "pictures")274 shutil.rmtree(root / "pictures")
279 shutil.copytree(source, root, dirs_exist_ok=True)275 shutil.copytree(source, root, dirs_exist_ok=True)
280 run("systemctl", "start", unit)276 run("systemctl", "start", "snowglobe-dashboard")
281 run("systemctl", "is-active", "--quiet", unit)277 run("systemctl", "is-active", "--quiet", "snowglobe-dashboard")
282 print(f"restored=dashboard backup={backup_id} safety={safety.name}")278 print(f"restored=dashboard backup={backup_id} safety={safety.name}")
283 return279 return
284 dataset = entry.get("dataset")280 dataset = entry.get("dataset")
...@@ -323,9 +319,9 @@ def restore(backup_id, service):...@@ -323,9 +319,9 @@ def restore(backup_id, service):
323 with (directory / database["dump"]).open("rb") as input_file:319 with (directory / database["dump"]).open("rb") as input_file:
324 run(*PODMAN, "exec", "-i", container, "pg_restore", "-U", "postgres", "-d", name,320 run(*PODMAN, "exec", "-i", container, "pg_restore", "-U", "postgres", "-d", name,
325 "--no-owner", "--no-acl", "--role=" + owner, stdin=input_file)321 "--no-owner", "--no-acl", "--role=" + owner, stdin=input_file)
326 script = transition.layout(current_release())["script"]322 script = current_release() / "tools/snowglobe.py"
327 run("python3", str(script), "deploy", service, env=transition.environment(current_release()))323 run("python3", str(script), "deploy", service)
328 run("python3", str(script), "check", service, env=transition.environment(current_release()))324 run("python3", str(script), "check", service)
329 print(f"restored={service} backup={backup_id} safety={safety}")325 print(f"restored={service} backup={backup_id} safety={safety}")
330326
331327
tools/deploy.py+1-11
...@@ -38,18 +38,9 @@ def run_logged(mode, target, command):...@@ -38,18 +38,9 @@ def run_logged(mode, target, command):
38 print(f"run={run}")38 print(f"run={run}")
3939
4040
41def prepare_remote():
42 subprocess.run(
43 ["ssh", "-p", PORT, "-o", "BatchMode=yes", HOST, "python3 - prepare"],
44 input="NAMESPACE = " + repr(json.loads((REPO / "dashboard/src/namespace-transition.json").read_text())) + "\n"
45 + (REPO / "tools/namespace-transition.py").read_text(), text=True, check=True,
46 )
47
48
49def sync_manager(release):41def sync_manager(release):
50 source = REMOTE / "releases" / release / "tools"42 source = REMOTE / "releases" / release / "tools"
51 ssh(f"cp {source}/release.py {source}/data.py {source}/namespace-transition.py {REMOTE}/")43 ssh(f"cp {source}/release.py {source}/data.py {REMOTE}/")
52 ssh(f"cp {source}/../dashboard/src/namespace-transition.json {REMOTE}/namespace-transition.json")
5344
5445
55def export_revision(source, commit, paths, destination):46def export_revision(source, commit, paths, destination):
...@@ -207,7 +198,6 @@ def main():...@@ -207,7 +198,6 @@ def main():
207 values = args.file.read_text()198 values = args.file.read_text()
208 if not values.strip():199 if not values.strip():
209 raise ValueError("secret input is empty")200 raise ValueError("secret input is empty")
210 prepare_remote()
211 manager = f"python3 {REMOTE}/release.py"201 manager = f"python3 {REMOTE}/release.py"
212 if args.mode == "stage":202 if args.mode == "stage":
213 release = upload()203 release = upload()
tools/namespace-transition-test.py deleted-342
...@@ -1,342 +0,0 @@
1#!/usr/bin/env python3
2from importlib import import_module
3import io
4import json
5import os
6from pathlib import Path
7import shutil
8import subprocess
9import sys
10import tempfile
11from types import SimpleNamespace
12import unittest
13from unittest.mock import patch
14import xml.etree.ElementTree as ET
15
16import release
17import snowglobe
18
19
20transition = import_module("namespace-transition")
21
22
23class NamespaceTransition(unittest.TestCase):
24 def setUp(self):
25 temporary = tempfile.TemporaryDirectory()
26 self.addCleanup(temporary.cleanup)
27 self.root = Path(temporary.name).resolve()
28 self.directories = tuple((self.root / parent / "snowglobe", self.root / parent / transition.PREVIOUS)
29 for parent in ("opt", "state", "assets", "cache"))
30 self.addCleanup(patch.stopall)
31 patch.object(transition, "DIRECTORIES", self.directories).start()
32 registry = self.root / "nixos"
33 registry.mkdir()
34 patch.object(transition, "NIXOS_STATE", registry).start()
35 patch.object(transition.pwd, "getpwnam", side_effect=KeyError).start()
36 patch.object(transition.grp, "getgrnam", side_effect=KeyError).start()
37
38 def test_staging_aliases_share_existing_state_and_never_seed_another_registry(self):
39 for _, old in self.directories:
40 old.mkdir(parents=True)
41 new, old = self.directories[1]
42 (old / "identities.json").write_text('{"knife":3132}')
43 transition.prepare()
44 transition.prepare()
45 self.assertTrue(new.is_symlink())
46 self.assertEqual(new.resolve(), old)
47 (new / "identities.json").write_text('{"knife":3132,"dashboard":3133}')
48 self.assertEqual(json.loads((old / "identities.json").read_text()), {"knife": 3132, "dashboard": 3133})
49 self.assertTrue(all(new.resolve() == old for new, old in self.directories))
50
51 def test_staging_bootstrap_starts_the_installed_router_generation_without_restart(self):
52 state = self.root / "bootstrap"
53 state.mkdir()
54 for name in ("nomad", "router", "dashboard"):
55 (state / (name + ".token")).write_text("disposable-" + name)
56 original = transition.layout
57 source = self.root / "installed"
58 (source / "tools").mkdir(parents=True)
59 (source / "tools" / (transition.PREVIOUS + ".py")).touch()
60 with patch.object(snowglobe, "STATE", state), patch.object(snowglobe, "token"), patch.object(
61 snowglobe.os, "geteuid", return_value=0,
62 ), patch.object(Path, "is_symlink", return_value=True), patch.object(
63 transition, "layout", return_value=original(source),
64 ), patch.object(snowglobe, "command", return_value=subprocess.CompletedProcess([], 0)) as command:
65 snowglobe.bootstrap([])
66 units = [call.args for call in command.call_args_list if call.args[0] == "systemctl"]
67 self.assertEqual(units, [("systemctl", "start", transition.PREVIOUS + "-router.service")])
68
69 def test_split_state_is_rejected_before_any_alias_is_created(self):
70 self.directories[0][1].mkdir(parents=True)
71 new, old = self.directories[1]
72 new.mkdir(parents=True)
73 old.mkdir()
74 with self.assertRaisesRegex(ValueError, "independent control stores"):
75 transition.prepare()
76 self.assertFalse(self.directories[0][0].exists())
77
78 def test_promotion_preserves_whole_stores_and_release_links_then_is_idempotent(self):
79 revision = "1" * 16
80 for _, old in self.directories:
81 old.mkdir(parents=True)
82 (old / "durable").write_text("existing bytes")
83 (old / "durable").chmod(0o600)
84 new_root, old_root = self.directories[0]
85 (old_root / "releases" / revision).mkdir(parents=True)
86 for name in ("current", "main"):
87 (old_root / name).symlink_to(old_root / "releases" / revision)
88 before = [(old / "durable").stat().st_ino for _, old in self.directories]
89 with patch.object(transition.subprocess, "run", return_value=subprocess.CompletedProcess([], 0)) as run, patch.object(
90 transition, "migrate_policies",
91 ) as policies:
92 transition.promote(self.root)
93 policies.assert_called_once_with(self.root, self.directories[1][0])
94 self.assertEqual(run.call_count, 6)
95 transition.promote(self.root)
96 self.assertEqual(run.call_count, 6)
97 for index, (new, old) in enumerate(self.directories):
98 self.assertFalse(new.is_symlink())
99 self.assertTrue(old.is_symlink())
100 self.assertEqual((new / "durable").stat().st_ino, before[index])
101 self.assertEqual((new / "durable").stat().st_mode & 0o777, 0o600)
102 for name in ("current", "main"):
103 self.assertEqual(os.readlink(new_root / name), str(new_root / "releases" / revision))
104
105 def test_old_release_manifest_and_canonical_alias_validate_without_rewriting_the_tree(self):
106 new_root, old_root = self.directories[0]
107 revision = "a" * 16
108 source = old_root / "releases" / revision
109 (source / "tools").mkdir(parents=True)
110 (source / "tools" / (transition.PREVIOUS + ".py")).write_text("immutable")
111 manifest = source / ("." + transition.PREVIOUS + "-release.json")
112 manifest.write_text(json.dumps({"id": revision, "digest": release.tree_digest(source), "version": 2}))
113 original = manifest.read_bytes()
114 (old_root / "current").symlink_to(source)
115 transition.prepare()
116 with patch.object(release, "ROOT", new_root), patch.object(release, "RELEASES", new_root / "releases"):
117 self.assertEqual(release.current_release(), revision)
118 self.assertEqual(release.check_release(revision).resolve(), source)
119 self.assertEqual(manifest.read_bytes(), original)
120
121 def test_old_release_activation_uses_its_units_script_and_environment(self):
122 revision = "b" * 16
123 source = self.root / "release"
124 (source / "tools").mkdir(parents=True)
125 (source / "tools" / (transition.PREVIOUS + ".py")).touch()
126 (source / "nixos").mkdir()
127 (source / "nixos/dashboard.nix").touch()
128 transition.layout(source)["manifest"].write_text('{"version":2}')
129 observed = []
130 read_text = Path.read_text
131
132 def run(argv, **kwargs):
133 observed.append((argv, kwargs))
134 return subprocess.CompletedProcess(argv, 0, '"leader"')
135
136 with patch.dict(os.environ, {"SNOWGLOBE_POOL": "globe"}), patch.object(release, "ROOT", self.root), patch.object(
137 release, "STATE", self.root,
138 ), patch.object(release, "check_release", return_value=source), patch.object(
139 release, "current_release", return_value=None,
140 ), patch.object(release, "host_digest", return_value="different"), patch.object(
141 release, "host_configuration", return_value=transition.NAMESPACE["previousHost"],
142 ), patch.object(release, "jobs", return_value=set()), patch.object(
143 release.os, "uname", return_value=SimpleNamespace(nodename="snowglobe"),
144 ), patch.object(release.subprocess, "run", side_effect=run), patch.object(transition, "activate") as activate, patch.object(
145 Path, "read_text", autospec=True,
146 side_effect=lambda path: "snowglobe\n" if path == Path("/etc/hostname") else read_text(path),
147 ):
148 release.activate(revision, initial=True)
149 activate.assert_called_once_with(source)
150 scripts = [(argv, kwargs) for argv, kwargs in observed if argv[0] == "python3"]
151 self.assertEqual([argv[-1] for argv, _ in scripts], ["preflight", "pool", "deploy", "check"])
152 self.assertTrue(all(argv[1].endswith("/" + transition.PREVIOUS + ".py") for argv, _ in scripts))
153 self.assertTrue(all(kwargs["env"][transition.PREVIOUS.upper() + "_POOL"] == "globe" for _, kwargs in scripts))
154 self.assertIn(["systemctl", "restart", transition.PREVIOUS + "-router.service"], [argv for argv, _ in observed])
155
156 def test_policy_attachment_changes_after_new_policy_exists_without_changing_token_files(self):
157 state = self.root / "state"
158 state.mkdir()
159 for name in ("nomad", "router", "dashboard"):
160 (state / (name + ".token")).write_text("disposable-" + name)
161 responses = [io.BytesIO(json.dumps({"Name": transition.PREVIOUS + "-" + consumer,
162 "AccessorID": consumer, "Policies": [transition.PREVIOUS + "-" + consumer, "other"]}).encode())
163 for consumer in ("router", "dashboard")]
164 with patch.object(transition.urllib.request, "urlopen", side_effect=responses), patch.object(
165 transition.subprocess, "run", return_value=subprocess.CompletedProcess([], 0),
166 ) as run:
167 transition.migrate_policies(self.root, state)
168 commands = [call.args[0] for call in run.call_args_list]
169 for index, consumer in enumerate(("router", "dashboard")):
170 self.assertEqual(commands[index * 2][:5], ["nomad", "acl", "policy", "apply", "snowglobe-" + consumer])
171 self.assertIn("-policy=snowglobe-" + consumer, commands[index * 2 + 1])
172 self.assertIn("-policy=other", commands[index * 2 + 1])
173 self.assertFalse(any("disposable" in argument for argument in commands[index * 2 + 1]))
174 self.assertEqual((state / (consumer + ".token")).read_text(), "disposable-" + consumer)
175
176 def test_existing_vm_owner_profile_and_seed_still_resolve(self):
177 old = "https://paperclover.net/" + transition.PREVIOUS
178 root = ET.fromstring(f'<domain><metadata><vm xmlns="{old}"><owner>owner-id</owner><hardwareProfile>windows-q35-secure</hardwareProfile></vm></metadata><devices><disk><serial>{transition.PREVIOUS}-cloud-init</serial></disk></devices></domain>')
179 transition.normalize_vm(root)
180 namespace = "{https://paperclover.net/snowglobe}"
181 self.assertEqual(root.findtext(f"metadata/{namespace}vm/{namespace}owner"), "owner-id")
182 self.assertEqual(root.findtext(f"metadata/{namespace}vm/{namespace}hardwareProfile"), "windows-q35-secure")
183 self.assertEqual(root.findtext("devices/disk/serial"), "snowglobe-cloud-init")
184
185 def test_account_and_nixos_registries_round_trip_with_fixed_numeric_ownership(self):
186 old, new = transition.PREVIOUS + "-dashboard", "snowglobe-dashboard"
187 users = {old: SimpleNamespace(pw_uid=997, pw_gid=994)}
188 groups = {old: SimpleNamespace(gr_gid=994)}
189 registry = transition.NIXOS_STATE
190 (registry / "uid-map").write_text(json.dumps({old: 997, "other": 888}))
191 (registry / "gid-map").write_text(json.dumps({old: 994}))
192 for name in ("declarative-users", "declarative-groups"):
193 (registry / name).write_text("root " + old + "\n")
194
195 def lookup(values, name):
196 if name not in values:
197 raise KeyError(name)
198 return values[name]
199
200 calls = []
201
202 def command(argv, **kwargs):
203 calls.append(argv)
204 if argv[0] == "groupmod":
205 groups[argv[2]] = groups.pop(argv[3])
206 if argv[0] == "usermod":
207 users[argv[2]] = users.pop(argv[3])
208 return subprocess.CompletedProcess(argv, 0)
209
210 for _, directory in self.directories:
211 directory.mkdir(parents=True)
212 release_path = self.directories[0][1] / "releases" / ("c" * 16)
213 (release_path / "tools").mkdir(parents=True)
214 (release_path / "tools/snowglobe.py").touch()
215 transition.prepare()
216 canonical_release = self.directories[0][0] / "releases" / release_path.name
217 with patch.object(transition, "NIXOS_STATE", registry), patch.object(
218 transition.pwd, "getpwnam", side_effect=lambda name: lookup(users, name),
219 ), patch.object(transition.grp, "getgrnam", side_effect=lambda name: lookup(groups, name)), patch.object(
220 transition.subprocess, "run", side_effect=command,
221 ), patch.object(transition, "migrate_policies"):
222 transition.activate(canonical_release)
223 self.assertEqual(set(users), {new})
224 self.assertEqual((users[new].pw_uid, users[new].pw_gid, groups[new].gr_gid), (997, 994, 994))
225 self.assertEqual(json.loads((registry / "uid-map").read_text()), {new: 997, "other": 888})
226 self.assertEqual((registry / "declarative-users").read_text().split(), ["root", new])
227 previous_release = self.directories[0][0] / "releases" / ("d" * 16)
228 (previous_release / "tools").mkdir(parents=True)
229 (previous_release / "tools" / (transition.PREVIOUS + ".py")).touch()
230 transition.activate(previous_release)
231 self.assertEqual(set(users), {old})
232 self.assertEqual((users[old].pw_uid, users[old].pw_gid, groups[old].gr_gid), (997, 994, 994))
233 self.assertEqual(json.loads((registry / "uid-map").read_text()), {old: 997, "other": 888})
234 self.assertEqual((registry / "declarative-users").read_text().split(), ["root", old])
235 self.assertEqual(calls[0], ["systemctl", "stop", old])
236 self.assertEqual(calls[8], ["systemctl", "stop", new])
237
238 def test_policy_failure_after_directory_move_is_retried_without_moving_state_again(self):
239 for _, old in self.directories:
240 old.mkdir(parents=True)
241 with patch.object(transition.subprocess, "run", return_value=subprocess.CompletedProcess([], 0)) as run, patch.object(
242 transition, "migrate_policies", side_effect=[RuntimeError("interrupted ACL update"), None],
243 ) as policies:
244 with self.assertRaisesRegex(RuntimeError, "ACL update"):
245 transition.promote(self.root)
246 before = [new.stat().st_ino for new, _ in self.directories]
247 transition.promote(self.root)
248 self.assertEqual(policies.call_count, 2)
249 self.assertEqual(run.call_count, 6)
250 self.assertEqual(before, [new.stat().st_ino for new, _ in self.directories])
251
252 def test_only_legacy_transition_stops_the_retired_window_proxy(self):
253 with patch.object(transition.subprocess, "run", return_value=subprocess.CompletedProcess([], 0)) as run:
254 transition.stop_units(transition.PREVIOUS)
255 previous = [call.args[0] for call in run.call_args_list]
256 run.reset_mock()
257 transition.stop_units("snowglobe")
258 canonical = [call.args[0] for call in run.call_args_list]
259 self.assertIn(["systemctl", "stop", transition.PREVIOUS + "-vm-window-host-proxy"], previous)
260 self.assertFalse(any("vm-window-host-proxy" in command[-1] for command in canonical))
261 self.assertTrue(all(command[:2] == ["systemctl", "stop"] for command in previous + canonical))
262
263 def test_missing_reverse_alias_after_directory_move_is_recovered_from_old_releases(self):
264 new, old = self.directories[0]
265 source = new / "releases" / ("e" * 16) / "tools"
266 source.mkdir(parents=True)
267 (source / (transition.PREVIOUS + ".py")).touch()
268 transition.prepare()
269 self.assertTrue(old.is_symlink())
270 self.assertEqual(old.resolve(), new)
271
272 @unittest.skipUnless(sys.platform == "linux" and os.geteuid() == 0 and shutil.which("usermod") and shutil.which("groupmod"),
273 "requires Linux root and shadow tools; all account files stay inside a temporary prefix")
274 def test_real_shadow_tools_and_interrupted_registry_update_resume_with_only_fixture_accounts(self):
275 old, new = transition.PREVIOUS + "-dashboard", "snowglobe-dashboard"
276 prefix = self.root / "accounts"
277 etc = prefix / "etc"
278 etc.mkdir(parents=True)
279 (etc / "passwd").write_text(f"{old}:x:997:994:fixture:/var/empty:/bin/false\n")
280 (etc / "group").write_text(f"{old}:x:994:\n")
281 (etc / "shadow").write_text(f"{old}:!:1:0:99999:7:::\n")
282 (etc / "gshadow").write_text(f"{old}:!::\n")
283 for name in ("shadow", "gshadow"):
284 (etc / name).chmod(0o600)
285 (etc / "login.defs").write_text("")
286 registry = transition.NIXOS_STATE
287 for name, value in (("uid-map", 997), ("gid-map", 994)):
288 (registry / name).write_text(json.dumps({old: value}))
289 for name in ("declarative-users", "declarative-groups"):
290 (registry / name).write_text(old + "\n")
291 command = subprocess.run
292 replace = Path.replace
293 fail_login = True
294 fail_registry = True
295
296 def run(argv, **kwargs):
297 nonlocal fail_login
298 self.assertIn(argv[0], {"usermod", "groupmod"})
299 if argv[0] == "usermod" and fail_login:
300 fail_login = False
301 raise subprocess.CalledProcessError(1, argv)
302 return command([argv[0], "--prefix", str(prefix), *argv[1:]], **kwargs)
303
304 def atomic_replace(path, target):
305 nonlocal fail_registry
306 if Path(target) == registry / "gid-map" and fail_registry:
307 fail_registry = False
308 raise OSError("interrupted registry write")
309 return replace(path, target)
310
311 def user(name):
312 fields = (etc / "passwd").read_text().splitlines()[0].split(":")
313 if fields[0] != name:
314 raise KeyError(name)
315 return SimpleNamespace(pw_uid=int(fields[2]), pw_gid=int(fields[3]))
316
317 def group(name):
318 fields = (etc / "group").read_text().splitlines()[0].split(":")
319 if fields[0] != name:
320 raise KeyError(name)
321 return SimpleNamespace(gr_gid=int(fields[2]))
322
323 with patch.object(transition.pwd, "getpwnam", side_effect=user), patch.object(
324 transition.grp, "getgrnam", side_effect=group,
325 ), patch.object(transition.subprocess, "run", side_effect=run), patch.object(Path, "replace", atomic_replace):
326 with self.assertRaises(subprocess.CalledProcessError):
327 transition.rename_identity(transition.identity_change("snowglobe"))
328 self.assertEqual(group(new).gr_gid, 994)
329 self.assertEqual(user(old).pw_uid, 997)
330 with self.assertRaisesRegex(OSError, "registry write"):
331 transition.rename_identity(transition.identity_change("snowglobe"))
332 self.assertEqual(user(new).pw_uid, 997)
333 transition.rename_identity(transition.identity_change("snowglobe"))
334 self.assertIsNone(transition.identity_change("snowglobe"))
335 self.assertEqual(json.loads((registry / "gid-map").read_text()), {new: 994})
336 transition.rename_identity(transition.identity_change(transition.PREVIOUS))
337 self.assertEqual((user(old).pw_uid, user(old).pw_gid, group(old).gr_gid), (997, 994, 994))
338 self.assertIsNone(transition.identity_change(transition.PREVIOUS))
339
340
341if __name__ == "__main__":
342 unittest.main()
tools/namespace-transition.py deleted-245
...@@ -1,245 +0,0 @@
1#!/usr/bin/env python3
2"""Bridge the installed namespace and immutable releases during the rename."""
3import argparse
4import grp
5import json
6import os
7from pathlib import Path
8import pwd
9import subprocess
10import urllib.request
11
12
13NAMESPACE = globals().get("NAMESPACE") or json.loads(
14 (Path(__file__).with_suffix(".json") if Path(__file__).with_suffix(".json").exists()
15 else Path(__file__).resolve().parent.parent / "dashboard/src/namespace-transition.json").read_text()
16)
17PREVIOUS = NAMESPACE["previous"]
18NIXOS_STATE = Path("/var/lib/nixos")
19DIRECTORIES = tuple((Path(parent) / "snowglobe", Path(parent) / PREVIOUS)
20 for parent in ("/opt", "/var/lib", "/var/lib/caddy", "/var/cache"))
21
22
23def prepare():
24 for new, old in DIRECTORIES:
25 if new.exists() and old.exists() and new.resolve() != old.resolve():
26 raise ValueError(f"Two independent control stores exist: {new}, {old}")
27 new_root, _ = DIRECTORIES[0]
28 previous_releases = any((new_root / "releases").glob("*/tools/" + PREVIOUS + ".py"))
29 for new, old in DIRECTORIES:
30 if old.exists() and not new.exists() and not new.is_symlink():
31 new.symlink_to(old, target_is_directory=True)
32 elif previous_releases and new.exists() and not old.exists() and not old.is_symlink():
33 old.symlink_to(new, target_is_directory=True)
34
35
36def inherit_environment():
37 for name, value in list(os.environ.items()):
38 if name.startswith(PREVIOUS.upper() + "_"):
39 os.environ.setdefault("SNOWGLOBE_" + name.removeprefix(PREVIOUS.upper() + "_"), value)
40
41
42def environment(path, values=None):
43 values = dict(os.environ if values is None else values)
44 if layout(path)["prefix"] == PREVIOUS:
45 for name, value in list(values.items()):
46 if name.startswith("SNOWGLOBE_"):
47 values[PREVIOUS.upper() + "_" + name.removeprefix("SNOWGLOBE_")] = value
48 return values
49
50
51def layout(path):
52 prefix = "snowglobe" if (path / ".snowglobe-release.json").exists() or (path / "tools/snowglobe.py").exists() else PREVIOUS
53 return {"prefix": prefix, "script": path / f"tools/{prefix}.py", "manifest": path / f".{prefix}-release.json"}
54
55
56def host_configuration(hostname, available):
57 hostname = hostname.split(".", 1)[0]
58 candidates = ("snowglobe", NAMESPACE["previousHost"]) if hostname in {"snowglobe", NAMESPACE["previousHost"]} else (
59 "vm" if hostname in {"snowglobe-rehearsal", "clover-demo"} else hostname,
60 )
61 for name in candidates:
62 if name in available:
63 return name
64 raise ValueError(f"release has no NixOS configuration for {hostname}")
65
66
67def host_environment():
68 for prefix in ("snowglobe", PREVIOUS):
69 result = subprocess.run(["systemctl", "show", prefix + "-host", "--property=Environment", "--value"],
70 capture_output=True, text=True)
71 if result.stdout.strip():
72 return result.stdout
73 raise ValueError("the host service environment is unavailable")
74
75
76def stop_preview(identity):
77 for prefix in ("snowglobe", PREVIOUS):
78 subprocess.run(["systemctl", "stop", prefix + "-preview-" + identity], capture_output=True)
79
80
81def dashboard_container():
82 for name in ("snowglobe-dashboard", PREVIOUS + "-dashboard"):
83 if subprocess.run(["podman", "container", "exists", name], capture_output=True).returncode == 0:
84 return name
85 raise ValueError("the dashboard container is unavailable")
86
87
88def normalize_vm(root):
89 for element in root.iter():
90 if element.tag.startswith("{https://paperclover.net/" + PREVIOUS + "}"):
91 element.tag = element.tag.replace("{https://paperclover.net/" + PREVIOUS + "}", "{https://paperclover.net/snowglobe}", 1)
92 if element.tag == "serial" and element.text == PREVIOUS + "-cloud-init":
93 element.text = "snowglobe-cloud-init"
94 return root
95
96
97def migrate_policies(source, state, prefix="snowglobe"):
98 management = {**os.environ, "NOMAD_TOKEN": (state / "nomad.token").read_text().strip()}
99 for consumer in ("router", "dashboard"):
100 request = urllib.request.Request("http://127.0.0.1:4646/v1/acl/token/self", headers={
101 "X-Nomad-Token": (state / (consumer + ".token")).read_text().strip(),
102 })
103 with urllib.request.urlopen(request, timeout=10) as response:
104 token = json.load(response)
105 old, new = (PREVIOUS if prefix == "snowglobe" else "snowglobe") + "-" + consumer, prefix + "-" + consumer
106 subprocess.run(["nomad", "acl", "policy", "apply", new, str(source / "config/policies" / (consumer + ".hcl"))],
107 env=management, check=True, capture_output=True)
108 policies = [new if value == old else value for value in token.get("Policies", [])]
109 if old in token.get("Policies", []) or token.get("Name") == old:
110 subprocess.run(["nomad", "acl", "token", "update", "-name=" + new,
111 *("-policy=" + value for value in policies), token["AccessorID"]],
112 env=management, check=True, capture_output=True)
113
114
115def stop_units(prefix):
116 units = ("dashboard", "router", "log-shipper", "vm-screen", "host")
117 if prefix == PREVIOUS:
118 units += ("vm-window-host-proxy",)
119 for unit in units:
120 result = subprocess.run(["systemctl", "stop", prefix + "-" + unit], capture_output=True, text=True)
121 if result.returncode and "not loaded" not in result.stderr:
122 result.check_returncode()
123
124
125def identity_change(prefix):
126 old = (PREVIOUS if prefix == "snowglobe" else "snowglobe") + "-dashboard"
127 new = prefix + "-dashboard"
128 users, groups = {}, {}
129 for name in (old, new):
130 try:
131 users[name] = pwd.getpwnam(name)
132 except KeyError:
133 pass
134 try:
135 groups[name] = grp.getgrnam(name)
136 except KeyError:
137 pass
138 if len(users) > 1 or len(groups) > 1:
139 raise ValueError("Two dashboard identities exist; refusing to merge identities")
140 if any((user.pw_uid, user.pw_gid) != (997, 994) for user in users.values()) or any(
141 group.gr_gid != 994 for group in groups.values()
142 ):
143 raise ValueError("The dashboard account must retain UID 997 and GID 994")
144 registries = False
145 for filename, expected in (("uid-map", 997), ("gid-map", 994)):
146 path = NIXOS_STATE / filename
147 if path.exists():
148 values = json.loads(path.read_text())
149 if any(name in values and values[name] != expected for name in (old, new)):
150 raise ValueError("The NixOS identity registry disagrees with the dashboard account")
151 registries |= old in values
152 for filename in ("declarative-users", "declarative-groups"):
153 path = NIXOS_STATE / filename
154 registries |= path.exists() and old in path.read_text().split()
155 return (old, new) if old in users or old in groups or registries else None
156
157
158def rename_identity(change):
159 if change is None:
160 return
161 old, new = change
162 try:
163 grp.getgrnam(old)
164 except KeyError:
165 pass
166 else:
167 subprocess.run(["groupmod", "--new-name", new, old], check=True, capture_output=True)
168 try:
169 pwd.getpwnam(old)
170 except KeyError:
171 pass
172 else:
173 subprocess.run(["usermod", "--login", new, old], check=True, capture_output=True)
174 for filename in ("uid-map", "gid-map", "declarative-users", "declarative-groups"):
175 path = NIXOS_STATE / filename
176 if not path.exists():
177 continue
178 if filename.endswith("-map"):
179 values = json.loads(path.read_text())
180 if old not in values:
181 continue
182 values[new] = values.pop(old)
183 content = json.dumps(values) + "\n"
184 else:
185 names = path.read_text().split()
186 if old not in names:
187 continue
188 content = " ".join(new if name == old else name for name in names) + "\n"
189 pending = path.with_suffix(".namespace-pending")
190 pending.write_text(content)
191 pending.chmod(path.stat().st_mode & 0o777)
192 pending.replace(path)
193
194
195def promote(source):
196 prepare()
197 change = identity_change("snowglobe")
198 moving = any(old.exists() and not old.is_symlink() for _, old in DIRECTORIES)
199 if moving or change is not None:
200 stop_units(PREVIOUS)
201 rename_identity(change)
202 for new, old in DIRECTORIES:
203 if old.exists() and not old.is_symlink():
204 if new.is_symlink():
205 new.unlink()
206 old.rename(new)
207 old.symlink_to(new, target_is_directory=True)
208 new_root, old_root = DIRECTORIES[0]
209 for name in ("current", "main"):
210 link = new_root / name
211 if link.is_symlink():
212 target = Path(os.readlink(link))
213 if target.is_relative_to(old_root):
214 pending = link.with_suffix(".namespace-pending")
215 pending.unlink(missing_ok=True)
216 pending.symlink_to(new_root / target.relative_to(old_root))
217 pending.replace(link)
218 if old_root.exists():
219 migrate_policies(source, DIRECTORIES[1][0])
220
221
222def activate(path):
223 if layout(path)["prefix"] == "snowglobe":
224 promote(path)
225 else:
226 change = identity_change(PREVIOUS)
227 stop_units("snowglobe")
228 rename_identity(change)
229 migrate_policies(path, DIRECTORIES[1][0], PREVIOUS)
230
231
232def main():
233 parser = argparse.ArgumentParser()
234 parser.add_argument("mode", choices=("prepare", "promote"))
235 args = parser.parse_args()
236 if os.geteuid() != 0:
237 raise PermissionError("the namespace transition requires root")
238 if args.mode == "prepare":
239 prepare()
240 else:
241 promote(Path(__file__).resolve().parent.parent)
242
243
244if __name__ == "__main__":
245 main()
tools/oidc-provider.py+1-2
...@@ -1,7 +1,6 @@...@@ -1,7 +1,6 @@
1#!/usr/bin/env python31#!/usr/bin/env python3
2"""Provision a first-party OIDC client through the dashboard's host-only CLI."""2"""Provision a first-party OIDC client through the dashboard's host-only CLI."""
3import json3import json
4from importlib import import_module
5import subprocess4import subprocess
6import sys5import sys
76
...@@ -9,7 +8,7 @@ data = json.load(sys.stdin)...@@ -9,7 +8,7 @@ data = json.load(sys.stdin)
9if data["request"]["kind"] != "client":8if data["request"]["kind"] != "client":
10 raise ValueError("unsupported Snowglobe input")9 raise ValueError("unsupported Snowglobe input")
11result = subprocess.run(10result = subprocess.run(
12 ["podman", "exec", "-i", import_module("namespace-transition").dashboard_container(), "/bin/home-dashboard", "--oidc-client"],11 ["podman", "exec", "-i", "snowglobe-dashboard", "/bin/home-dashboard", "--oidc-client"],
13 input=json.dumps(data), text=True, check=True, capture_output=True,12 input=json.dumps(data), text=True, check=True, capture_output=True,
14)13)
15sys.stdout.write(result.stdout)14sys.stdout.write(result.stdout)
tools/owl-neuron/README.md+2-9
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1# Owl neuron experiment1# Owl neuron experiment
22
3Disposable experiment on Zenith (`root@10.0.0.1:22`), authorized on 2026-10-183Disposable experiment on Snow Globe (`root@10.0.0.1:22`), authorized on 2026-10-18
4with inference downtime. Source and run state live at4with inference downtime. Source and run state live at
5`/srv/staging/owl-neuron-20261018`; the existing model weights are mounted5`/srv/staging/owl-neuron-20261018`; the existing model weights are mounted
6read-only. The container has no network, host credentials, personal data, or6read-only. The container has no network, host credentials, personal data, or
...@@ -165,14 +165,7 @@ The production change ports the verified code to the current Snow Globe namespac...@@ -165,14 +165,7 @@ The production change ports the verified code to the current Snow Globe namespac
165without changing the overlay. Deployment history and its pre-switch backup are165without changing the overlay. Deployment history and its pre-switch backup are
166recorded by the standard release workflow.166recorded by the standard release workflow.
167167
168The checkout's `deploy.py stage` stopped before startup: Zenith uses the renamed168Use the current checkout's deployment tooling for staging and destruction.
169Snow Globe units and environment, while this checkout still targets Studio.
170The installed `/opt/studio/current/tools/snowglobe.py` staging engine is therefore
171loaded with `REPO` set to the candidate release's resolved path and `SERVICES`
172set to its `service` directory. It runs the normal stage command with
173`--pool globe --base-domain paperclover.net` and `STUDIO_LOCAL_AI=true`.
174Use that same installed engine and candidate paths for `destroy <stage-id>`;
175the checkout's destroy command targets the missing `studio-router.service`.
176Only after preview destruction and GPU release should production count 1 return.169Only after preview destruction and GPU release should production count 1 return.
177170
178The same launcher accepts `--program train.py -- <training arguments>` or171The same launcher accepts `--program train.py -- <training arguments>` or
tools/plausible.md+1-1
...@@ -78,7 +78,7 @@ native events. Cloud exports also exclude earlier third-party imports....@@ -78,7 +78,7 @@ native events. Cloud exports also exclude earlier third-party imports.
7878
79## Rehearsal evidence79## Rehearsal evidence
8080
81On 2026-10-19 UTC, release `12a2725e1a1372ce` passed on Zenith at81On 2026-10-19 UTC, release `12a2725e1a1372ce` passed on Snow Globe at
82`https://plausible-preview-3234cb91.paperclover.net`. Owner login, disabled82`https://plausible-preview-3234cb91.paperclover.net`. Owner login, disabled
83registration, private dashboards, the CSV upload, keyboard filters, mobile,83registration, private dashboards, the CSV upload, keyboard filters, mobile,
84both themes, and installation instructions were checked in a real browser.84both themes, and installation instructions were checked in a real browser.
tools/release-host-test.py+9-58
...@@ -10,8 +10,6 @@ from unittest.mock import patch...@@ -10,8 +10,6 @@ from unittest.mock import patch
1010
11import release11import release
1212
13PREVIOUS_HOST = release.transition.NAMESPACE["previousHost"]
14
1513
16class HostConfiguration(unittest.TestCase):14class HostConfiguration(unittest.TestCase):
17 def select(self, hostname, configurations):15 def select(self, hostname, configurations):
...@@ -25,11 +23,10 @@ class HostConfiguration(unittest.TestCase):...@@ -25,11 +23,10 @@ class HostConfiguration(unittest.TestCase):
25 )23 )
26 return result24 return result
2725
28 def test_rename_and_rollback(self):26 def test_canonical_hostname(self):
29 for hostname in (PREVIOUS_HOST, "snowglobe", "snowglobe.paperclover.net"):27 for hostname in ("snowglobe", "snowglobe.paperclover.net"):
30 with self.subTest(hostname=hostname):28 with self.subTest(hostname=hostname):
31 self.assertEqual(self.select(hostname, ["installer", "snowglobe", "vm"]), "snowglobe")29 self.assertEqual(self.select(hostname, ["installer", "snowglobe", "vm"]), "snowglobe")
32 self.assertEqual(self.select(hostname, ["installer", PREVIOUS_HOST, "vm"]), PREVIOUS_HOST)
3330
34 def test_rehearsal_stays_on_vm(self):31 def test_rehearsal_stays_on_vm(self):
35 self.assertEqual(self.select("snowglobe-rehearsal", ["installer", "snowglobe", "vm"]), "vm")32 self.assertEqual(self.select("snowglobe-rehearsal", ["installer", "snowglobe", "vm"]), "vm")
...@@ -42,55 +39,11 @@ class HostConfiguration(unittest.TestCase):...@@ -42,55 +39,11 @@ class HostConfiguration(unittest.TestCase):
4239
4340
44class ActivationEnvironment(unittest.TestCase):41class ActivationEnvironment(unittest.TestCase):
45 def test_flake_paths_are_resolved_again_after_the_release_store_moves(self):
46 with tempfile.TemporaryDirectory() as temporary:
47 root = Path(temporary).resolve()
48 previous = root / release.transition.PREVIOUS
49 canonical = root / "snowglobe"
50 source = previous / "releases" / ("a" * 16)
51 (source / "tools").mkdir(parents=True)
52 (source / "tools/snowglobe.py").touch()
53 (source / ".snowglobe-release.json").write_text('{"version":1}')
54 canonical.symlink_to(previous, target_is_directory=True)
55 logical_source = canonical / "releases" / source.name
56 observed = []
57 read_text = Path.read_text
58
59 def activate(path):
60 self.assertEqual(path, logical_source)
61 canonical.unlink()
62 previous.rename(canonical)
63 previous.symlink_to(canonical, target_is_directory=True)
64
65 def run(argv, **kwargs):
66 if argv[0] in {"nix", "nixos-rebuild"}:
67 observed.append(argv)
68 output = '["snowglobe"]' if argv[0] == "nix" else '"leader"'
69 return subprocess.CompletedProcess(argv, 0, output)
70
71 with patch.dict(os.environ), patch.object(release, "ROOT", canonical), patch.object(release, "STATE", root), patch.object(
72 release, "check_release", return_value=logical_source,
73 ), patch.object(release, "current_release", return_value=None), patch.object(
74 release, "host_digest", return_value="new",
75 ), patch.object(release, "jobs", return_value=set()), patch.object(
76 release.os, "uname", return_value=SimpleNamespace(nodename="snowglobe"),
77 ), patch.object(release.subprocess, "run", side_effect=run), patch.object(
78 release.transition, "activate", side_effect=activate,
79 ), patch.object(
80 Path, "read_text", autospec=True,
81 side_effect=lambda path: "snowglobe\n" if path == Path("/etc/hostname") else read_text(path),
82 ):
83 release.activate(source.name, initial=True)
84 self.assertIn(f"path:{source}#nixosConfigurations", observed[0])
85 self.assertEqual(observed[1], ["nixos-rebuild", "dry-build", "--flake", f"path:{source}#snowglobe"])
86 self.assertEqual(observed[2], ["nixos-rebuild", "switch", "--flake", f"path:{logical_source}#snowglobe"])
87
88 def test_host_switch_refreshes_inherited_name_and_preserves_overrides(self):42 def test_host_switch_refreshes_inherited_name_and_preserves_overrides(self):
89 for before, after, inherited, expected in (43 for before, after, inherited, expected in (
90 (PREVIOUS_HOST, "snowglobe", PREVIOUS_HOST, "snowglobe"),44 ("fixture", "snowglobe", "fixture", "snowglobe"),
91 ("snowglobe", PREVIOUS_HOST, "snowglobe", PREVIOUS_HOST),45 ("fixture", "snowglobe", None, "snowglobe"),
92 (PREVIOUS_HOST, "snowglobe", None, "snowglobe"),46 ("fixture", "snowglobe", "test-override", "test-override"),
93 (PREVIOUS_HOST, "snowglobe", "test-override", "test-override"),
94 ("snowglobe-rehearsal", "snowglobe-rehearsal", "snowglobe-rehearsal", "snowglobe-rehearsal"),47 ("snowglobe-rehearsal", "snowglobe-rehearsal", "snowglobe-rehearsal", "snowglobe-rehearsal"),
95 ):48 ):
96 with self.subTest(before=before, inherited=inherited), tempfile.TemporaryDirectory() as temporary:49 with self.subTest(before=before, inherited=inherited), tempfile.TemporaryDirectory() as temporary:
...@@ -98,9 +51,8 @@ class ActivationEnvironment(unittest.TestCase):...@@ -98,9 +51,8 @@ class ActivationEnvironment(unittest.TestCase):
98 source = root / "release"51 source = root / "release"
99 source.mkdir()52 source.mkdir()
100 (source / "tools").mkdir()53 (source / "tools").mkdir()
101 prefix = release.transition.PREVIOUS if after == PREVIOUS_HOST else "snowglobe"54 (source / "tools/snowglobe.py").touch()
102 (source / "tools" / (prefix + ".py")).touch()55 (source / ".snowglobe-release.json").write_text('{"version":1}')
103 (source / ("." + prefix + "-release.json")).write_text('{"version":1}')
104 hostname = before56 hostname = before
105 observed = []57 observed = []
106 calls = []58 calls = []
...@@ -112,8 +64,7 @@ class ActivationEnvironment(unittest.TestCase):...@@ -112,8 +64,7 @@ class ActivationEnvironment(unittest.TestCase):
112 if argv[:3] == ["hostnamectl", "set-hostname", "--transient"]:64 if argv[:3] == ["hostnamectl", "set-hostname", "--transient"]:
113 hostname = after65 hostname = after
114 if argv[-1] == "deploy":66 if argv[-1] == "deploy":
115 key = prefix.upper() + "_NODE_NAME"67 observed.append(kwargs["env"].get("SNOWGLOBE_NODE_NAME"))
116 observed.append(kwargs["env"].get(key))
117 return subprocess.CompletedProcess(argv, 0, '"leader"')68 return subprocess.CompletedProcess(argv, 0, '"leader"')
11869
119 with patch.dict(os.environ), patch.object(release, "ROOT", root), patch.object(70 with patch.dict(os.environ), patch.object(release, "ROOT", root), patch.object(
...@@ -129,7 +80,7 @@ class ActivationEnvironment(unittest.TestCase):...@@ -129,7 +80,7 @@ class ActivationEnvironment(unittest.TestCase):
129 os.environ.pop("SNOWGLOBE_NODE_NAME", None)80 os.environ.pop("SNOWGLOBE_NODE_NAME", None)
130 else:81 else:
131 os.environ["SNOWGLOBE_NODE_NAME"] = inherited82 os.environ["SNOWGLOBE_NODE_NAME"] = inherited
132 with patch.object(release.transition, "activate"), patch.object(83 with patch.object(
133 Path, "read_text", autospec=True,84 Path, "read_text", autospec=True,
134 side_effect=lambda path: after + "\n" if path == Path("/etc/hostname") else read_text(path),85 side_effect=lambda path: after + "\n" if path == Path("/etc/hostname") else read_text(path),
135 ):86 ):
tools/release.py+31-40
...@@ -4,7 +4,6 @@ from datetime import datetime, timezone...@@ -4,7 +4,6 @@ from datetime import datetime, timezone
4import fcntl4import fcntl
5import hashlib5import hashlib
6import json6import json
7from importlib import import_module
8import os7import os
9from pathlib import Path8from pathlib import Path
10import re9import re
...@@ -12,8 +11,6 @@ import subprocess...@@ -12,8 +11,6 @@ import subprocess
12import time11import time
1312
1413
15transition = import_module("namespace-transition")
16
17ROOT = Path("/opt/snowglobe")14ROOT = Path("/opt/snowglobe")
18RELEASES = ROOT / "releases"15RELEASES = ROOT / "releases"
19STATE = Path("/var/lib/snowglobe")16STATE = Path("/var/lib/snowglobe")
...@@ -63,27 +60,25 @@ def host_digest(root):...@@ -63,27 +60,25 @@ def host_digest(root):
63 digest = hashlib.sha256()60 digest = hashlib.sha256()
64 paths = sorted(path for path, relative in files(root)61 paths = sorted(path for path, relative in files(root)
65 if relative.parts[0] in {"nixos", "dashboard", "config", "service"}62 if relative.parts[0] in {"nixos", "dashboard", "config", "service"}
66 or str(relative) in {"flake.nix", "flake.lock", "tools/router.py", "tools/dashboard-host.py", "tools/shale-access.py", "tools/shale-labels.py", "tools/dashboard-run.py", "tools/release.py", "tools/namespace-transition.py", "tools/vms.py", "tools/mac-vms.py", "tools/vm-screen.py", "guest/protocol.json"})63 or str(relative) in {"flake.nix", "flake.lock", "tools/router.py", "tools/dashboard-host.py", "tools/shale-access.py", "tools/shale-labels.py", "tools/dashboard-run.py", "tools/release.py", "tools/vms.py", "tools/mac-vms.py", "tools/vm-screen.py", "guest/protocol.json"})
67 for path in paths:64 for path in paths:
68 digest.update(str(path.relative_to(root)).encode())65 digest.update(str(path.relative_to(root)).encode())
69 _hash_contents(digest, path)66 _hash_contents(digest, path)
70 return digest.hexdigest()67 return digest.hexdigest()
7168
7269
73def check_release(release, legacy=False):70def check_release(release):
74 if not RELEASE_ID.fullmatch(release):71 if not RELEASE_ID.fullmatch(release):
75 raise ValueError("invalid release ID")72 raise ValueError("invalid release ID")
76 path = RELEASES / release73 path = RELEASES / release
77 if not path.is_dir():74 if not path.is_dir():
78 raise ValueError(f"release is missing: {release}")75 raise ValueError(f"release is missing: {release}")
79 manifest = transition.layout(path)["manifest"]76 manifest = path / ".snowglobe-release.json"
80 if not manifest.exists():77 if not manifest.exists():
81 if not legacy:78 raise ValueError(f"release has no manifest: {release}")
82 raise ValueError(f"release has no manifest: {release}")79 details = json.loads(manifest.read_text())
83 else:80 if details.get("id") != release or details.get("digest") != tree_digest(path) or details.get("version", 1) not in (1, 2):
84 details = json.loads(manifest.read_text())81 raise ValueError(f"release contents changed: {release}")
85 if details.get("id") != release or details.get("digest") != tree_digest(path) or details.get("version", 1) not in (1, 2):
86 raise ValueError(f"release contents changed: {release}")
87 return path82 return path
8883
8984
...@@ -103,7 +98,7 @@ def main_release(version=None):...@@ -103,7 +98,7 @@ def main_release(version=None):
103 return None98 return None
104 if not RELEASE_ID.fullmatch(version):99 if not RELEASE_ID.fullmatch(version):
105 raise ValueError("invalid release ID")100 raise ValueError("invalid release ID")
106 details = json.loads(transition.layout(RELEASES / version)["manifest"].read_text())101 details = json.loads((RELEASES / version / ".snowglobe-release.json").read_text())
107 revision = details.get("main")102 revision = details.get("main")
108 if (not isinstance(revision, dict) or not isinstance(revision.get("commit"), str)103 if (not isinstance(revision, dict) or not isinstance(revision.get("commit"), str)
109 or not re.fullmatch(r"[0-9a-f]{40}", revision["commit"])104 or not re.fullmatch(r"[0-9a-f]{40}", revision["commit"])
...@@ -124,8 +119,8 @@ def save_history(entries):...@@ -124,8 +119,8 @@ def save_history(entries):
124119
125def jobs(path):120def jobs(path):
126 rendered = subprocess.run(121 rendered = subprocess.run(
127 ["python3", str(transition.layout(path)["script"]), "render"],122 ["python3", str(path / "tools/snowglobe.py"), "render"],
128 check=True, capture_output=True, text=True, env=transition.environment(path),123 check=True, capture_output=True, text=True,
129 ).stdout124 ).stdout
130 result = set(re.findall(r'^job "([a-z][a-z0-9-]*)" \{$', rendered, re.MULTILINE))125 result = set(re.findall(r'^job "([a-z][a-z0-9-]*)" \{$', rendered, re.MULTILINE))
131 if not result:126 if not result:
...@@ -139,15 +134,16 @@ def host_configuration(path):...@@ -139,15 +134,16 @@ def host_configuration(path):
139 ["nix", "--extra-experimental-features", "nix-command flakes", "eval", "--json", f"path:{path.resolve()}#nixosConfigurations", "--apply", "builtins.attrNames"],134 ["nix", "--extra-experimental-features", "nix-command flakes", "eval", "--json", f"path:{path.resolve()}#nixosConfigurations", "--apply", "builtins.attrNames"],
140 check=True, capture_output=True, text=True,135 check=True, capture_output=True, text=True,
141 ).stdout)136 ).stdout)
142 return transition.host_configuration(hostname, available)137 name = "vm" if hostname == "snowglobe-rehearsal" else hostname
138 if name not in available:
139 raise ValueError(f"release has no NixOS configuration for {hostname}")
140 return name
143141
144142
145def activate(release, legacy=False, initial=False):143def activate(release, initial=False):
146 path = check_release(release, legacy)144 path = check_release(release)
147 layout = transition.layout(path)145 script = path / "tools/snowglobe.py"
148 script = layout["script"]146 environment = dict(os.environ)
149 environment = transition.environment(path)
150 prefix = layout["prefix"]
151 managed = STATE / "managed-jobs.json"147 managed = STATE / "managed-jobs.json"
152 current = current_release()148 current = current_release()
153 previous = set(json.loads(managed.read_text())) if managed.exists() else (149 previous = set(json.loads(managed.read_text())) if managed.exists() else (
...@@ -175,14 +171,13 @@ def activate(release, legacy=False, initial=False):...@@ -175,14 +171,13 @@ def activate(release, legacy=False, initial=False):
175 if current is None:171 if current is None:
176 (ROOT / "current").symlink_to(path)172 (ROOT / "current").symlink_to(path)
177 hostname = os.uname().nodename.split(".", 1)[0]173 hostname = os.uname().nodename.split(".", 1)[0]
178 transition.activate(path)
179 subprocess.run(["nixos-rebuild", "switch", "--flake", f"path:{path.resolve()}#{configuration}"], check=True)174 subprocess.run(["nixos-rebuild", "switch", "--flake", f"path:{path.resolve()}#{configuration}"], check=True)
180 configured_hostname = Path("/etc/hostname").read_text().strip()175 configured_hostname = Path("/etc/hostname").read_text().strip()
181 if os.uname().nodename != configured_hostname:176 if os.uname().nodename != configured_hostname:
182 subprocess.run(["hostnamectl", "set-hostname", "--transient", configured_hostname], check=True)177 subprocess.run(["hostnamectl", "set-hostname", "--transient", configured_hostname], check=True)
183 if os.environ.get("SNOWGLOBE_NODE_NAME", hostname) == hostname:178 if os.environ.get("SNOWGLOBE_NODE_NAME", hostname) == hostname:
184 os.environ["SNOWGLOBE_NODE_NAME"] = os.uname().nodename.split(".", 1)[0]179 os.environ["SNOWGLOBE_NODE_NAME"] = os.uname().nodename.split(".", 1)[0]
185 environment = transition.environment(path)180 environment = dict(os.environ)
186 next_link = ROOT / ("next-" + release)181 next_link = ROOT / ("next-" + release)
187 next_link.unlink(missing_ok=True)182 next_link.unlink(missing_ok=True)
188 next_link.symlink_to(path)183 next_link.symlink_to(path)
...@@ -199,10 +194,10 @@ def activate(release, legacy=False, initial=False):...@@ -199,10 +194,10 @@ def activate(release, legacy=False, initial=False):
199 time.sleep(2)194 time.sleep(2)
200 else:195 else:
201 raise RuntimeError("Nomad API did not become ready")196 raise RuntimeError("Nomad API did not become ready")
202 subprocess.run(["systemctl", "restart", prefix + "-router.service"], check=True)197 subprocess.run(["systemctl", "restart", "snowglobe-router.service"], check=True)
203 if (path / "nixos/dashboard.nix").exists():198 if (path / "nixos/dashboard.nix").exists():
204 subprocess.run(["systemctl", "start", prefix + "-dashboard.service"], check=True)199 subprocess.run(["systemctl", "start", "snowglobe-dashboard.service"], check=True)
205 subprocess.run(["systemctl", "is-active", "--quiet", prefix + "-dashboard.service"], check=True)200 subprocess.run(["systemctl", "is-active", "--quiet", "snowglobe-dashboard.service"], check=True)
206 subprocess.run(["python3", str(script), "pool"], check=True, env=environment)201 subprocess.run(["python3", str(script), "pool"], check=True, env=environment)
207 subprocess.run(["python3", str(script), "deploy"], check=True, env=environment)202 subprocess.run(["python3", str(script), "deploy"], check=True, env=environment)
208 desired = jobs(path)203 desired = jobs(path)
...@@ -215,9 +210,9 @@ def activate(release, legacy=False, initial=False):...@@ -215,9 +210,9 @@ def activate(release, legacy=False, initial=False):
215 pending.write_text(json.dumps(sorted(desired)) + "\n")210 pending.write_text(json.dumps(sorted(desired)) + "\n")
216 pending.replace(managed)211 pending.replace(managed)
217 if (path / "tools/log-shipper.py").exists():212 if (path / "tools/log-shipper.py").exists():
218 subprocess.run(["systemctl", "restart", prefix + "-log-shipper.service"], check=True)213 subprocess.run(["systemctl", "restart", "snowglobe-log-shipper.service"], check=True)
219 manifest = transition.layout(path)["manifest"]214 manifest = path / ".snowglobe-release.json"
220 if not legacy and json.loads(manifest.read_text()).get("version", 1) >= 2:215 if json.loads(manifest.read_text()).get("version", 1) >= 2:
221 subprocess.run(["python3", str(script), "check"], check=True, env=environment)216 subprocess.run(["python3", str(script), "check"], check=True, env=environment)
222 return backup217 return backup
223218
...@@ -227,16 +222,13 @@ def main():...@@ -227,16 +222,13 @@ def main():
227 parser.add_argument("mode", choices=["publish", "deploy", "rollback", "history", "bootstrap", "verify", "stage-destroy"])222 parser.add_argument("mode", choices=["publish", "deploy", "rollback", "history", "bootstrap", "verify", "stage-destroy"])
228 parser.add_argument("target", nargs="?")223 parser.add_argument("target", nargs="?")
229 args = parser.parse_args()224 args = parser.parse_args()
230 transition.prepare()
231 transition.inherit_environment()
232 STATE.mkdir(parents=True, exist_ok=True)225 STATE.mkdir(parents=True, exist_ok=True)
233 if args.mode == "stage-destroy":226 if args.mode == "stage-destroy":
234 if not args.target or not STAGE_ID.fullmatch(args.target):227 if not args.target or not STAGE_ID.fullmatch(args.target):
235 parser.error("stage-destroy requires a stage ID")228 parser.error("stage-destroy requires a stage ID")
236 saved = json.loads((STATE / "stages" / (args.target + ".json")).read_text())229 saved = json.loads((STATE / "stages" / (args.target + ".json")).read_text())
237 path = check_release(saved["release"])230 path = check_release(saved["release"])
238 subprocess.run(["python3", str(transition.layout(path)["script"]), "destroy", args.target],231 subprocess.run(["python3", str(path / "tools/snowglobe.py"), "destroy", args.target], check=True)
239 check=True, env=transition.environment(path))
240 return232 return
241 if args.mode == "verify":233 if args.mode == "verify":
242 if not args.target:234 if not args.target:
...@@ -271,7 +263,7 @@ def main():...@@ -271,7 +263,7 @@ def main():
271 entries = history()263 entries = history()
272 current = current_release()264 current = current_release()
273 if current and not entries and args.mode != "bootstrap":265 if current and not entries and args.mode != "bootstrap":
274 entries.append({"release": current, "source": "previous", "time": int(time.time()), "legacy": not transition.layout(RELEASES / current)["manifest"].exists()})266 entries.append({"release": current, "source": "previous", "time": int(time.time())})
275 save_history(entries)267 save_history(entries)
276 if args.mode == "deploy":268 if args.mode == "deploy":
277 candidate = main_release()269 candidate = main_release()
...@@ -279,11 +271,10 @@ def main():...@@ -279,11 +271,10 @@ def main():
279 raise ValueError("main changed or is unavailable. Publish main and retry deployment.")271 raise ValueError("main changed or is unavailable. Publish main and retry deployment.")
280 release = candidate["release"]272 release = candidate["release"]
281 source = "main"273 source = "main"
282 legacy = False
283 elif args.mode == "bootstrap":274 elif args.mode == "bootstrap":
284 if not args.target or not RELEASE_ID.fullmatch(args.target) or entries:275 if not args.target or not RELEASE_ID.fullmatch(args.target) or entries:
285 parser.error("bootstrap requires a release ID and no successful deployment")276 parser.error("bootstrap requires a release ID and no successful deployment")
286 release, source, legacy = args.target, "bootstrap", False277 release, source = args.target, "bootstrap"
287 main_release(release)278 main_release(release)
288 else:279 else:
289 if args.target:280 if args.target:
...@@ -294,12 +285,12 @@ def main():...@@ -294,12 +285,12 @@ def main():
294 match = next((item for item in reversed(entries) if item["release"] != current), None)285 match = next((item for item in reversed(entries) if item["release"] != current), None)
295 if not match:286 if not match:
296 parser.error("no earlier production release")287 parser.error("no earlier production release")
297 release, source, legacy = match["release"], "rollback", match.get("legacy", False)288 release, source = match["release"], "rollback"
298 if release == current and entries and entries[-1]["release"] == current:289 if release == current and entries and entries[-1]["release"] == current:
299 print(f"already running {release}")290 print(f"already running {release}")
300 return291 return
301 backup = activate(release, legacy, args.mode == "bootstrap")292 backup = activate(release, args.mode == "bootstrap")
302 entries.append({"release": release, "source": source, "time": int(time.time()), "legacy": legacy, "backup": backup})293 entries.append({"release": release, "source": source, "time": int(time.time()), "backup": backup})
303 save_history(entries)294 save_history(entries)
304 print(f"production={release} previous={current or ''}")295 print(f"production={release} previous={current or ''}")
305296
tools/snowglobe-hardware.md+26
...@@ -103,3 +103,29 @@ Before destructive storage or OS work, verify key recovery and application/...@@ -103,3 +103,29 @@ Before destructive storage or OS work, verify key recovery and application/
103database restores from at least two restricted copies stored separately off103database restores from at least two restricted copies stored separately off
104this computer. Preserve the existing encrypted roots, pool host ID, numeric104this computer. Preserve the existing encrypted roots, pool host ID, numeric
105owners, SSH trust, and retained recovery sources through a rebuild.105owners, SSH trust, and retained recovery sources through a rebuild.
106
107## Namespace migration, 2026-10-21
108
109Production's kernel hostname, static hostname, and Nomad node name are
110`snowglobe`. Clover manages the Tailscale machine name separately.
111
112The final telemetry cutover validated 6,949,996 custom metric samples across
113458 series and all 308,283 stored spans, including 4,953,978 renamed samples
114and 3,861 renamed spans. Metrics retained every series and timestamp within
115the store's numeric precision; two existing conflicting timestamps retained
116one of their original values. Traces retained their timestamps, stream labels,
117and every field, verified with a normalized all-field digest. Other metrics
118and logs remained intact. The original metrics and traces directories are
119preserved in `/srv/prod/victoria/archives/namespace-20261021`. Root-only
120migration reports and the executed script live under
121`/var/lib/snowglobe/migrations/namespace-final-20261021`.
122
123The 265 pre-rename releases are preserved under
124`/opt/snowglobe/archives/releases`; they are archives, excluded from executable
125rollback history. `/opt/snowglobe/archives/namespace-20261021` preserves the
126complete prior deployment history, retired manager compatibility files and
127ACL policy definitions, and the former `/etc/nixos` source tree. The installed
128configuration now follows `/opt/snowglobe/current`. Old path aliases, stale
129runtime sockets, the unused preview host unit, and unreferenced old ACL
130policies have been removed. Numeric identities and active service data paths
131were preserved.
tools/snowglobe.py+1-5
...@@ -4,7 +4,6 @@ from contextlib import nullcontext...@@ -4,7 +4,6 @@ from contextlib import nullcontext
4import fcntl4import fcntl
5import hashlib5import hashlib
6import json6import json
7from importlib import import_module
8import os7import os
9from pathlib import Path8from pathlib import Path
10import re9import re
...@@ -18,9 +17,6 @@ import time...@@ -18,9 +17,6 @@ import time
18from data import cloned_postgres, dataset_for17from data import cloned_postgres, dataset_for
1918
2019
21transition = import_module("namespace-transition")
22transition.inherit_environment()
23
24REPO = Path(__file__).resolve().parent.parent20REPO = Path(__file__).resolve().parent.parent
25SERVICES = REPO / "service"21SERVICES = REPO / "service"
26STATE = Path("/var/lib/snowglobe")22STATE = Path("/var/lib/snowglobe")
...@@ -810,7 +806,7 @@ def bootstrap(all_data):...@@ -810,7 +806,7 @@ def bootstrap(all_data):
810 Path(path).unlink()806 Path(path).unlink()
811 current = Path("/opt/snowglobe/current")807 current = Path("/opt/snowglobe/current")
812 if current.is_symlink():808 if current.is_symlink():
813 command("systemctl", "start", transition.layout(current)["prefix"] + "-router.service")809 command("systemctl", "start", "snowglobe-router.service")
814810
815811
816def destroy_stage(stage, metadata, definitions):812def destroy_stage(stage, metadata, definitions):
tools/vms.py+10-11
...@@ -19,7 +19,6 @@ DISKS = Path("/srv/vm")...@@ -19,7 +19,6 @@ DISKS = Path("/srv/vm")
19IMAGES = Path(os.environ.get("SNOWGLOBE_VM_IMAGES_ROOT", "/srv/clover/Media/vm"))19IMAGES = Path(os.environ.get("SNOWGLOBE_VM_IMAGES_ROOT", "/srv/clover/Media/vm"))
20PRESETS = Path(os.environ.get("SNOWGLOBE_VM_PRESETS_ROOT", str(IMAGES / "Presets")))20PRESETS = Path(os.environ.get("SNOWGLOBE_VM_PRESETS_ROOT", str(IMAGES / "Presets")))
21UPLOADS = Path(os.environ.get("SNOWGLOBE_VM_UPLOADS_ROOT", str(IMAGES / "Install Disks")))21UPLOADS = Path(os.environ.get("SNOWGLOBE_VM_UPLOADS_ROOT", str(IMAGES / "Install Disks")))
22transition = import_module("namespace-transition")
23mac_vms = import_module("mac-vms")22mac_vms = import_module("mac-vms")
24NS = "{https://paperclover.net/snowglobe}"23NS = "{https://paperclover.net/snowglobe}"
25NAME = re.compile(r"[a-z0-9][a-z0-9-]{0,62}\Z")24NAME = re.compile(r"[a-z0-9][a-z0-9-]{0,62}\Z")
...@@ -245,7 +244,7 @@ def domains():...@@ -245,7 +244,7 @@ def domains():
245 for name in virsh("list", "--all", "--name").splitlines():244 for name in virsh("list", "--all", "--name").splitlines():
246 if not name:245 if not name:
247 continue246 continue
248 root = transition.normalize_vm(ET.fromstring(virsh("dumpxml", name)))247 root = ET.fromstring(virsh("dumpxml", name))
249 state_line = virsh("domstate", name, "--reason").splitlines()[0].lower()248 state_line = virsh("domstate", name, "--reason").splitlines()[0].lower()
250 state = next((value for value in ("running", "blocked", "paused", "shutdown", "crashed", "pmsuspended") if state_line.startswith(value)), "shutoff")249 state = next((value for value in ("running", "blocked", "paused", "shutdown", "crashed", "pmsuspended") if state_line.startswith(value)), "shutoff")
251 reason = state_line.split("(", 1)[1].rstrip(")") if state in {"paused", "crashed"} and "(" in state_line else None250 reason = state_line.split("(", 1)[1].rstrip(")") if state in {"paused", "crashed"} and "(" in state_line else None
...@@ -468,7 +467,7 @@ def managed_directory(path):...@@ -468,7 +467,7 @@ def managed_directory(path):
468467
469def change_media(spec):468def change_media(spec):
470 name = spec["name"]469 name = spec["name"]
471 root = transition.normalize_vm(ET.fromstring(virsh("dumpxml", name, "--inactive")))470 root = ET.fromstring(virsh("dumpxml", name, "--inactive"))
472 drives = root.findall("./devices/disk[@device='cdrom']")471 drives = root.findall("./devices/disk[@device='cdrom']")
473 source = resolve_image(spec["image"]) if spec["image"] else None472 source = resolve_image(spec["image"]) if spec["image"] else None
474 details = profile(inferred_profile(root))473 details = profile(inferred_profile(root))
...@@ -523,7 +522,7 @@ def save_preset(spec):...@@ -523,7 +522,7 @@ def save_preset(spec):
523 name = spec["name"]522 name = spec["name"]
524 if virsh("domstate", name).strip() != "shut off":523 if virsh("domstate", name).strip() != "shut off":
525 raise ValueError("Shut down this VM before saving a preset.")524 raise ValueError("Shut down this VM before saving a preset.")
526 root = transition.normalize_vm(ET.fromstring(virsh("dumpxml", name, "--inactive")))525 root = ET.fromstring(virsh("dumpxml", name, "--inactive"))
527 if root.findtext(f"metadata/{NS}vm/{NS}platform") == "macos":526 if root.findtext(f"metadata/{NS}vm/{NS}platform") == "macos":
528 raise ValueError("Use a prepared OS X preset from the OS library.")527 raise ValueError("Use a prepared OS X preset from the OS library.")
529 if root.findtext(f"metadata/{NS}vm/{NS}setup") in {"windows-v2", "windows-v3", "windows-v4"} and spec.get("setup") not in {"windows-v3", "windows-v4"}:528 if root.findtext(f"metadata/{NS}vm/{NS}setup") in {"windows-v2", "windows-v3", "windows-v4"} and spec.get("setup") not in {"windows-v3", "windows-v4"}:
...@@ -587,7 +586,7 @@ def save_preset(spec):...@@ -587,7 +586,7 @@ def save_preset(spec):
587586
588587
589def console_target(name):588def console_target(name):
590 root = transition.normalize_vm(ET.fromstring(virsh("dumpxml", name)))589 root = ET.fromstring(virsh("dumpxml", name))
591 graphics = root.find("./devices/graphics[@type='vnc']")590 graphics = root.find("./devices/graphics[@type='vnc']")
592 if virsh("domstate", name).strip() not in {"running", "paused", "blocked"} or graphics is None:591 if virsh("domstate", name).strip() not in {"running", "paused", "blocked"} or graphics is None:
593 raise ValueError("Start this VM before opening its screen.")592 raise ValueError("Start this VM before opening its screen.")
...@@ -958,7 +957,7 @@ def main():...@@ -958,7 +957,7 @@ def main():
958 fields = Path(f"/proc/{pid}/stat").read_text().rsplit(") ", 1)[1].split()957 fields = Path(f"/proc/{pid}/stat").read_text().rsplit(") ", 1)[1].split()
959 resident = int(Path(f"/proc/{pid}/statm").read_text().split()[1]) * os.sysconf("SC_PAGE_SIZE")958 resident = int(Path(f"/proc/{pid}/statm").read_text().split()[1]) * os.sysconf("SC_PAGE_SIZE")
960 result[name] = {"cpu": (int(fields[11]) + int(fields[12])) / os.sysconf("SC_CLK_TCK"), "memory": resident,959 result[name] = {"cpu": (int(fields[11]) + int(fields[12])) / os.sysconf("SC_CLK_TCK"), "memory": resident,
961 "vcpus": int(transition.normalize_vm(ET.fromstring(virsh("dumpxml", name))).findtext("vcpu", "1"))}960 "vcpus": int(ET.fromstring(virsh("dumpxml", name)).findtext("vcpu", "1"))}
962 return result961 return result
963 if action == "library":962 if action == "library":
964 return library()963 return library()
...@@ -967,7 +966,7 @@ def main():...@@ -967,7 +966,7 @@ def main():
967 if action == "console":966 if action == "console":
968 return console_target(payload["name"])967 return console_target(payload["name"])
969 if action == "guest":968 if action == "guest":
970 root = transition.normalize_vm(ET.fromstring(virsh("dumpxml", payload["name"])))969 root = ET.fromstring(virsh("dumpxml", payload["name"]))
971 source = root.find(f"./devices/channel[@type='unix']/target[@name='{GUEST_CHANNEL}']/../source")970 source = root.find(f"./devices/channel[@type='unix']/target[@name='{GUEST_CHANNEL}']/../source")
972 expected = f"/run/libvirt/qemu/channel/{root.get('id')}-{payload['name'][:20]}/{GUEST_CHANNEL}"971 expected = f"/run/libvirt/qemu/channel/{root.get('id')}-{payload['name'][:20]}/{GUEST_CHANNEL}"
973 if virsh("domstate", payload["name"]).strip() != "running" or source is None or source.get("mode") != "bind" or source.get("path") != expected:972 if virsh("domstate", payload["name"]).strip() != "running" or source is None or source.get("mode") != "bind" or source.get("path") != expected:
...@@ -976,7 +975,7 @@ def main():...@@ -976,7 +975,7 @@ def main():
976 if action == "serial":975 if action == "serial":
977 if virsh("domstate", payload["name"]).strip() not in {"running", "blocked"}:976 if virsh("domstate", payload["name"]).strip() not in {"running", "blocked"}:
978 raise ValueError("Start this VM before opening its console.")977 raise ValueError("Start this VM before opening its console.")
979 root = transition.normalize_vm(ET.fromstring(virsh("dumpxml", payload["name"])))978 root = ET.fromstring(virsh("dumpxml", payload["name"]))
980 console = root.find("./devices/console[@type='pty']")979 console = root.find("./devices/console[@type='pty']")
981 source = console.find("source") if console is not None else None980 source = console.find("source") if console is not None else None
982 target = console.find("target") if console is not None else None981 target = console.find("target") if console is not None else None
...@@ -985,7 +984,7 @@ def main():...@@ -985,7 +984,7 @@ def main():
985 raise ValueError("This VM has no serial console. Add one in its hardware settings.")984 raise ValueError("This VM has no serial console. Add one in its hardware settings.")
986 return {"path": path}985 return {"path": path}
987 if action == "owner":986 if action == "owner":
988 return {"owner": transition.normalize_vm(ET.fromstring(virsh("dumpxml", payload["name"]))).findtext(f"metadata/{NS}vm/{NS}owner")}987 return {"owner": ET.fromstring(virsh("dumpxml", payload["name"])).findtext(f"metadata/{NS}vm/{NS}owner")}
989 if action == "access":988 if action == "access":
990 try:989 try:
991 with os.fdopen(open_regular(DISKS / payload["name"] / "access.json")) as incoming:990 with os.fdopen(open_regular(DISKS / payload["name"] / "access.json")) as incoming:
...@@ -1002,7 +1001,7 @@ def main():...@@ -1002,7 +1001,7 @@ def main():
1002 name = payload["name"]1001 name = payload["name"]
1003 ensure_name(name)1002 ensure_name(name)
1004 if payload["action"] == "start":1003 if payload["action"] == "start":
1005 root = transition.normalize_vm(ET.fromstring(virsh("dumpxml", name, "--inactive")))1004 root = ET.fromstring(virsh("dumpxml", name, "--inactive"))
1006 if root.find("./devices/interface/source[@network='default']") is not None:1005 if root.find("./devices/interface/source[@network='default']") is not None:
1007 ensure_network()1006 ensure_network()
1008 virsh({"start": "start", "shutdown": "shutdown", "reboot": "reboot", "destroy": "destroy", "resume": "resume", "suspend": "suspend"}[payload["action"]], name)1007 virsh({"start": "start", "shutdown": "shutdown", "reboot": "reboot", "destroy": "destroy", "resume": "resume", "suspend": "suspend"}[payload["action"]], name)
...@@ -1023,7 +1022,7 @@ def main():...@@ -1023,7 +1022,7 @@ def main():
1023 raise ValueError("VM does not exist")1022 raise ValueError("VM does not exist")
1024 if virsh("domstate", name).strip() != "shut off":1023 if virsh("domstate", name).strip() != "shut off":
1025 virsh("destroy", name)1024 virsh("destroy", name)
1026 root = transition.normalize_vm(ET.fromstring(virsh("dumpxml", name)))1025 root = ET.fromstring(virsh("dumpxml", name))
1027 virsh("undefine", name, "--managed-save", *(["--nvram"] if root.find("./os/nvram") is not None else []), *(["--tpm"] if root.find("./devices/tpm") is not None else []))1026 virsh("undefine", name, "--managed-save", *(["--nvram"] if root.find("./os/nvram") is not None else []), *(["--tpm"] if root.find("./devices/tpm") is not None else []))
1028 directory = DISKS / name1027 directory = DISKS / name
1029 if payload["disks"] and directory.is_dir():1028 if payload["disks"] and directory.is_dir():