vmm/vmm_config/
instance_info.rs

1// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3use std::fmt::{self, Display, Formatter};
4
5use serde::{Serialize, ser};
6
7/// Enumerates microVM runtime states.
8#[derive(Clone, Debug, Default, PartialEq, Eq)]
9pub enum VmState {
10    /// Vm not started (yet)
11    #[default]
12    NotStarted,
13    /// Vm is Paused
14    Paused,
15    /// Vm is running
16    Running,
17}
18
19impl Display for VmState {
20    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
21        match *self {
22            VmState::NotStarted => write!(f, "Not started"),
23            VmState::Paused => write!(f, "Paused"),
24            VmState::Running => write!(f, "Running"),
25        }
26    }
27}
28
29impl ser::Serialize for VmState {
30    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
31    where
32        S: ser::Serializer,
33    {
34        self.to_string().serialize(serializer)
35    }
36}
37
38/// Serializable struct that contains general information about the microVM.
39#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize)]
40pub struct InstanceInfo {
41    /// The ID of the microVM.
42    pub id: String,
43    /// Whether the microVM is not started/running/paused.
44    pub state: VmState,
45    /// The version of the VMM that runs the microVM.
46    pub vmm_version: String,
47    /// The name of the application that runs the microVM.
48    pub app_name: String,
49}