fly_sdk/machines/
endpoints.rs

1use crate::machines::{
2    MachineConfig,
3    MachineRegions,
4    // Checks, DnsConfig, FileConfig, GuestConfig, Header, InitConfig,
5    // MetricsConfig, MountConfig, ProcessConfig, RestartPolicy, ServiceConfig, StaticConfig,
6    // StopConfig, TimeoutConfig,
7};
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10
11#[derive(Serialize, Deserialize, Debug)]
12pub struct MachineRequest {
13    pub name: Option<String>,
14    pub config: MachineConfig,
15    pub region: Option<MachineRegions>,
16    pub lease_ttl: Option<u64>,
17    pub lsvd: Option<bool>,
18    pub skip_launch: Option<bool>,
19    pub skip_service_registration: Option<bool>,
20}
21
22impl MachineRequest {
23    pub fn new(
24        config: MachineConfig,
25        name: Option<String>,
26        region: Option<MachineRegions>,
27    ) -> Self {
28        Self {
29            name: name,
30            config,
31            region: region,
32            lease_ttl: None,
33            lsvd: None,
34            skip_launch: None,
35            skip_service_registration: None,
36        }
37    }
38
39    pub fn with_lease_ttl(mut self, lease_ttl: u64) -> Self {
40        self.lease_ttl = Some(lease_ttl);
41        self
42    }
43
44    pub fn with_lsvd(mut self, lsvd: bool) -> Self {
45        self.lsvd = Some(lsvd);
46        self
47    }
48
49    pub fn with_skip_launch(mut self, skip_launch: bool) -> Self {
50        self.skip_launch = Some(skip_launch);
51        self
52    }
53
54    pub fn with_skip_service_registration(mut self, skip_service_registration: bool) -> Self {
55        self.skip_service_registration = Some(skip_service_registration);
56        self
57    }
58
59    pub fn to_json(&self) -> String {
60        serde_json::to_string(&self).unwrap()
61    }
62}
63
64#[derive(Serialize, Deserialize, Debug)]
65pub struct MachineResponse {
66    pub id: Option<String>,
67    pub checks: Option<Vec<CheckResponse>>,
68    pub config: Option<MachineConfig>,
69    pub created_at: Option<String>,
70    pub events: Option<Vec<EventResponse>>,
71    pub host_status: Option<HostStatusEnum>,
72    pub image_ref: Option<ImageRef>,
73    pub incomplete_config: Option<Value>,
74    pub instance_id: Option<String>,
75    pub name: Option<String>,
76    pub nonce: Option<String>,
77    pub private_ip: Option<String>,
78    pub region: Option<String>,
79    pub state: Option<String>,
80    pub updated_at: Option<String>,
81}
82
83#[derive(Serialize, Deserialize, Debug)]
84pub struct EventResponse {
85    pub id: Option<String>,
86    pub request: Option<Value>,
87    pub source: Option<String>,
88    pub status: Option<String>,
89    pub timestamp: Option<u64>,
90    pub event_type: Option<String>,
91}
92
93#[derive(Serialize, Deserialize, Debug)]
94#[serde(rename_all = "lowercase")]
95pub enum HostStatusEnum {
96    Ok,
97    Unknown,
98    Unreachable,
99}
100
101#[derive(Serialize, Deserialize, Debug)]
102pub struct ImageRef {
103    pub digest: Option<String>,
104    pub labels: Option<Value>,
105    pub registry: Option<String>,
106    pub repository: Option<String>,
107    pub tag: Option<String>,
108}
109
110#[derive(Serialize, Deserialize, Debug)]
111pub struct CheckResponse {
112    pub name: Option<String>,
113    pub output: Option<String>,
114    pub status: Option<String>,
115    pub updated_at: Option<String>,
116}
117
118#[derive(Serialize, Deserialize, Debug)]
119struct CreateMachinesResponse {
120    machines: Vec<MachineResponse>,
121}