Skip to main content

microsandbox_db/entity/
cpu_allocation_cpu.rs

1//! Entity definition for logical processors reserved by active allocations.
2
3use sea_orm::entity::prelude::*;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// One guest vCPU assignment coordinated by a host allocation.
10#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
11#[sea_orm(table_name = "cpu_allocation_cpu")]
12pub struct Model {
13    /// Owning allocation identifier.
14    #[sea_orm(primary_key, auto_increment = false)]
15    pub allocation_id: String,
16    /// Guest vCPU index within the allocation.
17    #[sea_orm(primary_key, auto_increment = false)]
18    pub vcpu_index: i32,
19    /// Host logical processor selected for this vCPU. Multiple allocations may share it.
20    pub logical_cpu: i64,
21    /// Assignment role: `planned` before the OS acknowledgement, then `assigned` when confirmed.
22    pub role: String,
23}
24
25/// Relations for a CPU reservation.
26#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
27pub enum Relation {
28    /// The reserved processor belongs to one allocation.
29    #[sea_orm(
30        belongs_to = "super::cpu_allocation::Entity",
31        from = "Column::AllocationId",
32        to = "super::cpu_allocation::Column::Id",
33        on_delete = "Cascade"
34    )]
35    Allocation,
36}
37
38//--------------------------------------------------------------------------------------------------
39// Trait Implementations
40//--------------------------------------------------------------------------------------------------
41
42impl Related<super::cpu_allocation::Entity> for Entity {
43    fn to() -> RelationDef {
44        Relation::Allocation.def()
45    }
46}
47
48impl ActiveModelBehavior for ActiveModel {}