-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate dedicated instance price and add tag tenancy and nested_vir…
…tualization
- Loading branch information
1 parent
af53cfe
commit a33f9f5
Showing
13 changed files
with
180 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,6 @@ | ||
[package] | ||
name = "osc-cost" | ||
version = "0.4.2" | ||
version = "0.5.0" | ||
edition = "2021" | ||
authors = ["OpenSource Team <[email protected]>"] | ||
license = "BSD-3-Clause" | ||
|
This file contains 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 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 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 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 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 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,41 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::{ResourceError, ResourceTrait, HOURS_PER_MONTH}; | ||
use crate::VERSION; | ||
|
||
#[derive(Serialize, Deserialize, Debug)] | ||
pub struct DedicatedInstance { | ||
pub osc_cost_version: Option<String>, | ||
pub account_id: Option<String>, | ||
pub read_date_rfc3339: Option<String>, | ||
pub region: Option<String>, | ||
pub price_per_hour: Option<f32>, | ||
pub price_per_month: Option<f32>, | ||
} | ||
|
||
impl ResourceTrait for DedicatedInstance { | ||
fn compute(&mut self) -> Result<(), ResourceError> { | ||
self.price_per_month = Some(self.price_per_hour.unwrap_or_default() * HOURS_PER_MONTH); | ||
Ok(()) | ||
} | ||
|
||
fn price_per_hour(&self) -> Result<f32, ResourceError> { | ||
match self.price_per_hour { | ||
Some(price) => Ok(price), | ||
None => Err(ResourceError::NotComputed), | ||
} | ||
} | ||
} | ||
|
||
impl Default for DedicatedInstance { | ||
fn default() -> Self { | ||
Self { | ||
osc_cost_version: Some(String::from(VERSION)), | ||
account_id: Some("".to_string()), | ||
read_date_rfc3339: Some("".to_string()), | ||
region: Some("".to_string()), | ||
price_per_hour: Some(0.0), | ||
price_per_month: Some(0.0), | ||
} | ||
} | ||
} |
This file contains 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 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 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,42 @@ | ||
use std::error; | ||
|
||
use log::{info, warn}; | ||
|
||
use crate::{ | ||
core::{dedicated_instances::DedicatedInstance, Resource, Resources}, | ||
VERSION, | ||
}; | ||
|
||
use super::Input; | ||
|
||
impl Input { | ||
pub fn fetch_dedicated_instances(&self) -> Result<(), Box<dyn error::Error>> { | ||
if self.use_dedicated_instance { | ||
info!("Use dedicated instance") | ||
} | ||
Ok(()) | ||
} | ||
pub fn fill_resource_dedicated_instances(&self, resources: &mut Resources) { | ||
if self.use_dedicated_instance { | ||
let Some(price_per_hour) = | ||
self.catalog_entry("TinaOS-FCU", "UseDedicated", "RunDedicatedInstances") | ||
else { | ||
warn!("warning: could not retrieve catalog for dedicated instance"); | ||
return; | ||
}; | ||
let core_resource = DedicatedInstance { | ||
osc_cost_version: Some(String::from(VERSION)), | ||
account_id: self.account_id(), | ||
read_date_rfc3339: self.fetch_date.map(|date| date.to_rfc3339()), | ||
region: self.region.clone(), | ||
price_per_hour: Some(price_per_hour), | ||
price_per_month: None, | ||
}; | ||
resources | ||
.resources | ||
.push(Resource::DedicatedInstance(core_resource)); | ||
} else { | ||
info!("Use default instance") | ||
} | ||
} | ||
} |
Oops, something went wrong.