Skip to content

Commit

Permalink
Small fixes and changes to client config
Browse files Browse the repository at this point in the history
  • Loading branch information
hasanhakkaev committed Sep 29, 2023
1 parent f690abc commit ecffae1
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 34 deletions.
5 changes: 2 additions & 3 deletions hack/provider/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ options:
default: docker-ce
INSTANCE_TYPE:
description: The machine type to use, arm based machines are only available in certain zones.
default: cx31
default: tiny
suggestions:
- micro
- tiny
- small
- medium
Expand All @@ -55,7 +54,7 @@ options:
- huge
DISK_SIZE:
description: The disk size to use.
default: 50
default: 10
suggestions:
- 10
- 50
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ impl Create {
match exoscale {
Ok(provider) => {
let create = provider.create().await;
match create {
Err(err) => return Err(anyhow::anyhow!("Error creating instance: {}", err)),
_ => {}
if let Err(err) = create {
return Err(anyhow::anyhow!("Error creating instance: {}", err));
}
}
Err(err) => return Err(err),
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ impl Delete {
match exoscale {
Ok(provider) => {
let create = provider.delete().await;
match create {
Err(err) => return Err(anyhow::anyhow!("Error deleting instance: {}", err)),
_ => {}
if let Err(err) = create {
return Err(anyhow::anyhow!("Error deleting instance: {}", err));
}
}
Err(err) => return Err(err),
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ impl Start {
match exoscale {
Ok(provider) => {
let start = provider.start().await;
match start {
Err(err) => return Err(anyhow::anyhow!("Error starting instance: {}", err)),
_ => {}
if let Err(err) = start {
return Err(anyhow::anyhow!("Error starting instance: {}", err));
}
}
Err(err) => return Err(err),
Expand Down
7 changes: 2 additions & 5 deletions src/cmd/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ impl State {
match exoscale {
Ok(provider) => {
let status = provider.state().await;
match status {
Err(err) => {
return Err(anyhow::anyhow!("Error getting instance state: {}", err))
}
_ => {}
if let Err(err) = status {
return Err(anyhow::anyhow!("Error getting instance state: {}", err));
}
println!("{}", status.unwrap());
}
Expand Down
5 changes: 2 additions & 3 deletions src/cmd/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ impl Stop {
match exoscale {
Ok(provider) => {
let stop = provider.stop().await;
match stop {
Err(err) => return Err(anyhow::anyhow!("Error stopping instance: {}", err)),
_ => {}
if let Err(err) = stop {
return Err(anyhow::anyhow!("Error stopping instance: {}", err));
}
}
Err(err) => return Err(err),
Expand Down
19 changes: 7 additions & 12 deletions src/exoscale/exoscale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ impl ExoscaleProvider {
let mut configuration = Configuration::new();
let options = from_env(init);

configuration.base_path =
format!("https://api-{:?}.exoscale.com/v2", options.zone.as_str());

match key {
Ok(key) => {
configuration.api_key =
Some(exoscale::apis::configuration::ApiKey { key, prefix: None }).unwrap()
configuration.api_key = exoscale::apis::configuration::ApiKey { key, prefix: None }
}
Err(err) => return Err(anyhow::anyhow!("Error getting API key: {}", err)),
}
Expand Down Expand Up @@ -88,14 +84,14 @@ impl ExoscaleProvider {

pub async fn delete(&self) -> Result<()> {
let devpod_instance = self.get_devpod_instance().await?;
let id: Option<&str> = devpod_instance.id.as_ref().map(|s| s.as_str());
let id: Option<&str> = devpod_instance.id.as_deref();
exoscale::apis::instance_api::delete_instance(&self.configuration, id.unwrap()).await?;
Ok(())
}

pub async fn start(&self) -> Result<()> {
let devpod_instance = self.get_devpod_instance().await?;
let id: Option<&str> = devpod_instance.id.as_ref().map(|s| s.as_str());
let id: Option<&str> = devpod_instance.id.as_deref();
exoscale::apis::instance_api::start_instance(
&self.configuration,
id.unwrap(),
Expand All @@ -109,22 +105,21 @@ impl ExoscaleProvider {

pub async fn stop(&self) -> Result<()> {
let devpod_instance = self.get_devpod_instance().await?;
let id: Option<&str> = devpod_instance.id.as_ref().map(|s| s.as_str());
let id: Option<&str> = devpod_instance.id.as_deref();
exoscale::apis::instance_api::stop_instance(&self.configuration, id.unwrap()).await?;
Ok(())
}

pub async fn state(&self) -> Result<String> {
let devpod_instance = self.get_devpod_instance().await?;
return if devpod_instance.state == Option::from(exoscale::models::instance::State::Running)
{
if devpod_instance.state == Option::from(exoscale::models::instance::State::Running) {
Ok("Running".to_string())
} else if devpod_instance.state == Option::from(exoscale::models::instance::State::Stopped)
{
Ok("Stopped".to_string())
} else {
Ok("Error".to_string())
};
}
}

pub async fn create(&self) -> Result<()> {
Expand Down Expand Up @@ -154,7 +149,7 @@ impl ExoscaleProvider {
if zone
== &map_str_to_zone_name(self.options.zone.as_str()).unwrap()
{
Some(zone.clone())
Some(*zone)
} else {
None
}
Expand Down
4 changes: 2 additions & 2 deletions src/ssh/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ pub async fn new_ssh_client(
}
Ok("".to_string())
} else {
return Err(Error::new(
Err(Error::new(
ErrorCode::Session(0),
"Error connecting to ssh server",
));
))
}
}

Expand Down

0 comments on commit ecffae1

Please sign in to comment.