libredfish 0.2.0

A redfish library. Useful for querying server hardware from a BMC.
Documentation
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
/*
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */
use serde::{Deserialize, Serialize};

use super::{Firmware, ODataId, ODataLinks, ResourceStatus};

pub trait Hardware {
    fn odata_context(&self) -> String;
    fn odata_id(&self) -> String;
    fn odata_type(&self) -> String;
    fn description(&self) -> String;
    fn firmware_version(&self) -> Firmware;
    fn id(&self) -> String;
    fn location(&self) -> String;
    fn location_format(&self) -> String;
    fn model(&self) -> String;
    fn name(&self) -> String;
    fn serial_number(&self) -> String;
    fn status(&self) -> ResourceStatus;
    fn get_type(&self) -> HardwareType;
}

#[derive(Debug, Clone, Copy)]
pub enum HardwareType {
    ArrayController,
    DiskDrive,
    SmartArray,
    StorageEnclosure,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct HardwareCommon {
    #[serde(flatten)]
    pub odata: ODataLinks,
    pub description: String,
    pub id: String,
    pub firmware_version: Firmware,
    pub location: String,
    pub location_format: String,
    pub model: String,
    pub name: String,
    pub serial_number: String,
    pub status: ResourceStatus,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct ArrayController {
    pub adapter_type: String,
    pub backup_power_source_status: String,
    pub current_operating_mode: String,
    pub encryption_crypto_officer_password_set: bool,
    pub encryption_enabled: bool,
    pub encryption_fw_locked: bool,
    pub encryption_has_locked_volumes_missing_boot_password: bool,
    pub encryption_mixed_volumes_enabled: bool,
    pub encryption_standalone_mode_enabled: bool,
    pub external_port_count: i64,
    #[serde(flatten)]
    pub hardware_common: HardwareCommon,
    pub hardware_revision: String,
    pub internal_port_count: i64,

    #[serde(rename = "Type")]
    pub controller_type: String,
}

impl Hardware for ArrayController {
    fn odata_context(&self) -> String {
        self.hardware_common
            .odata
            .odata_context
            .as_deref()
            .unwrap_or("")
            .to_owned()
    }
    fn odata_id(&self) -> String {
        self.hardware_common.odata.odata_id.to_owned()
    }
    fn odata_type(&self) -> String {
        self.hardware_common.odata.odata_type.to_owned()
    }
    fn description(&self) -> String {
        self.hardware_common.description.to_owned()
    }
    fn firmware_version(&self) -> Firmware {
        self.hardware_common.firmware_version.to_owned()
    }
    fn id(&self) -> String {
        self.hardware_common.id.to_owned()
    }
    fn location(&self) -> String {
        self.hardware_common.location.to_owned()
    }
    fn location_format(&self) -> String {
        self.hardware_common.location_format.to_owned()
    }
    fn model(&self) -> String {
        self.hardware_common.model.to_owned()
    }
    fn name(&self) -> String {
        self.hardware_common.name.to_owned()
    }
    fn serial_number(&self) -> String {
        self.hardware_common.serial_number.to_owned()
    }
    fn status(&self) -> ResourceStatus {
        self.hardware_common.status
    }
    fn get_type(&self) -> HardwareType {
        HardwareType::ArrayController
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct MultHardware {
    #[serde(flatten)]
    pub odata: ODataLinks,
    pub description: String,
    pub member_type: String,
    pub members: Vec<ODataId>,
    #[serde(rename = "Members@odata.count")]
    pub members_odata_count: i64,
    pub name: String,
    pub total: i64,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct ArrayControllers {
    #[serde(flatten)]
    pub mult_hardware: MultHardware,
    #[serde(rename = "Type")]
    pub controller_type: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct SmartArray {
    pub adapter_type: String,
    pub backup_power_source_status: String,
    pub current_operating_mode: String,
    pub encryption_crypto_officer_password_set: bool,
    pub encryption_enabled: bool,
    pub encryption_fw_locked: bool,
    pub encryption_has_locked_volumes_missing_boot_password: bool,
    pub encryption_mixed_volumes_enabled: bool,
    pub encryption_standalone_mode_enabled: bool,
    pub external_port_count: i64,
    pub hardware_revision: String,
    #[serde(flatten)]
    pub hardware_common: HardwareCommon,
    pub internal_port_count: i64,
    #[serde(rename = "Type")]
    pub array_type: String,
}

impl Hardware for SmartArray {
    fn odata_context(&self) -> String {
        self.hardware_common
            .odata
            .odata_context
            .as_deref()
            .unwrap_or("")
            .to_owned()
    }
    fn odata_id(&self) -> String {
        self.hardware_common.odata.odata_id.to_owned()
    }
    fn odata_type(&self) -> String {
        self.hardware_common.odata.odata_type.to_owned()
    }
    fn description(&self) -> String {
        self.hardware_common.description.to_owned()
    }
    fn firmware_version(&self) -> Firmware {
        self.hardware_common.firmware_version.to_owned()
    }
    fn id(&self) -> String {
        self.hardware_common.id.to_owned()
    }
    fn location(&self) -> String {
        self.hardware_common.location.to_owned()
    }
    fn location_format(&self) -> String {
        self.hardware_common.location_format.to_owned()
    }
    fn model(&self) -> String {
        self.hardware_common.model.to_owned()
    }
    fn name(&self) -> String {
        self.hardware_common.name.to_owned()
    }
    fn serial_number(&self) -> String {
        self.hardware_common.serial_number.to_owned()
    }
    fn status(&self) -> ResourceStatus {
        self.hardware_common.status
    }
    fn get_type(&self) -> HardwareType {
        HardwareType::SmartArray
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct StorageEnclosure {
    pub drive_bay_count: i64,
    #[serde(flatten)]
    pub hardware_common: HardwareCommon,
    #[serde(rename = "Type")]
    pub enclosure_type: String,
}

impl Hardware for StorageEnclosure {
    fn odata_context(&self) -> String {
        self.hardware_common
            .odata
            .odata_context
            .as_deref()
            .unwrap_or("")
            .to_owned()
    }
    fn odata_id(&self) -> String {
        self.hardware_common.odata.odata_id.to_owned()
    }
    fn odata_type(&self) -> String {
        self.hardware_common.odata.odata_type.to_owned()
    }
    fn description(&self) -> String {
        self.hardware_common.description.to_owned()
    }
    fn firmware_version(&self) -> Firmware {
        self.hardware_common.firmware_version.to_owned()
    }
    fn id(&self) -> String {
        self.hardware_common.id.to_owned()
    }
    fn location(&self) -> String {
        self.hardware_common.location.to_owned()
    }
    fn location_format(&self) -> String {
        self.hardware_common.location_format.to_owned()
    }
    fn model(&self) -> String {
        self.hardware_common.model.to_owned()
    }
    fn name(&self) -> String {
        self.hardware_common.name.to_owned()
    }
    fn serial_number(&self) -> String {
        self.hardware_common.serial_number.to_owned()
    }
    fn status(&self) -> ResourceStatus {
        self.hardware_common.status
    }
    fn get_type(&self) -> HardwareType {
        HardwareType::StorageEnclosure
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct StorageEnclosures {
    #[serde(flatten)]
    pub mult_hardware: MultHardware,
    #[serde(rename = "Type")]
    pub enclosure_type: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct DiskDrive {
    pub block_size_bytes: i64,
    #[serde(rename = "CapacityGB")]
    pub capacity_gb: i64,
    pub capacity_logical_blocks: i64,
    pub capacity_mi_b: i64,
    pub carrier_application_version: String,
    pub carrier_authentication_status: String,
    pub current_temperature_celsius: i64,
    pub disk_drive_status_reasons: Vec<String>,
    pub encrypted_drive: bool,
    #[serde(flatten)]
    pub hardware_common: HardwareCommon,
    pub interface_speed_mbps: i64,
    pub interface_type: String,
    pub maximum_temperature_celsius: i64,
    pub media_type: String,
    pub power_on_hours: Option<i64>,
    pub rotational_speed_rpm: i64,
    pub ssd_endurance_utilization_percentage: Option<f64>,
    #[serde(rename = "Type")]
    pub drive_type: String,
}

impl Hardware for DiskDrive {
    fn odata_context(&self) -> String {
        self.hardware_common
            .odata
            .odata_context
            .as_deref()
            .unwrap_or("")
            .to_owned()
    }
    fn odata_id(&self) -> String {
        self.hardware_common.odata.odata_id.to_owned()
    }
    fn odata_type(&self) -> String {
        self.hardware_common.odata.odata_type.to_owned()
    }
    fn description(&self) -> String {
        self.hardware_common.description.to_owned()
    }
    fn firmware_version(&self) -> Firmware {
        self.hardware_common.firmware_version.to_owned()
    }
    fn id(&self) -> String {
        self.hardware_common.id.to_owned()
    }
    fn location(&self) -> String {
        self.hardware_common.location.to_owned()
    }
    fn location_format(&self) -> String {
        self.hardware_common.location_format.to_owned()
    }
    fn model(&self) -> String {
        self.hardware_common.model.to_owned()
    }
    fn name(&self) -> String {
        self.hardware_common.name.to_owned()
    }
    fn serial_number(&self) -> String {
        self.hardware_common.serial_number.to_owned()
    }
    fn status(&self) -> ResourceStatus {
        self.hardware_common.status
    }
    fn get_type(&self) -> HardwareType {
        HardwareType::DiskDrive
    }
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct DiskDrives {
    #[serde(flatten)]
    pub mult_hardware: MultHardware,
    #[serde(rename = "Type")]
    pub drive_type: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct LogicalDrives {
    #[serde(flatten)]
    pub odata: ODataLinks,
    pub description: String,
    pub member_type: String,
    #[serde(rename = "Members@odata.count")]
    pub members_odata_count: i64,
    pub name: String,
    pub total: i64,
    #[serde(rename = "Type")]
    pub drive_type: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct StorageSubsystem {
    #[serde(flatten)]
    pub odata: ODataLinks,
    pub description: Option<String>,
    pub members: Option<Vec<ODataId>>,
    #[serde(rename = "Members@odata.count")]
    pub members_odata_count: Option<i64>,
    pub name: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct Storage {
    #[serde(flatten)]
    pub odata: ODataLinks,
    pub id: Option<String>,
    pub name: Option<String>,
    pub description: Option<String>,
    pub drives: Option<Vec<ODataId>>,
    pub volumes: Option<ODataId>,
    pub status: Option<ResourceStatus>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct OemSmc {
    #[serde(flatten)]
    pub temperature: Option<f64>,
    pub percentage_drive_life_used: Option<f64>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct Oem {
    #[serde(flatten)]
    pub supermicro: Option<OemSmc>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct Drives {
    #[serde(flatten)]
    pub odata: ODataLinks,
    pub capacity_bytes: Option<i64>,
    pub failure_predicted: Option<bool>,
    pub predicted_media_life_left_percent: Option<f64>,
    pub oem: Option<Oem>,
    pub id: Option<String>,
    pub manufacturer: Option<String>,
    pub model: Option<String>,
    pub name: Option<String>,
    pub revision: Option<String>,
    pub serial_number: Option<String>,
    pub status: Option<ResourceStatus>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct DriveCollection {
    #[serde(flatten)]
    pub odata: ODataLinks,
    pub members: Vec<ODataId>,
    #[serde(rename = "Members@odata.count")]
    pub members_odata_count: i32,
    pub name: String,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct SimpleStorage {
    #[serde(flatten)]
    pub odata: ODataLinks,
    pub id: String,
    pub name: String,
    pub devices: Option<Vec<StorageDevice>>,
    pub description: Option<String>,
    pub status: Option<ResourceStatus>,
    pub uefi_device_path: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "PascalCase")]
pub struct StorageDevice {
    capacity_bytes: Option<i64>,
    manufacturer: Option<String>,
    model: Option<String>,
    name: String,
    status: Option<ResourceStatus>,
}

#[cfg(test)]
mod test {
    #[test]
    fn test_storage_logical_drives_parser() {
        let test_data = include_str!("testdata/logical-drives.json");
        let result: super::LogicalDrives = serde_json::from_str(test_data).unwrap();
        println!("result: {result:#?}");
    }

    #[test]
    fn test_array_controller_parser() {
        let test_data = include_str!("testdata/array-controller.json");
        let result: super::ArrayController = serde_json::from_str(test_data).unwrap();
        println!("result: {result:#?}");
    }

    #[test]
    fn test_storage_drives_parser() {
        let test_data = include_str!("testdata/disk-drives.json");
        let result: super::DiskDrives = serde_json::from_str(test_data).unwrap();
        println!("result: {result:#?}");
    }

    #[test]
    fn test_storage_drive_parser() {
        let test_data = include_str!("testdata/disk-drive.json");
        let result: super::DiskDrive = serde_json::from_str(test_data).unwrap();
        println!("result: {result:#?}");
    }

    #[test]
    fn test_array_controllers_parser() {
        let test_data = include_str!("testdata/array-controllers.json");
        let result: super::ArrayControllers = serde_json::from_str(test_data).unwrap();
        println!("result: {result:#?}");
    }

    #[test]
    fn test_smart_array_parser() {
        let test_data = include_str!("testdata/smart-array.json");
        let result: super::SmartArray = serde_json::from_str(test_data).unwrap();
        println!("result: {result:#?}");
    }

    #[test]
    fn test_storage_enclosure_parser() {
        let test_data = include_str!("testdata/storage-enclosure.json");
        let result: super::StorageEnclosure = serde_json::from_str(test_data).unwrap();
        println!("result: {result:#?}");
    }

    #[test]
    fn test_storage_enclosures_parser() {
        let test_data = include_str!("testdata/storage-enclosures.json");
        let result: super::StorageEnclosures = serde_json::from_str(test_data).unwrap();
        println!("result: {result:#?}");
    }
}