Skip to content

Commit

Permalink
Adapt to new pkg, provider option fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hasanhakkaev committed Oct 1, 2023
1 parent 9f8de56 commit 72fa4d3
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 63 deletions.
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
anyhow = { version = "1.0.71", features = [] }
clap = { version = "4.3.0", features = ["derive"] }
crossbeam = { version = "0.8.2", features = ["crossbeam-channel"] }
exoscale-rs = "2.0.0"
exoscale-rs = "2.0.1"
openssh-keys = "0.6.0"
openssl = { version = "0.10.52", features = ["vendored"] }
petname = "1.1.3"
Expand Down
22 changes: 19 additions & 3 deletions hack/provider/provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ description: |-
icon: https://avatars.githubusercontent.com/u/2023286?s=200&v=4
optionGroups:
- options:
- ZONE
- TEMPLATE
- INSTANCE_TYPE
- DISK_SIZE
Expand All @@ -26,7 +25,7 @@ options:
description: The Exoscale API secret to use.
required: true
password: true
ZONE:
EXOSCALE_ZONE:
description: The Exoscale Zone to use.
required: true
default: at-vie-1
Expand All @@ -41,7 +40,24 @@ options:
- at-vie-2
TEMPLATE:
description: The template to use.
default: docker-ce
default: Exoscale Container-Optimized Instance
suggestions:
- Exoscale Container-Optimized Instance
- Linux Arch Rolling
- Linux CentOS Stream 8 64-bit
- Linux CentOS Stream 9 64-bit
- Linux Debian 10 (Buster) 64-bit
- Linux Debian 11 (Bullseye) 64-bit
- Linux Debian 12 (Bookworm) 64-bit
- Linux Ubuntu 20.04 LTS 64-bit
- Linux Ubuntu 22.04 LTS 64-bit
- Linux Ubuntu 23.04 64-bit
- Linux Fedora CoreOS 38 64-bit
- Rocky Linux 8 (Green Obsidian) 64-bit
- Rocky Linux 9 (Blue Onyx) 64-bit
- Linux CentOS 7 64-bit
- Linux RedHat 7.9 BYOL 64-bit
- Linux RedHat 8.2 BYOL 64-bit
INSTANCE_TYPE:
description: The machine type to use, arm based machines are only available in certain zones.
default: tiny
Expand Down
68 changes: 38 additions & 30 deletions src/exoscale/exoscale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ impl ExoscaleProvider {
.context("Please set EXOSCALE_API_KEY environment variable");
let api_secret = env::var("EXOSCALE_API_SECRET")
.context("Please set EXOSCALE_API_SECRET environment variable");
let zone =
env::var("EXOSCALE_ZONE").context("Please set EXOSCALE_ZONE environment variable");

let mut configuration = Configuration::new();
let mut configuration = Configuration::new(zone.as_ref().unwrap());
let options = from_env(init);

match api_key {
Expand All @@ -43,6 +45,12 @@ impl ExoscaleProvider {
}
Err(err) => return Err(anyhow::anyhow!("Error getting API secret: {}", err)),
}
match zone {
Ok(zone) => {
configuration.zone = zone;
}
Err(err) => return Err(anyhow::anyhow!("Error getting ZONE: {}", err)),
}
let provider = ExoscaleProvider {
configuration,
options,
Expand Down Expand Up @@ -78,8 +86,16 @@ impl ExoscaleProvider {
.labels
.as_ref()
.unwrap()
.get(self.options.machine_id.as_str())
.is_some()
.get("devpod_enabled".to_string().as_str())
.unwrap()
== "true".to_string().as_str()
&& instance
.labels
.as_ref()
.unwrap()
.get("devpod_instance_id".to_string().as_str())
.unwrap()
== self.options.machine_id.clone().as_str()
{
Some(instance.clone())
} else {
Expand Down Expand Up @@ -218,30 +234,38 @@ impl ExoscaleProvider {
);

let mut labels = HashMap::new();
labels.insert(self.options.machine_id.clone(), "true".to_string());
labels.insert("devpod_instance".to_string(), "true".to_string());
labels.insert(
"devpod_instance_id".to_string(),
self.options.machine_id.clone(),
);
labels.insert(
"devpod_instance_folder".to_string(),
self.options.machine_folder.clone(),
);

let request_params = exoscale_rs::models::CreateInstanceRequest {
anti_affinity_groups: None,
instance_type,
template,
disk_size: self.options.disk_size.parse().unwrap(),
labels: Some(labels),
auto_start: None,
auto_start: Option::from(true),
security_groups: None,
user_data: Some(format!(
r#"#cloud-config
users:
- name: devpod
shell: /bin/bash
groups: [ sudo, docker ]
ssh_authorized_keys:
- {}
sudo: [ "ALL=(ALL) NOPASSWD:ALL" ]"#,
users:
- name: devpod
shell: /bin/bash
groups: [ sudo, docker ]
ssh_authorized_keys:
- {}
sudo: [ "ALL=(ALL) NOPASSWD:ALL" ]"#,
public_key_base
)),
deploy_target: None,
public_ip_assignment: None,
name: None,
public_ip_assignment: Some(exoscale_rs::models::PublicIpAssignment::Inet4),
name: Some(self.options.machine_id.clone().to_string()),
ssh_key: None,
ipv6_enabled: None,
ssh_keys: None,
Expand All @@ -254,23 +278,7 @@ users:
},
)
.await?;
/*
let mut still_creating = true;
while still_creating {
let instance = exoscale_rs::apis::instance_api::get_instance(
&self.configuration,
result.id.as_ref().unwrap(),
)
.await?
.clone();

if instance.state == Option::from(exoscale_rs::models::InstanceState::Running) {
still_creating = false;
} else {
std::thread::sleep(std::time::Duration::from_secs(5));
}
}*/
Ok(())
}
}
7 changes: 1 addition & 6 deletions src/options/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::env;
#[derive(Default)]
pub struct Options {
pub template: String,
pub zone: String,
pub instance_type: String,
pub disk_size: String,
pub machine_id: String,
Expand All @@ -13,27 +12,23 @@ pub struct Options {
pub fn from_env(init: bool) -> Options {
let template = from_env_or_error("TEMPLATE");

let zone = from_env_or_error("ZONE");

let instance_type = from_env_or_error("INSTANCE_TYPE");

let disk_size = from_env_or_error("DISK_SIZE");

if init {
return Options {
template,
zone,
instance_type,
disk_size,
..Default::default()
};
}
let mut machine_id = from_env_or_error("MACHINE_ID");
machine_id = format!("devpod-{}", machine_id);
machine_id = machine_id.to_string();
let machine_folder = from_env_or_error("MACHINE_FOLDER");
Options {
template,
zone,
instance_type,
disk_size,
machine_id,
Expand Down

0 comments on commit 72fa4d3

Please sign in to comment.