lmrc_ports/models.rs
1//! Provider-agnostic domain models
2//!
3//! These models represent infrastructure resources in a way that's independent
4//! of any specific cloud provider.
5
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9// ============================================================================
10// Server Models
11// ============================================================================
12
13/// Request to provision a new server
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct ProvisionRequest {
16 /// Unique name for the server
17 pub name: String,
18 /// Server type/size (e.g., "cx11", "t2.micro")
19 pub server_type: String,
20 /// Operating system image (e.g., "ubuntu-22.04", "ami-12345")
21 pub image: String,
22 /// Geographic location/region (e.g., "nbg1", "us-east-1")
23 pub location: String,
24 /// SSH keys to install (provider-specific IDs or names)
25 pub ssh_keys: Vec<String>,
26 /// Labels/tags for the server
27 pub labels: HashMap<String, String>,
28 /// Network to attach to (if any)
29 pub network_id: Option<String>,
30 /// Firewall rules to apply (if any)
31 pub firewall_ids: Vec<String>,
32 /// User data / cloud-init script
33 pub user_data: Option<String>,
34}
35
36/// A provisioned server
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct ProvisionedServer {
39 /// Provider-specific server ID
40 pub id: String,
41 /// Server name
42 pub name: String,
43 /// Server type/size
44 pub server_type: String,
45 /// Current status
46 pub status: ServerStatus,
47 /// Public IPv4 address (if assigned)
48 pub public_ipv4: Option<String>,
49 /// Public IPv6 address (if assigned)
50 pub public_ipv6: Option<String>,
51 /// Private IPv4 address (if assigned)
52 pub private_ipv4: Option<String>,
53 /// Server labels/tags
54 pub labels: HashMap<String, String>,
55 /// Geographic location/region
56 pub location: String,
57}
58
59/// Server status
60#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
61#[serde(rename_all = "lowercase")]
62pub enum ServerStatus {
63 Running,
64 Stopped,
65 Starting,
66 Stopping,
67 Deleting,
68 Unknown,
69}
70
71// ============================================================================
72// DNS Models
73// ============================================================================
74
75/// Request to create a DNS record
76#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct DnsRecordRequest {
78 /// Record type (A, AAAA, CNAME, TXT, etc.)
79 pub record_type: DnsRecordType,
80 /// Record name (e.g., "www", "@" for root)
81 pub name: String,
82 /// Record content/value (IP address, domain, etc.)
83 pub content: String,
84 /// Time to live in seconds
85 pub ttl: Option<u32>,
86 /// Whether to proxy through provider (Cloudflare-specific, ignored elsewhere)
87 pub proxied: bool,
88 /// Record priority (for MX records)
89 pub priority: Option<u16>,
90}
91
92/// DNS record type
93#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
94pub enum DnsRecordType {
95 A,
96 AAAA,
97 CNAME,
98 MX,
99 TXT,
100 NS,
101 SRV,
102 CAA,
103}
104
105/// A DNS record
106#[derive(Debug, Clone, Serialize, Deserialize)]
107pub struct DnsRecord {
108 /// Provider-specific record ID
109 pub id: String,
110 /// Zone/domain ID
111 pub zone_id: String,
112 /// Record type
113 pub record_type: DnsRecordType,
114 /// Record name
115 pub name: String,
116 /// Record content
117 pub content: String,
118 /// TTL in seconds
119 pub ttl: u32,
120 /// Whether proxied (if applicable)
121 pub proxied: bool,
122 /// Priority (if applicable)
123 pub priority: Option<u16>,
124}
125
126// ============================================================================
127// Kubernetes Models
128// ============================================================================
129
130/// Request to install a Kubernetes cluster
131#[derive(Debug, Clone, Serialize, Deserialize)]
132pub struct ClusterInstallRequest {
133 /// Cluster name
134 pub name: String,
135 /// Kubernetes version (e.g., "1.28", "latest")
136 pub version: Option<String>,
137 /// Master node IPs
138 pub master_nodes: Vec<String>,
139 /// Worker node IPs
140 pub worker_nodes: Vec<String>,
141 /// Additional configuration options
142 pub options: HashMap<String, String>,
143}
144
145/// Installed cluster information
146#[derive(Debug, Clone, Serialize, Deserialize)]
147pub struct InstalledCluster {
148 /// Cluster name
149 pub name: String,
150 /// Kubernetes version
151 pub version: String,
152 /// Kubeconfig content
153 pub kubeconfig: String,
154 /// Cluster endpoint URL
155 pub endpoint: String,
156 /// Master node IPs
157 pub master_nodes: Vec<String>,
158 /// Worker node IPs
159 pub worker_nodes: Vec<String>,
160}
161
162// ============================================================================
163// Database Models
164// ============================================================================
165
166/// Request to create a database
167#[derive(Debug, Clone, Serialize, Deserialize)]
168pub struct DatabaseCreateRequest {
169 /// Database name
170 pub name: String,
171 /// Database owner/user
172 pub owner: String,
173 /// Encoding (e.g., "UTF8")
174 pub encoding: Option<String>,
175 /// Locale (e.g., "en_US.UTF-8")
176 pub locale: Option<String>,
177 /// Database server host/IP
178 pub host: String,
179 /// Database server port
180 pub port: u16,
181 /// SSH private key path for server access
182 pub ssh_key_path: String,
183}
184
185/// A created database
186#[derive(Debug, Clone, Serialize, Deserialize)]
187pub struct CreatedDatabase {
188 /// Database name
189 pub name: String,
190 /// Database owner
191 pub owner: String,
192 /// Connection string
193 pub connection_string: String,
194 /// Host address
195 pub host: String,
196 /// Port number
197 pub port: u16,
198}
199
200/// Request to create a database user
201#[derive(Debug, Clone, Serialize, Deserialize)]
202pub struct DatabaseUserRequest {
203 /// Username
204 pub username: String,
205 /// Password
206 pub password: String,
207 /// Whether user is a superuser
208 pub superuser: bool,
209 /// Database server host/IP
210 pub host: String,
211 /// Database server port
212 pub port: u16,
213 /// SSH private key path for server access
214 pub ssh_key_path: String,
215}
216
217/// A database user
218#[derive(Debug, Clone, Serialize, Deserialize)]
219pub struct DatabaseUser {
220 /// Username
221 pub username: String,
222 /// Whether user is a superuser
223 pub superuser: bool,
224}
225
226// ============================================================================
227// Git/CI Models
228// ============================================================================
229
230/// Request to create or update a CI/CD variable
231#[derive(Debug, Clone, Serialize, Deserialize)]
232pub struct CiVariableRequest {
233 /// Variable key
234 pub key: String,
235 /// Variable value
236 pub value: String,
237 /// Whether the variable is protected
238 pub protected: bool,
239 /// Whether the variable is masked in logs
240 pub masked: bool,
241}
242
243/// A CI/CD variable
244#[derive(Debug, Clone, Serialize, Deserialize)]
245pub struct CiVariable {
246 /// Variable key
247 pub key: String,
248 /// Variable value (may be masked)
249 pub value: String,
250 /// Whether protected
251 pub protected: bool,
252 /// Whether masked
253 pub masked: bool,
254}
255
256/// Repository information
257#[derive(Debug, Clone, Serialize, Deserialize)]
258pub struct Repository {
259 /// Repository ID
260 pub id: String,
261 /// Repository name
262 pub name: String,
263 /// Repository URL (HTTPS)
264 pub url: String,
265 /// SSH URL
266 pub ssh_url: String,
267 /// Default branch
268 pub default_branch: String,
269}
270
271/// Pipeline/workflow run status
272#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
273#[serde(rename_all = "lowercase")]
274pub enum PipelineStatus {
275 Pending,
276 Running,
277 Success,
278 Failed,
279 Canceled,
280 Skipped,
281}
282
283/// A pipeline/workflow run
284#[derive(Debug, Clone, Serialize, Deserialize)]
285pub struct PipelineRun {
286 /// Pipeline ID
287 pub id: String,
288 /// Pipeline status
289 pub status: PipelineStatus,
290 /// Reference (branch/tag)
291 pub reference: String,
292 /// Web URL to view pipeline
293 pub web_url: String,
294}