Skip to content

Commit 244d646

Browse files
committed
rust 1.0.2
1 parent 264728f commit 244d646

File tree

4 files changed

+35
-20
lines changed

4 files changed

+35
-20
lines changed

rust/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "xnode-deployer"
33
description = "Deploy new Xnodes on several hardware providers"
4-
version = "1.0.1"
4+
version = "1.0.2"
55
edition = "2024"
66
repository = "https://github.com/Openmesh-Network/xnode-deployer"
77
license = "MIT"

rust/src/hivelocity/mod.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,6 @@ impl HivelocityDeployer {
5555
hardware,
5656
}
5757
}
58-
59-
pub async fn undeploy(&self, input: HivelocityUndeployInput) -> Option<Error> {
60-
let scope = match input {
61-
HivelocityUndeployInput::BareMetal { device_id } => {
62-
format!("bare-metal-devices/{device_id}")
63-
}
64-
HivelocityUndeployInput::Compute { device_id } => format!("compute/{device_id}"),
65-
};
66-
self.client
67-
.delete(format!("https://core.hivelocity.net/api/v2/{scope}"))
68-
.header("X-API-KEY", self.api_key.clone())
69-
.send()
70-
.await
71-
.err()
72-
.map(Error::ReqwestError)
73-
}
7458
}
7559

7660
impl XnodeDeployer for HivelocityDeployer {
@@ -81,7 +65,7 @@ impl XnodeDeployer for HivelocityDeployer {
8165
input: DeployInput,
8266
) -> Result<DeployOutput<Self::ProviderOutput>, Error> {
8367
log::info!(
84-
"Deploying Xnode with configuration {input:?} on {hardware:?}",
68+
"Hivelocity deployment of {input:?} on {hardware:?} started",
8569
hardware = self.hardware
8670
);
8771
let mut response = match &self.hardware {
@@ -125,6 +109,7 @@ impl XnodeDeployer for HivelocityDeployer {
125109
.header("X-API-KEY", self.api_key.clone())
126110
.send()
127111
.await
112+
.and_then(|response| response.error_for_status())
128113
.map_err(Error::ReqwestError)?
129114
.json::<serde_json::Value>()
130115
.await
@@ -197,6 +182,30 @@ impl XnodeDeployer for HivelocityDeployer {
197182
log::info!("Hivelocity deployment succeeded: {output:?}");
198183
Ok(output)
199184
}
185+
186+
async fn undeploy(&self, xnode: DeployOutput<Self::ProviderOutput>) -> Option<Error> {
187+
let device_id = xnode.provider.device_id;
188+
log::info!("Undeploying hivelocity device {device_id} started",);
189+
let scope = match self.hardware {
190+
HivelocityHardware::BareMetal { .. } => "bare-metal-devices",
191+
HivelocityHardware::Compute { .. } => "compute",
192+
};
193+
if let Err(e) = self
194+
.client
195+
.delete(format!(
196+
"https://core.hivelocity.net/api/v2/{scope}/{device_id}"
197+
))
198+
.header("X-API-KEY", self.api_key.clone())
199+
.send()
200+
.await
201+
.and_then(|response| response.error_for_status())
202+
{
203+
return Some(Error::ReqwestError(e));
204+
}
205+
206+
log::info!("Undeploying hivelocity device {device_id} succeeded");
207+
None
208+
}
200209
}
201210

202211
#[derive(Debug)]

rust/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ pub struct DeployOutput<ProviderOutput> {
2424
pub trait XnodeDeployer: Send + Sync {
2525
type ProviderOutput;
2626

27-
/// Decide who should be the current controller based on external data
27+
/// Provision new hardware with XnodeOS
2828
fn deploy(
2929
&self,
3030
input: DeployInput,
3131
) -> impl Future<Output = Result<DeployOutput<Self::ProviderOutput>, Error>> + Send;
32+
33+
/// Cancel renting of hardware
34+
fn undeploy(
35+
&self,
36+
xnode: DeployOutput<Self::ProviderOutput>,
37+
) -> impl Future<Output = Option<Error>> + Send;
3238
}
3339

3440
impl DeployInput {

0 commit comments

Comments
 (0)