Skip to content

Commit c2728e1

Browse files
authored
Add a minimal API definition Propolis Client (#11)
1 parent fad5fba commit c2728e1

File tree

4 files changed

+219
-0
lines changed

4 files changed

+219
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
members = [
44
"propolis",
55
"propolis-cli",
6+
"propolis-client",
67
"propolis-server",
78
]

propolis-client/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "propolis-client"
3+
version = "0.1.0"
4+
authors = ["Sean Klein <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[profile.dev]
10+
panic = "abort"
11+
[profile.release]
12+
panic = "abort"
13+
14+
[dependencies]
15+
schemars = { version = "0.8", features = [ "uuid" ] }
16+
serde = "1.0"
17+
uuid = "0.8"

propolis-client/src/api.rs

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
//! Types used to communicate between the Sled Agent and Propolis.
2+
//!
3+
//! Although many of these types mirror the API between Nexus
4+
//! and sled agent (within omicron-common), they are intentionally
5+
//! decoupled so the interfaces may evolve independently, as necessary.
6+
7+
use schemars::JsonSchema;
8+
use serde::{Deserialize, Serialize};
9+
use uuid::Uuid;
10+
11+
#[derive(Deserialize, Serialize, JsonSchema)]
12+
pub struct InstancePathParams {
13+
pub instance_id: Uuid,
14+
}
15+
16+
#[derive(Deserialize, Serialize, JsonSchema)]
17+
pub struct InstanceEnsureRequest {
18+
pub properties: InstanceProperties,
19+
}
20+
21+
#[derive(Deserialize, Serialize, JsonSchema)]
22+
pub struct InstanceEnsureResponse {}
23+
24+
#[derive(Deserialize, Serialize, JsonSchema)]
25+
pub struct InstanceGetResponse {
26+
pub instance: Instance,
27+
}
28+
29+
/// Requested state of an Instance.
30+
#[derive(Deserialize, Serialize, JsonSchema)]
31+
pub struct InstanceStateChange {
32+
pub state: InstanceStateRequested,
33+
}
34+
35+
#[derive(Deserialize, Serialize, JsonSchema)]
36+
pub enum InstanceStateRequested {
37+
Run,
38+
Stop,
39+
Reboot,
40+
}
41+
42+
#[derive(Deserialize, Serialize, JsonSchema)]
43+
pub struct InstanceSerialRequest {
44+
pub bytes: Vec<u8>,
45+
}
46+
47+
#[derive(Deserialize, Serialize, JsonSchema)]
48+
pub struct InstanceSerialResponse {
49+
pub bytes: Vec<u8>,
50+
}
51+
52+
/// Current state of an Instance.
53+
#[derive(Deserialize, Serialize, JsonSchema)]
54+
pub enum InstanceState {
55+
Creating,
56+
Starting,
57+
Running,
58+
Stopping,
59+
Stopped,
60+
Repairing,
61+
Failed,
62+
Destroyed,
63+
}
64+
65+
#[derive(Clone, Deserialize, Serialize, JsonSchema)]
66+
pub struct InstanceProperties {
67+
pub generation_id: u64,
68+
69+
/// Unique identifier for this Instance.
70+
pub id: Uuid,
71+
/// Human-readable name of the Instance.
72+
pub name: String,
73+
/// Free-form text description of an Instance.
74+
pub description: String,
75+
76+
/// ID of the image used to initialize this Instance.
77+
pub image_id: Uuid,
78+
/// ID of the bootrom used to initialize this Instance.
79+
pub bootrom_id: Uuid,
80+
/// Size of memory allocated to the Instance, in MiB.
81+
pub memory: u64,
82+
/// Number of vCPUs to be allocated to the Instance.
83+
pub vcpus: u8,
84+
}
85+
86+
#[derive(Deserialize, Serialize, JsonSchema)]
87+
pub struct Instance {
88+
pub properties: InstanceProperties,
89+
pub state: InstanceState,
90+
91+
pub disks: Vec<DiskAttachment>,
92+
pub nics: Vec<NicAttachment>,
93+
}
94+
95+
/// Describes how to connect to one or more storage agent services.
96+
#[derive(Deserialize, Serialize, JsonSchema)]
97+
pub struct StorageAgentDescription {
98+
/// Addresses of storage agents.
99+
pub agents: Vec<std::net::SocketAddrV6>,
100+
101+
/// Opaque key material for encryption and decryption.
102+
/// May become more structured as encryption scheme is solidified.
103+
pub key: Vec<u8>,
104+
105+
/// Minimum number of redundant copies of a block which must
106+
/// be written until data is considered "persistent".
107+
pub write_redundancy_threshold: u32,
108+
}
109+
110+
/// Refer to RFD 135 for more information on Virtual Storage Interfaces.
111+
/// This describes the type of disk which should be exposed to the guest VM.
112+
#[derive(Deserialize, Serialize, JsonSchema)]
113+
pub enum DiskType {
114+
NVMe,
115+
VirtioBlock,
116+
}
117+
118+
/// Describes a virtual disk.
119+
#[derive(Deserialize, Serialize, JsonSchema)]
120+
pub struct Disk {
121+
/// Unique identifier for this disk.
122+
pub id: Uuid,
123+
124+
/// Storage agents which implement networked block device servers.
125+
pub storage_agents: StorageAgentDescription,
126+
127+
/// Size of the disk (blocks).
128+
pub block_count: u64,
129+
130+
/// Block size (bytes).
131+
pub block_size: u32,
132+
133+
/// Storage interface.
134+
pub interface: DiskType,
135+
}
136+
137+
// TODO: Struggling to make this struct derive "JsonSchema"
138+
/*
139+
bitflags! {
140+
#[derive(Deserialize, Serialize)]
141+
pub struct DiskFlags: u32 {
142+
const READ = 0b0000_0001;
143+
const WRITE = 0b0000_0010;
144+
const READ_WRITE = Self::READ.bits | Self::WRITE.bits;
145+
}
146+
}
147+
*/
148+
149+
// TODO: Remove this; it's a hack to workaround the above bug.
150+
#[allow(dead_code)]
151+
pub const DISK_FLAG_READ: u32 = 0b0000_0001;
152+
#[allow(dead_code)]
153+
pub const DISK_FLAG_WRITE: u32 = 0b0000_0010;
154+
#[allow(dead_code)]
155+
pub const DISK_FLAG_READ_WRITE: u32 = DISK_FLAG_READ | DISK_FLAG_WRITE;
156+
type DiskFlags = u32;
157+
158+
#[derive(Deserialize, Serialize, JsonSchema)]
159+
pub struct DiskAttachmentInfo {
160+
pub flags: DiskFlags,
161+
pub slot: u16,
162+
}
163+
164+
#[derive(Deserialize, Serialize, JsonSchema)]
165+
pub enum DiskAttachmentState {
166+
Attached(DiskAttachmentInfo),
167+
Detached,
168+
Faulted,
169+
}
170+
171+
#[derive(Deserialize, Serialize, JsonSchema)]
172+
pub struct DiskAttachment {
173+
pub generation_id: u64,
174+
pub disk_id: Uuid,
175+
pub state: DiskAttachmentState,
176+
}
177+
178+
#[derive(Deserialize, Serialize, JsonSchema)]
179+
pub struct NicAttachmentInfo {
180+
pub slot: u16,
181+
}
182+
183+
#[derive(Deserialize, Serialize, JsonSchema)]
184+
pub enum NicAttachmentState {
185+
Attached(NicAttachmentInfo),
186+
Detached,
187+
Faulted,
188+
}
189+
190+
#[derive(Deserialize, Serialize, JsonSchema)]
191+
pub struct NicAttachment {
192+
pub generation_id: u64,
193+
pub nic_id: Uuid,
194+
pub stat: NicAttachmentState,
195+
}

propolis-client/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! Interface for making API requests to propolis.
2+
//! This should be replaced with a client generated from the OpenAPI spec.
3+
4+
pub mod api;
5+
6+
// TODO: Implement the client.

0 commit comments

Comments
 (0)