-
Notifications
You must be signed in to change notification settings - Fork 4
Isolated container #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2afb9e8
WIP
lukasfrank e64716e
Implemented stop / state
lukasfrank 9b91b28
Remove not used deps
lukasfrank f8370e4
PR Review
lukasfrank 02b6d78
PR Review
lukasfrank 718a466
upgrading to kernel 6.6.60 (#55)
MalteJ 3121314
updating dependencies (#54)
MalteJ 7ac3b96
Merge branch 'master' into feat/isolated-container
lukasfrank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| tonic_build::configure() | ||
| .protoc_arg("--experimental_allow_proto3_optional") | ||
| .compile_protos(&["proto/feos.proto", "proto/container.proto"], &["proto"])?; | ||
| .compile_protos( | ||
| &[ | ||
| "proto/feos.proto", | ||
| "proto/container.proto", | ||
| "proto/isolated_container.proto", | ||
| ], | ||
| &["proto"], | ||
| )?; | ||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| use std::time::Duration; | ||
| use structopt::StructOpt; | ||
| use tokio::time::timeout; | ||
| use tonic::transport::Endpoint; | ||
| use tonic::Request; | ||
|
|
||
| use isolated_container_grpc::isolated_container_service_client::IsolatedContainerServiceClient; | ||
| use isolated_container_grpc::*; | ||
|
|
||
| pub mod isolated_container_grpc { | ||
| tonic::include_proto!("isolated_container"); | ||
| } | ||
|
|
||
| #[derive(StructOpt, Debug)] | ||
| pub enum IsolatedContainerCommand { | ||
| Create { | ||
| image: String, | ||
| #[structopt(name = "COMMAND", required = true, min_values = 1)] | ||
| command: Vec<String>, | ||
| }, | ||
| Run { | ||
| uuid: String, | ||
| }, | ||
| Stop { | ||
| uuid: String, | ||
| }, | ||
| State { | ||
| uuid: String, | ||
| }, | ||
| } | ||
|
|
||
| pub async fn run_isolated_container_client( | ||
| server_ip: String, | ||
| port: u16, | ||
| cmd: IsolatedContainerCommand, | ||
| ) -> Result<(), Box<dyn std::error::Error>> { | ||
| let address = format!("http://{}:{}", server_ip, port); | ||
| let channel = Endpoint::from_shared(address)?.connect().await?; | ||
| let mut client = IsolatedContainerServiceClient::new(channel); | ||
|
|
||
| match cmd { | ||
| IsolatedContainerCommand::Create { image, command } => { | ||
| let request = Request::new(CreateContainerRequest { image, command }); | ||
| match timeout(Duration::from_secs(30), client.create_container(request)).await { | ||
| Ok(response) => match response { | ||
| Ok(response) => println!("CREATE ISOLATED CONTAINER RESPONSE={:?}", response), | ||
| Err(e) => eprintln!("Error creating isolated container: {:?}", e), | ||
| }, | ||
| Err(_) => eprintln!("Request timed out after 30 seconds"), | ||
| } | ||
| } | ||
| IsolatedContainerCommand::Run { uuid } => { | ||
| let request = Request::new(RunContainerRequest { uuid }); | ||
| match client.run_container(request).await { | ||
| Ok(response) => println!("RUN ISOLATED CONTAINER RESPONSE={:?}", response), | ||
| Err(e) => eprintln!("Error running isolated container: {:?}", e), | ||
| } | ||
| } | ||
| IsolatedContainerCommand::Stop { uuid } => { | ||
| let request = Request::new(StopContainerRequest { uuid }); | ||
| match client.stop_container(request).await { | ||
| Ok(response) => println!("STOP ISOLATED CONTAINER RESPONSE={:?}", response), | ||
| Err(e) => eprintln!("Error stopping isolated container: {:?}", e), | ||
| } | ||
| } | ||
| IsolatedContainerCommand::State { uuid } => { | ||
| let request = Request::new(StateContainerRequest { uuid }); | ||
| match client.state_container(request).await { | ||
| Ok(response) => println!("STATE ISOLATED CONTAINER RESPONSE={:?}", response), | ||
| Err(e) => eprintln!("Error getting isolated container state: {:?}", e), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| mod client; | ||
| mod client_container; | ||
| mod client_isolated_container; | ||
|
|
||
| use client::Opt; | ||
| use structopt::StructOpt; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| syntax = "proto3"; | ||
| package isolated_container; | ||
|
|
||
| service IsolatedContainerService { | ||
| rpc CreateContainer (CreateContainerRequest) returns (CreateContainerResponse); | ||
| rpc RunContainer (RunContainerRequest) returns (RunContainerResponse); | ||
| rpc StopContainer (StopContainerRequest) returns (StopContainerResponse); | ||
| rpc StateContainer (StateContainerRequest) returns (StateContainerResponse); | ||
| } | ||
|
|
||
| message CreateContainerRequest { | ||
| string image = 1; | ||
| repeated string command = 2; | ||
| } | ||
| message CreateContainerResponse { | ||
| string uuid = 1; | ||
| } | ||
|
|
||
| message RunContainerRequest { | ||
| string uuid = 1; | ||
| } | ||
| message RunContainerResponse {} | ||
|
|
||
| message StopContainerRequest { | ||
| string uuid = 1; | ||
| } | ||
| message StopContainerResponse {} | ||
|
|
||
| message StateContainerRequest { | ||
| string uuid = 1; | ||
| } | ||
| message StateContainerResponse { | ||
| string state = 1; | ||
| optional int32 pid = 2; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.