-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathlib.rs
More file actions
98 lines (80 loc) · 2.45 KB
/
lib.rs
File metadata and controls
98 lines (80 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
use std::collections::BTreeMap;
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use strum::FromRepr;
pub use cpuid_profile_config::*;
#[derive(FromRepr, Eq, PartialEq)]
#[repr(u8)]
pub enum SnapshotTag {
Config = 0,
Global = 1,
Device = 2,
Lowmem = 3,
Himem = 4,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Config {
pub main: Main,
#[serde(default, rename = "dev")]
pub devices: BTreeMap<String, Device>,
#[serde(default, rename = "block_dev")]
pub block_devs: BTreeMap<String, BlockDevice>,
#[serde(default, rename = "cpuid")]
pub cpuid_profiles: BTreeMap<String, CpuidProfile>,
pub cloudinit: Option<CloudInit>,
}
impl Config {
pub fn cpuid_profile(&self) -> Option<&CpuidProfile> {
match self.main.cpuid_profile.as_ref() {
Some(name) => self.cpuid_profiles.get(name),
None => None,
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Main {
pub name: String,
pub cpus: u8,
pub bootrom: String,
pub memory: usize,
pub use_reservoir: Option<bool>,
pub qemu_debug_file: Option<PathBuf>,
pub cpuid_profile: Option<String>,
}
/// A hard-coded device, either enabled by default or accessible locally
/// on a machine.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Device {
pub driver: String,
#[serde(flatten, default)]
pub options: BTreeMap<String, toml::Value>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BlockOpts {
pub block_size: Option<u32>,
pub read_only: Option<bool>,
pub skip_flush: Option<bool>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct BlockDevice {
#[serde(default, rename = "type")]
pub bdtype: String,
#[serde(flatten)]
pub block_opts: BlockOpts,
#[serde(flatten, default)]
pub options: BTreeMap<String, toml::Value>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
pub struct CloudInit {
pub user_data: Option<String>,
pub meta_data: Option<String>,
pub network_config: Option<String>,
// allow path-style contents as well
pub user_data_path: Option<String>,
pub meta_data_path: Option<String>,
pub network_config_path: Option<String>,
}