Skip to content

Commit

Permalink
vmm: Prepare for static CPU template deprecation
Browse files Browse the repository at this point in the history
Add an implementation of conversion from `&CpuTemplateType` to
`Option<StaticCpuTemplate>`, which will be used in a successive commit
to deprecate the `cpu_template` field in the `/machine-config` API.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
  • Loading branch information
zulinx86 committed Sep 28, 2023
1 parent 65bef36 commit bf0b605
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/vmm/src/cpu_config/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub enum CpuTemplateType {
Static(StaticCpuTemplate),
}

// This conversion is only used for snapshot, but the static CPU template
// information has not been saved into snapshot since v1.1.
impl From<&Option<CpuTemplateType>> for StaticCpuTemplate {
fn from(value: &Option<CpuTemplateType>) -> Self {
match value {
Expand All @@ -72,6 +74,18 @@ impl From<&Option<CpuTemplateType>> for StaticCpuTemplate {
}
}

// This conversion will be used when converting `&VmConfig` to `MachineConfig`
// to respond `GET /machine-config` and `GET /vm`.
#[allow(dead_code)]
impl From<&CpuTemplateType> for StaticCpuTemplate {
fn from(value: &CpuTemplateType) -> Self {
match value {
CpuTemplateType::Static(template) => *template,
CpuTemplateType::Custom(_) => StaticCpuTemplate::None,
}
}
}

impl<'a> TryFrom<&'a [u8]> for CustomCpuTemplate {
type Error = serde_json::Error;

Expand Down

0 comments on commit bf0b605

Please sign in to comment.