lrzcc_wire/resources/
flavor.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use crate::common::display_option;
use crate::resources::FlavorGroupMinimal;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use std::fmt::Display;
use tabled::Tabled;

#[derive(Clone, Debug, Deserialize, Serialize, Tabled, PartialEq, FromRow)]
pub struct Flavor {
    #[sqlx(try_from = "i32")]
    pub id: u32,
    pub name: String,
    pub openstack_id: String, // UUIDv4
    #[tabled(display_with = "display_option")]
    #[sqlx(rename = "group_id")]
    pub group: Option<u32>,
    #[tabled(display_with = "display_option")]
    pub group_name: Option<String>,
    pub weight: u32,
}

impl Display for Flavor {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&format!("Flavor(id={}, name={})", self.id, self.name))
    }
}

#[derive(Clone, Debug, Deserialize, Serialize, Tabled, PartialEq, FromRow)]
pub struct FlavorMinimal {
    pub id: u32,
    pub name: String,
}

// TODO maybe rethink the Display implementations
impl Display for FlavorMinimal {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&format!("Flavor(id={}, name={})", self.id, self.name))
    }
}

#[derive(Clone, Debug, Deserialize, Serialize, Tabled, PartialEq)]
pub struct FlavorDetailed {
    pub id: u32,
    pub name: String,
    pub openstack_id: String, // UUIDv4
    #[tabled(display_with = "display_option")]
    pub group: Option<FlavorGroupMinimal>,
    #[tabled(display_with = "display_option")]
    pub group_name: Option<String>,
    pub weight: u32,
}

impl Display for FlavorDetailed {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&format!("Flavor(id={}, name={})", self.id, self.name))
    }
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FlavorListParams {
    pub all: Option<bool>,
    #[serde(rename = "flavorgroup")]
    pub group: Option<u32>,
}

#[derive(Clone, Debug, Deserialize, Serialize, Tabled, PartialEq)]
pub struct FlavorImport {
    pub new_flavor_count: u32,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FlavorCreateData {
    pub name: String,
    pub openstack_id: String, // UUIDv4
    #[serde(skip_serializing_if = "Option::is_none")]
    pub group: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub weight: Option<u32>,
}

impl FlavorCreateData {
    pub fn new(name: String, openstack_id: String) -> Self {
        Self {
            name,
            openstack_id,
            group: None,
            weight: None,
        }
    }
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FlavorModifyData {
    pub id: u32,

    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub openstack_id: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub group: Option<Option<u32>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub weight: Option<u32>,
}

impl FlavorModifyData {
    pub fn new(id: u32) -> Self {
        Self {
            id,
            name: None,
            openstack_id: None,
            group: None,
            weight: None,
        }
    }
}

#[derive(Clone, Debug, Deserialize, Serialize, Tabled)]
pub struct FlavorUsage {
    pub user_id: u32,
    pub user_name: String,
    pub flavor_id: u32,
    pub flavor_name: String,
    #[tabled(display_with = "display_option")]
    pub flavorgroup_id: Option<u32>,
    #[tabled(display_with = "display_option")]
    pub flavorgroup_name: Option<String>,
    pub count: u32,
    pub usage: u32,
}

#[derive(Clone, Debug, Deserialize, Serialize, Tabled)]
pub struct FlavorUsageAggregate {
    pub flavor_id: u32,
    pub flavor_name: String,
    #[tabled(display_with = "display_option")]
    pub flavorgroup_id: Option<u32>,
    #[tabled(display_with = "display_option")]
    pub flavorgroup_name: Option<String>,
    pub count: u32,
    pub usage: u32,
}