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

Method uuid

gateway/src/config.rs:250–283  ·  view source on GitHub ↗

Get or generate a unique node UUID. The UUID is stored in `{data_dir}/node_uuid` and persisted across restarts.

(&self)

Source from the content-addressed store, hash-verified

248 /// Get or generate a unique node UUID.
249 /// The UUID is stored in `{data_dir}/node_uuid` and persisted across restarts.
250 pub fn uuid(&self) -> Vec<u8> {
251 use std::fs;
252 use std::path::Path;
253
254 let uuid_path = Path::new(&self.sync.data_dir).join("node_uuid");
255
256 // Try to read existing UUID
257 if let Ok(content) = fs::read_to_string(&uuid_path) {
258 if let Ok(uuid) = uuid::Uuid::parse_str(content.trim()) {
259 return uuid.as_bytes().to_vec();
260 }
261 }
262
263 // Generate new UUID
264 let uuid = uuid::Uuid::new_v4();
265
266 // Ensure directory exists
267 if let Some(parent) = uuid_path.parent() {
268 let _ = fs::create_dir_all(parent);
269 }
270
271 // Save UUID to file
272 if let Err(err) = fs::write(&uuid_path, uuid.to_string()) {
273 tracing::warn!(
274 "failed to save node UUID to {}: {}",
275 uuid_path.display(),
276 err
277 );
278 } else {
279 tracing::info!("generated new node UUID: {}", uuid);
280 }
281
282 uuid.as_bytes().to_vec()
283 }
284}
285
286#[derive(Debug, Clone, Deserialize)]

Callers 2

statusMethod · 0.45
newMethod · 0.45

Calls 1

to_vecMethod · 0.80

Tested by

no test coverage detected