blob: bac841a43da21b2feeb02aa1acd1b06ebf0587bd [file] [log] [blame]
Jooyung Han347d9f22021-05-28 00:05:14 +09001// Copyright 2021, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! VM Payload Config
16
17use log::info;
18use serde::{Deserialize, Serialize};
Jooyung Han347d9f22021-05-28 00:05:14 +090019use std::io;
Jooyung Hanf48ceb42021-06-01 18:00:04 +090020use std::path::Path;
21use std::time::Duration;
22
23use crate::ioutil;
24
25const WAIT_TIMEOUT: Duration = Duration::from_secs(10);
Jooyung Han347d9f22021-05-28 00:05:14 +090026
27#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
28pub struct VmPayloadConfig {
29 #[serde(default)]
30 pub task: Option<Task>,
31}
32
33#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
34pub struct Task {
35 pub command: String,
36 #[serde(default)]
37 pub args: Vec<String>,
38}
39
40impl VmPayloadConfig {
Jooyung Hanf48ceb42021-06-01 18:00:04 +090041 pub fn load_from(path: &Path) -> io::Result<VmPayloadConfig> {
42 info!("loading config from {:?}...", path);
43 let file = ioutil::wait_for_file(path, WAIT_TIMEOUT)?;
Jooyung Han347d9f22021-05-28 00:05:14 +090044 Ok(serde_json::from_reader(file)?)
45 }
46}