Skip to content

Commit

Permalink
add helpers to create flavor ovo and access fields
Browse files Browse the repository at this point in the history
this change disabled the builder interface and adds new types
and default impls to enabled constucting a flavor ovo with less
boiler plate.
  • Loading branch information
SeanMooney committed Mar 7, 2024
1 parent fe9a6f3 commit 5ba1efb
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 307 deletions.
297 changes: 0 additions & 297 deletions src/gen/flavor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ impl From<&FlavorVariant0NovaObjectData> for FlavorVariant0NovaObjectData {
value.clone()
}
}
impl FlavorVariant0NovaObjectData {
pub fn builder() -> builder::FlavorVariant0NovaObjectData {
Default::default()
}
}
#[doc = "FlavorVariant0NovaObjectDataDeleted"]
#[doc = r""]
#[doc = r" <details><summary>JSON schema</summary>"]
Expand Down Expand Up @@ -828,298 +823,6 @@ impl From<i64> for FlavorVariant0NovaObjectDataVcpus {
Self::Variant0(value)
}
}
pub mod builder {
#[derive(Clone, Debug)]
pub struct FlavorVariant0NovaObjectData {
created_at: Result<Option<chrono::DateTime<chrono::offset::Utc>>, String>,
deleted: Result<super::FlavorVariant0NovaObjectDataDeleted, String>,
deleted_at: Result<Option<chrono::DateTime<chrono::offset::Utc>>, String>,
description: Result<Option<String>, String>,
disabled: Result<super::FlavorVariant0NovaObjectDataDisabled, String>,
ephemeral_gb: Result<super::FlavorVariant0NovaObjectDataEphemeralGb, String>,
extra_specs: Result<super::FlavorVariant0NovaObjectDataExtraSpecs, String>,
flavorid: Result<super::FlavorVariant0NovaObjectDataFlavorid, String>,
id: Result<super::FlavorVariant0NovaObjectDataId, String>,
is_public: Result<super::FlavorVariant0NovaObjectDataIsPublic, String>,
memory_mb: Result<super::FlavorVariant0NovaObjectDataMemoryMb, String>,
name: Result<Option<String>, String>,
projects: Result<super::FlavorVariant0NovaObjectDataProjects, String>,
root_gb: Result<super::FlavorVariant0NovaObjectDataRootGb, String>,
rxtx_factor: Result<Option<f64>, String>,
swap: Result<super::FlavorVariant0NovaObjectDataSwap, String>,
updated_at: Result<Option<chrono::DateTime<chrono::offset::Utc>>, String>,
vcpu_weight: Result<Option<i64>, String>,
vcpus: Result<super::FlavorVariant0NovaObjectDataVcpus, String>,
}
impl Default for FlavorVariant0NovaObjectData {
fn default() -> Self {
Self {
created_at: Ok(Default::default()),
deleted: Err("no value supplied for deleted".to_string()),
deleted_at: Ok(Default::default()),
description: Ok(Default::default()),
disabled: Err("no value supplied for disabled".to_string()),
ephemeral_gb: Err("no value supplied for ephemeral_gb".to_string()),
extra_specs: Err("no value supplied for extra_specs".to_string()),
flavorid: Err("no value supplied for flavorid".to_string()),
id: Err("no value supplied for id".to_string()),
is_public: Err("no value supplied for is_public".to_string()),
memory_mb: Err("no value supplied for memory_mb".to_string()),
name: Ok(Default::default()),
projects: Err("no value supplied for projects".to_string()),
root_gb: Err("no value supplied for root_gb".to_string()),
rxtx_factor: Ok(super::defaults::flavor_variant0_nova_object_data_rxtx_factor()),
swap: Err("no value supplied for swap".to_string()),
updated_at: Ok(Default::default()),
vcpu_weight: Ok(Default::default()),
vcpus: Err("no value supplied for vcpus".to_string()),
}
}
}
impl FlavorVariant0NovaObjectData {
pub fn created_at<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<Option<chrono::DateTime<chrono::offset::Utc>>>,
T::Error: std::fmt::Display,
{
self.created_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for created_at: {}", e));
self
}
pub fn deleted<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataDeleted>,
T::Error: std::fmt::Display,
{
self.deleted = value
.try_into()
.map_err(|e| format!("error converting supplied value for deleted: {}", e));
self
}
pub fn deleted_at<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<Option<chrono::DateTime<chrono::offset::Utc>>>,
T::Error: std::fmt::Display,
{
self.deleted_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for deleted_at: {}", e));
self
}
pub fn description<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<Option<String>>,
T::Error: std::fmt::Display,
{
self.description = value
.try_into()
.map_err(|e| format!("error converting supplied value for description: {}", e));
self
}
pub fn disabled<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataDisabled>,
T::Error: std::fmt::Display,
{
self.disabled = value
.try_into()
.map_err(|e| format!("error converting supplied value for disabled: {}", e));
self
}
pub fn ephemeral_gb<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataEphemeralGb>,
T::Error: std::fmt::Display,
{
self.ephemeral_gb = value
.try_into()
.map_err(|e| format!("error converting supplied value for ephemeral_gb: {}", e));
self
}
pub fn extra_specs<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataExtraSpecs>,
T::Error: std::fmt::Display,
{
self.extra_specs = value
.try_into()
.map_err(|e| format!("error converting supplied value for extra_specs: {}", e));
self
}
pub fn flavorid<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataFlavorid>,
T::Error: std::fmt::Display,
{
self.flavorid = value
.try_into()
.map_err(|e| format!("error converting supplied value for flavorid: {}", e));
self
}
pub fn id<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataId>,
T::Error: std::fmt::Display,
{
self.id = value
.try_into()
.map_err(|e| format!("error converting supplied value for id: {}", e));
self
}
pub fn is_public<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataIsPublic>,
T::Error: std::fmt::Display,
{
self.is_public = value
.try_into()
.map_err(|e| format!("error converting supplied value for is_public: {}", e));
self
}
pub fn memory_mb<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataMemoryMb>,
T::Error: std::fmt::Display,
{
self.memory_mb = value
.try_into()
.map_err(|e| format!("error converting supplied value for memory_mb: {}", e));
self
}
pub fn name<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<Option<String>>,
T::Error: std::fmt::Display,
{
self.name = value
.try_into()
.map_err(|e| format!("error converting supplied value for name: {}", e));
self
}
pub fn projects<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataProjects>,
T::Error: std::fmt::Display,
{
self.projects = value
.try_into()
.map_err(|e| format!("error converting supplied value for projects: {}", e));
self
}
pub fn root_gb<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataRootGb>,
T::Error: std::fmt::Display,
{
self.root_gb = value
.try_into()
.map_err(|e| format!("error converting supplied value for root_gb: {}", e));
self
}
pub fn rxtx_factor<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<Option<f64>>,
T::Error: std::fmt::Display,
{
self.rxtx_factor = value
.try_into()
.map_err(|e| format!("error converting supplied value for rxtx_factor: {}", e));
self
}
pub fn swap<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataSwap>,
T::Error: std::fmt::Display,
{
self.swap = value
.try_into()
.map_err(|e| format!("error converting supplied value for swap: {}", e));
self
}
pub fn updated_at<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<Option<chrono::DateTime<chrono::offset::Utc>>>,
T::Error: std::fmt::Display,
{
self.updated_at = value
.try_into()
.map_err(|e| format!("error converting supplied value for updated_at: {}", e));
self
}
pub fn vcpu_weight<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<Option<i64>>,
T::Error: std::fmt::Display,
{
self.vcpu_weight = value
.try_into()
.map_err(|e| format!("error converting supplied value for vcpu_weight: {}", e));
self
}
pub fn vcpus<T>(mut self, value: T) -> Self
where
T: std::convert::TryInto<super::FlavorVariant0NovaObjectDataVcpus>,
T::Error: std::fmt::Display,
{
self.vcpus = value
.try_into()
.map_err(|e| format!("error converting supplied value for vcpus: {}", e));
self
}
}
impl std::convert::TryFrom<FlavorVariant0NovaObjectData> for super::FlavorVariant0NovaObjectData {
type Error = String;
fn try_from(value: FlavorVariant0NovaObjectData) -> Result<Self, String> {
Ok(Self {
created_at: value.created_at?,
deleted: value.deleted?,
deleted_at: value.deleted_at?,
description: value.description?,
disabled: value.disabled?,
ephemeral_gb: value.ephemeral_gb?,
extra_specs: value.extra_specs?,
flavorid: value.flavorid?,
id: value.id?,
is_public: value.is_public?,
memory_mb: value.memory_mb?,
name: value.name?,
projects: value.projects?,
root_gb: value.root_gb?,
rxtx_factor: value.rxtx_factor?,
swap: value.swap?,
updated_at: value.updated_at?,
vcpu_weight: value.vcpu_weight?,
vcpus: value.vcpus?,
})
}
}
impl From<super::FlavorVariant0NovaObjectData> for FlavorVariant0NovaObjectData {
fn from(value: super::FlavorVariant0NovaObjectData) -> Self {
Self {
created_at: Ok(value.created_at),
deleted: Ok(value.deleted),
deleted_at: Ok(value.deleted_at),
description: Ok(value.description),
disabled: Ok(value.disabled),
ephemeral_gb: Ok(value.ephemeral_gb),
extra_specs: Ok(value.extra_specs),
flavorid: Ok(value.flavorid),
id: Ok(value.id),
is_public: Ok(value.is_public),
memory_mb: Ok(value.memory_mb),
name: Ok(value.name),
projects: Ok(value.projects),
root_gb: Ok(value.root_gb),
rxtx_factor: Ok(value.rxtx_factor),
swap: Ok(value.swap),
updated_at: Ok(value.updated_at),
vcpu_weight: Ok(value.vcpu_weight),
vcpus: Ok(value.vcpus),
}
}
}
}
pub mod defaults {
pub(super) fn flavor_variant0_nova_object_data_rxtx_factor() -> Option<f64> {
Some(1.0_f64)
Expand Down
65 changes: 64 additions & 1 deletion src/gen/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
pub mod flavor;
pub mod flavor;

// a struct representing a gen::flavor::Flavor::Variant0
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, schemars::JsonSchema, Default)]
pub struct FlavorVariant0 {
#[serde(
rename = "nova_object.changes",
default,
skip_serializing_if = "Vec::is_empty"
)]
pub nova_object_changes: Vec<String>,
#[serde(rename = "nova_object.data")]
pub nova_object_data: flavor::FlavorVariant0NovaObjectData,
#[serde(rename = "nova_object.name")]
pub nova_object_name: String,
#[serde(rename = "nova_object.namespace")]
pub nova_object_namespace: String,
#[serde(rename = "nova_object.version")]
pub nova_object_version: String,
}

impl flavor::Flavor {
// a convert into trait implemation for gen::flavor::Flavor -> FlavorVariant0
pub fn into(self) -> FlavorVariant0 {
match self {
flavor::Flavor::Variant0 { nova_object_changes, nova_object_data, nova_object_name, nova_object_namespace, nova_object_version } => {
FlavorVariant0 {
nova_object_changes,
nova_object_data,
nova_object_name,
nova_object_namespace,
nova_object_version,
}
}
}
}

}

impl Default for flavor::FlavorVariant0NovaObjectData {
fn default() -> Self {
Self {
id: 0.into(),
name: None,
memory_mb: 0.into(),
vcpus: 0.into(),
root_gb: 0.into(),
ephemeral_gb: 0.into(),
flavorid: flavor::FlavorVariant0NovaObjectDataFlavorid::Variant0("".to_string()),
swap: 0.into(),
rxtx_factor: Some(1.0),
vcpu_weight: Some(1),
disabled: false.into(),
is_public: true.into(),
extra_specs: std::collections::HashMap::new().into(),
projects: vec![].into(),
description: None,
created_at: None,
updated_at: None,
deleted_at: None,
deleted: false.into(),
}
}
}
Loading

0 comments on commit 5ba1efb

Please sign in to comment.