MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / register

Method register

vmm/src/discovery.rs:59–97  ·  view source on GitHub ↗

Register a new VMM instance. Creates the discovery directory if needed and writes the instance info JSON file.

(
        listen_address: &str,
        config_file: Option<&str>,
        image_path: &Path,
        run_path: &Path,
        node_name: &str,
        version: &str,
    )

Source from the content-addressed store, hash-verified

57 /// Register a new VMM instance. Creates the discovery directory if needed
58 /// and writes the instance info JSON file.
59 pub fn register(
60 listen_address: &str,
61 config_file: Option<&str>,
62 image_path: &Path,
63 run_path: &Path,
64 node_name: &str,
65 version: &str,
66 ) -> Result<Self> {
67 let dir = discovery_dir();
68 fs_err::create_dir_all(&dir).context("failed to create discovery directory")?;
69
70 let id = Uuid::new_v4().to_string();
71 let path = dir.join(format!("{id}.json"));
72
73 let cwd = std::env::current_dir().context("failed to get current directory")?;
74
75 let info = VmmInstanceInfo {
76 id: id.clone(),
77 pid: std::process::id(),
78 address: listen_address.to_string(),
79 working_dir: cwd.to_string_lossy().to_string(),
80 config_file: config_file.map(|s| s.to_string()),
81 image_path: image_path.to_string_lossy().to_string(),
82 run_path: run_path.to_string_lossy().to_string(),
83 node_name: node_name.to_string(),
84 version: version.to_string(),
85 started_at: std::time::SystemTime::now()
86 .duration_since(std::time::UNIX_EPOCH)
87 .unwrap_or_default()
88 .as_secs(),
89 };
90
91 let json =
92 serde_json::to_string_pretty(&info).context("failed to serialize instance info")?;
93 fs_err::write(&path, &json).context("failed to write discovery file")?;
94
95 info!("registered VMM instance {id} at {}", path.display());
96 Ok(Self { path })
97 }
98}
99
100impl Drop for DiscoveryRegistration {

Callers

nothing calls this directly

Calls 2

discovery_dirFunction · 0.85
cloneMethod · 0.80

Tested by

no test coverage detected