xo_api_client/
object_type.rs

1use jsonrpsee_types::JsonValue;
2
3/// Object type
4///
5/// This is most often used with [`crate::Client::get_objects_of_type`] to specify what type
6/// of objects to fetch
7///
8/// NOTE: This is only checked by running
9/// `xo-cli --list-objects --type | grep type | sort | uniq`
10/// on an existing XO-setup. Thus there may be more types
11// TODO: Check if there are more types
12#[derive(Debug)]
13pub enum ObjectType {
14    GpuGroup,
15
16    /// A virualization host, likely XCP-ng or similar
17    Host,
18    Message,
19    Network,
20
21    Pbd,
22    Pci,
23
24    /// Physical graphics card
25    Pgpu,
26
27    /// Physical network interface of a host
28    Pif,
29
30    /// Pool of hosts
31    Pool,
32
33    /// Storage repository - Place where the disks of VMs are stored ([`Self::Vdi`]s)
34    Sr,
35
36    Task,
37    Vbd,
38
39    /// Virtual disk, the disks of virtual machines
40    Vdi,
41    VdiSnapshot,
42    VdiUnmanaged,
43
44    /// Virtual network interface of a VM
45    Vif,
46
47    /// A virtual machine
48    Vm,
49    VmController,
50
51    /// Snapshot of a VM
52    VmSnapshot,
53
54    /// Virtual machine template, used to easily create preconfigured VMs
55    VmTemplate,
56}
57
58impl ToString for ObjectType {
59    fn to_string(&self) -> String {
60        match self {
61            ObjectType::GpuGroup => "gpuGroup",
62            ObjectType::Host => "host",
63            ObjectType::Message => "message",
64            ObjectType::Network => "network",
65            ObjectType::Pbd => "PBD",
66            ObjectType::Pci => "PCI",
67            ObjectType::Pgpu => "PGPU",
68            ObjectType::Pif => "PIF",
69            ObjectType::Pool => "pool",
70            ObjectType::Sr => "SR",
71            ObjectType::Task => "task",
72            ObjectType::Vbd => "VBD",
73            ObjectType::Vdi => "VDI",
74            ObjectType::VdiSnapshot => "VDI-snapshot",
75            ObjectType::VdiUnmanaged => "VDI-unmanaged",
76            ObjectType::Vif => "VIF",
77            ObjectType::Vm => "VM",
78            ObjectType::VmController => "VM-controller",
79            ObjectType::VmSnapshot => "VM-snapshot",
80            ObjectType::VmTemplate => "VM-template",
81        }
82        .to_string()
83    }
84}
85
86impl From<ObjectType> for JsonValue {
87    fn from(val: ObjectType) -> Self {
88        JsonValue::String(val.to_string())
89    }
90}