Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion build.rs
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(&["proto/feos.proto", "proto/container.proto"], &["proto"])?;
.compile(
&[
"proto/feos.proto",
"proto/container.proto",
"proto/isolated_container.proto",
],
&["proto"],
)?;
Ok(())
}
6 changes: 5 additions & 1 deletion client/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ fn main() {
tonic_build::configure()
.build_server(false)
.compile(
&["../proto/feos.proto", "../proto/container.proto"],
&[
"../proto/feos.proto",
"../proto/container.proto",
"../proto/isolated_container.proto",
],
&["../proto"],
)
.unwrap();
Expand Down
10 changes: 10 additions & 0 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use tonic::transport::Endpoint;
use tonic::Request;

use crate::client_container::ContainerCommand;
use crate::client_isolated_container::IsolatedContainerCommand;
use feos_grpc::feos_grpc_client::FeosGrpcClient;
use feos_grpc::*;

Expand Down Expand Up @@ -63,6 +64,7 @@ pub enum Command {
uuid: String,
},
Container(ContainerCommand),
IsolatedContainer(IsolatedContainerCommand),
}

fn format_address(ip: &str, port: u16) -> String {
Expand All @@ -89,6 +91,14 @@ pub async fn run_client(opt: Opt) -> Result<(), Box<dyn std::error::Error>> {
crate::client_container::run_container_client(opt.server_ip, opt.port, container_cmd)
.await?;
}
Command::IsolatedContainer(container_cmd) => {
crate::client_isolated_container::run_isolated_container_client(
opt.server_ip,
opt.port,
container_cmd,
)
.await?;
}
Command::Reboot => {
let request = Request::new(RebootRequest {});
let response = client.reboot(request).await?;
Expand Down
76 changes: 76 additions & 0 deletions client/src/client_isolated_container.rs
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(())
}
1 change: 1 addition & 0 deletions client/src/main.rs
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;
Expand Down
35 changes: 35 additions & 0 deletions proto/isolated_container.proto
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;
}
Loading