added new vm requests
This commit is contained in:
		
							parent
							
								
									ec962197ff
								
							
						
					
					
						commit
						64a84c48be
					
				
							
								
								
									
										29
									
								
								src/main.rs
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										29
									
								
								src/main.rs
									
									
									
									
									
								
							| @ -4,17 +4,26 @@ mod constants; | ||||
| mod tcontract; | ||||
| 
 | ||||
| use crate::config::Config; | ||||
| use crate::state::NewVMRequest; | ||||
| 
 | ||||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||||
|     let config = Config::from_file("test_data/config1.yaml")?; | ||||
|     println!("{:#?}", config); | ||||
|     let config = Config::from_file("test_data/config2.yaml")?; | ||||
|     println!("{:#?}", config); | ||||
|     let config = Config::from_file("test_data/config3.yaml")?; | ||||
|     println!("{:#?}", config); | ||||
|     let config = Config::from_file("test_data/config4.yaml")?; | ||||
|     println!("{:#?}", config); | ||||
|     let config = Config::from_file("test_data/config5.yaml")?; | ||||
|     println!("{:#?}", config); | ||||
|     // let config = Config::from_file("test_data/config1.yaml")?;
 | ||||
|     // println!("{:#?}", config);
 | ||||
|     // let config = Config::from_file("test_data/config2.yaml")?;
 | ||||
|     // println!("{:#?}", config);
 | ||||
|     // let config = Config::from_file("test_data/config3.yaml")?;
 | ||||
|     // println!("{:#?}", config);
 | ||||
|     // let config = Config::from_file("test_data/config4.yaml")?;
 | ||||
|     // println!("{:#?}", config);
 | ||||
|     // let config = Config::from_file("test_data/config5.yaml")?;
 | ||||
|     // println!("{:#?}", config);
 | ||||
|     let new_vm_req = NewVMRequest::from_file("test_data/new_vm_req1.yaml")?; | ||||
|     println!("{:#?}", new_vm_req); | ||||
|     let new_vm_req = NewVMRequest::from_file("test_data/new_vm_req2.yaml")?; | ||||
|     println!("{:#?}", new_vm_req); | ||||
|     let new_vm_req = NewVMRequest::from_file("test_data/new_vm_req3.yaml")?; | ||||
|     println!("{:#?}", new_vm_req); | ||||
|     let new_vm_req = NewVMRequest::from_file("test_data/new_vm_req4.yaml")?; | ||||
|     println!("{:#?}", new_vm_req); | ||||
|     Ok(()) | ||||
| } | ||||
|  | ||||
							
								
								
									
										10
									
								
								src/state.rs
									
									
									
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										10
									
								
								src/state.rs
									
									
									
									
									
								
							| @ -12,6 +12,7 @@ use std::io::Read; | ||||
| use std::io::Write; | ||||
| use std::path::Path; | ||||
| use std::process::Command; | ||||
| use serde::Deserialize; | ||||
| 
 | ||||
| pub struct Resources { | ||||
|     // QEMU does not support MHz limiation
 | ||||
| @ -263,6 +264,7 @@ pub struct VM { | ||||
|     dtrfs_sha: String, | ||||
| } | ||||
| 
 | ||||
| #[derive(Deserialize, Debug)] | ||||
| pub struct NewVMRequest { | ||||
|     uuid: String, | ||||
|     hostname: String, | ||||
| @ -279,6 +281,14 @@ pub struct NewVMRequest { | ||||
|     dtrfs_sha: String, | ||||
| } | ||||
| 
 | ||||
| impl NewVMRequest { | ||||
|     pub fn from_file(path: &str) -> Result<Self, Box<dyn std::error::Error>> { | ||||
|         let content = std::fs::read_to_string(path)?; | ||||
|         let request: NewVMRequest = serde_yaml::from_str(&content)?; | ||||
|         Ok(request) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| pub enum VMCreationErrors { | ||||
|     NATandIPv4Conflict, | ||||
|     TooManyCores, | ||||
|  | ||||
							
								
								
									
										15
									
								
								test_data/new_vm_req1.yaml
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										15
									
								
								test_data/new_vm_req1.yaml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,15 @@ | ||||
| uuid: "123e4567-e89b-12d3-a456-426614174000" | ||||
| hostname: "test-vm-01" | ||||
| admin_key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArandomkeyexample" | ||||
| extra_ports: | ||||
|   - 8080 | ||||
|   - 8443 | ||||
| public_ipv4: true | ||||
| public_ipv6: false | ||||
| disk_size: 50 | ||||
| vcpus: 4 | ||||
| memory: 8192 | ||||
| kernel_url: "http://example.com/kernel" | ||||
| kernel_sha: "abc123def4567890ghij" | ||||
| dtrfs_url: "http://example.com/dtrfs" | ||||
| dtrfs_sha: "xyz9876543210mnop" | ||||
							
								
								
									
										14
									
								
								test_data/new_vm_req2.yaml
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										14
									
								
								test_data/new_vm_req2.yaml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | ||||
| uuid: "987e6543-e21b-43d3-c321-654987210000" | ||||
| hostname: "minimal-vm" | ||||
| admin_key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQAnotherExampleKey" | ||||
| extra_ports: [] | ||||
| public_ipv4: false | ||||
| public_ipv6: false | ||||
| disk_size: 10 | ||||
| vcpus: 1 | ||||
| memory: 2048 | ||||
| kernel_url: "http://minimal.com/kernel" | ||||
| kernel_sha: "minimalsha123" | ||||
| dtrfs_url: "http://minimal.com/dtrfs" | ||||
| dtrfs_sha: "dtrfssha456" | ||||
| 
 | ||||
							
								
								
									
										19
									
								
								test_data/new_vm_req3.yaml
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										19
									
								
								test_data/new_vm_req3.yaml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,19 @@ | ||||
| uuid: "246e1357-e98b-76d3-f345-129874650000" | ||||
| hostname: "extensive-vm" | ||||
| admin_key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEExtendedKeyExample" | ||||
| extra_ports: | ||||
|   - 80 | ||||
|   - 443 | ||||
|   - 3000 | ||||
|   - 5000 | ||||
|   - 6000 | ||||
| public_ipv4: true | ||||
| public_ipv6: true | ||||
| disk_size: 200 | ||||
| vcpus: 16 | ||||
| memory: 65536 | ||||
| kernel_url: "http://large.com/kernel" | ||||
| kernel_sha: "largekernelsha" | ||||
| dtrfs_url: "http://large.com/dtrfs" | ||||
| dtrfs_sha: "largedtrfssha" | ||||
| 
 | ||||
							
								
								
									
										14
									
								
								test_data/new_vm_req4.yaml
									
									
									
									
									
										Normal file
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										14
									
								
								test_data/new_vm_req4.yaml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,14 @@ | ||||
| uuid: "default-uuid" | ||||
| hostname: "testing-vm" | ||||
| admin_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAAKeyExampleForTesting" | ||||
| extra_ports: [1234, 5678] | ||||
| public_ipv4: false | ||||
| public_ipv6: true | ||||
| disk_size: 25 | ||||
| vcpus: 2 | ||||
| memory: 4096 | ||||
| kernel_url: "http://testing.com/kernel" | ||||
| kernel_sha: "testkernelsha" | ||||
| dtrfs_url: "http://testing.com/dtrfs" | ||||
| dtrfs_sha: "testdtrfssha" | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user