1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/openeuler-stratovirt

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
В этом репозитории не указан файл с открытой лицензией (LICENSE). При использовании обратитесь к конкретному описанию проекта и его зависимостям в коде.
Клонировать/Скачать
qmp_schema.rs 59 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
Jinhao Gao Отправлено 2 лет назад 3099450
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342
// Copyright (c) 2020 Huawei Technologies Co.,Ltd. All rights reserved.
//
// StratoVirt is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan
// PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
// http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
// KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.
use serde::{Deserialize, Serialize};
pub use serde_json::Value as Any;
use strum_macros::{EnumIter, EnumString, EnumVariantNames};
use super::Version;
use crate::qmp::{Command, Empty, TimeStamp};
/// A error enum for qmp
#[allow(clippy::upper_case_acronyms)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum QmpErrorClass {
#[serde(rename = "GenericError")]
GenericError(String),
#[serde(rename = "CommandNotFound")]
CommandNotFound(String),
#[serde(rename = "DeviceNotActive")]
DeviceNotActive(String),
#[serde(rename = "DeviceNotFound")]
DeviceNotFound(String),
#[serde(rename = "KVMMissingCap")]
KVMMissingCap(String),
#[serde(rename = "OperationThrottled")]
OperationThrottled(u64),
}
impl QmpErrorClass {
pub fn to_content(&self) -> String {
match self {
QmpErrorClass::GenericError(s) => s.to_string(),
QmpErrorClass::CommandNotFound(s) => s.to_string(),
QmpErrorClass::DeviceNotActive(s) => s.to_string(),
QmpErrorClass::DeviceNotFound(s) => s.to_string(),
QmpErrorClass::KVMMissingCap(s) => s.to_string(),
QmpErrorClass::OperationThrottled(nr) => {
format!("More than {} requests received during 1 second", nr)
}
}
}
}
/// A enum to store all command struct
#[derive(Debug, Clone, Serialize, Deserialize, EnumIter, EnumVariantNames, EnumString)]
#[serde(tag = "execute")]
#[serde(deny_unknown_fields)]
pub enum QmpCommand {
#[serde(rename = "qmp_capabilities")]
qmp_capabilities {
#[serde(default)]
arguments: qmp_capabilities,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
quit {
#[serde(default)]
arguments: quit,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
stop {
#[serde(default)]
arguments: stop,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
cont {
#[serde(default)]
arguments: cont,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
device_add {
arguments: Box<device_add>,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
device_del {
arguments: device_del,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "chardev-add")]
chardev_add {
arguments: chardev_add,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "chardev-remove")]
chardev_remove {
arguments: chardev_remove,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
netdev_add {
arguments: Box<netdev_add>,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
netdev_del {
arguments: netdev_del,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-hotpluggable-cpus")]
#[strum(serialize = "query-hotpluggable-cpus")]
query_hotpluggable_cpus {
#[serde(default)]
arguments: query_hotpluggable_cpus,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-cpus")]
#[strum(serialize = "query-cpus")]
query_cpus {
#[serde(default)]
arguments: query_cpus,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-status")]
query_status {
#[serde(default)]
arguments: query_status,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
getfd {
arguments: getfd,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "blockdev-add")]
blockdev_add {
arguments: Box<blockdev_add>,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "blockdev-del")]
blockdev_del {
arguments: blockdev_del,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "balloon")]
balloon {
#[serde(default)]
arguments: balloon,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-balloon")]
query_balloon {
#[serde(default)]
arguments: query_balloon,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "migrate")]
migrate {
arguments: migrate,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-migrate")]
query_migrate {
#[serde(default)]
arguments: query_migrate,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "migrate_cancel")]
cancel_migrate {
#[serde(default)]
arguments: cancel_migrate,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-version")]
query_version {
#[serde(default)]
arguments: query_version,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-commands")]
query_commands {
#[serde(default)]
arguments: query_commands,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-target")]
query_target {
#[serde(default)]
arguments: query_target,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-kvm")]
query_kvm {
#[serde(default)]
arguments: query_kvm,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-machines")]
query_machines {
#[serde(default)]
arguments: query_machines,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-events")]
#[strum(serialize = "query-events")]
query_events {
#[serde(default)]
arguments: query_events,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "qom-list-types")]
list_type {
#[serde(default)]
arguments: list_type,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "device-list-properties")]
device_list_properties {
#[serde(default)]
arguments: device_list_properties,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "block-commit")]
#[strum(serialize = "block-commit")]
block_commit {
#[serde(default)]
arguments: block_commit,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-tpm-models")]
query_tpm_models {
#[serde(default)]
arguments: query_tpm_models,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-tpm-types")]
query_tpm_types {
#[serde(default)]
arguments: query_tpm_types,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-command-line-options")]
query_command_line_options {
#[serde(default)]
arguments: query_command_line_options,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-migrate-capabilities")]
query_migrate_capabilities {
#[serde(default)]
arguments: query_migrate_capabilities,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-qmp-schema")]
query_qmp_schema {
#[serde(default)]
arguments: query_qmp_schema,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-sev-capabilities")]
query_sev_capabilities {
#[serde(default)]
arguments: query_sev_capabilities,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-chardev")]
#[strum(serialize = "query-chardev")]
query_chardev {
#[serde(default)]
arguments: query_chardev,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "qom-list")]
#[strum(serialize = "qom-list")]
qom_list {
#[serde(default)]
arguments: qom_list,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "qom_get")]
#[strum(serialize = "qom_get")]
qom_get {
#[serde(default)]
arguments: qom_get,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-block")]
#[strum(serialize = "query-block")]
query_block {
#[serde(default)]
arguments: query_block,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-named-block-nodes")]
#[strum(serialize = "query-named-block-nodes")]
query_named_block_nodes {
#[serde(default)]
arguments: query_named_block_nodes,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-blockstats")]
#[strum(serialize = "query-blockstats")]
query_blockstats {
#[serde(default)]
arguments: query_blockstats,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-block-jobs")]
#[strum(serialize = "query-block-jobs")]
query_block_jobs {
#[serde(default)]
arguments: query_block_jobs,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-gic-capabilities")]
#[strum(serialize = "query-gic-capabilities")]
query_gic_capabilities {
#[serde(default)]
arguments: query_gic_capabilities,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
#[serde(rename = "query-iothreads")]
#[strum(serialize = "query-iothreads")]
query_iothreads {
#[serde(default)]
arguments: query_iothreads,
#[serde(default, skip_serializing_if = "Option::is_none")]
id: Option<String>,
},
}
/// qmp_capabilities
///
/// Enable QMP capabilities.
///
/// # Examples
///
/// ```text
/// -> { "execute": "qmp_capabilities" }
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct qmp_capabilities {}
impl Command for qmp_capabilities {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// quit
///
/// This command will cause the StratoVirt process to exit gracefully. While every
/// attempt is made to send the QMP response before terminating, this is not
/// guaranteed. When using this interface, a premature EOF would not be
/// unexpected.
///
/// # Examples
///
/// ```text
/// -> { "execute": "quit" }
/// <- { "return": {}}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct quit {}
impl Command for quit {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// stop
///
/// Stop all guest VCPU execution
///
/// # Examples
///
/// ```text
/// -> { "execute": "stop" }
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct stop {}
impl Command for stop {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// cont
///
/// Resume guest VCPU execution.
///
/// # Examples
///
/// ```text
/// -> { "execute": "cont" }
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct cont {}
impl Command for cont {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// device_add
///
/// # Arguments
///
/// * `id` - the device's ID, must be unique.
/// * `driver` - the name of the new device's driver.
/// * `addr` - the address device insert into.
///
/// Additional arguments depend on the type.
///
/// # Examples
///
/// ```text
/// -> { "execute": "device_add",
/// "arguments": { "id": "net-0", "driver": "virtio-net-mmio", "addr": "0x0"}}
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct device_add {
#[serde(rename = "id")]
pub id: String,
#[serde(rename = "driver")]
pub driver: String,
#[serde(rename = "addr")]
pub addr: Option<String>,
#[serde(rename = "lun")]
pub lun: Option<usize>,
#[serde(rename = "drive")]
pub drive: Option<String>,
#[serde(rename = "romfile")]
pub romfile: Option<String>,
#[serde(rename = "share-rw")]
pub share: Option<String>,
#[serde(rename = "bus")]
pub bus: Option<String>,
#[serde(rename = "mac")]
pub mac: Option<String>,
#[serde(rename = "netdev")]
pub netdev: Option<String>,
#[serde(rename = "disable-modern")]
pub disable_modern: Option<String>,
#[serde(rename = "mq")]
pub mq: Option<String>,
#[serde(rename = "vectors")]
pub vectors: Option<String>,
#[serde(rename = "serial")]
pub serial_num: Option<String>,
pub iothread: Option<String>,
pub multifunction: Option<bool>,
pub host: Option<String>,
#[serde(rename = "num-queues")]
pub queues: Option<u16>,
pub boot_index: Option<u8>,
pub sysfsdev: Option<String>,
}
pub type DeviceAddArgument = device_add;
impl Command for device_add {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct FileOptions {
pub driver: String,
pub filename: String,
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct CacheOptions {
#[serde(rename = "no-flush")]
pub no_flush: Option<bool>,
pub direct: Option<bool>,
}
/// blockdev_add
///
/// # Arguments
///
/// * `node_name` - the device's ID, must be unique.
/// * `file` - the backend file information.
/// * `cache` - if use direct io.
/// * `read_only` - if readonly.
///
/// Additional arguments depend on the type.
///
/// # Examples
///
/// ```text
/// -> { "execute": "blockdev_add",
/// "arguments": {"node-name": "drive-0",
/// "file": {"driver": "file", "filename": "/path/to/block"},
/// "cache": {"direct": true}, "read-only": false }}
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct blockdev_add {
#[serde(rename = "node-name")]
pub node_name: String,
pub file: FileOptions,
pub cache: Option<CacheOptions>,
#[serde(rename = "read-only")]
pub read_only: Option<bool>,
#[serde(rename = "read-zeros")]
pub read_zeros: Option<bool>,
pub driver: Option<String>,
pub backing: Option<String>,
pub discard: Option<String>,
pub id: Option<String>,
pub options: Option<String>,
#[serde(rename = "throttling.iops-total")]
pub iops: Option<u64>,
}
pub type BlockDevAddArgument = blockdev_add;
impl Command for blockdev_add {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// netdev_add
///
/// # Arguments
///
/// * `id` - the device's ID, must be unique.
/// * `ifname` - the backend tap dev name.
/// * `fds` - the file fd opened by upper level.
///
/// Additional arguments depend on the type.
///
/// # Examples
///
/// ```text
/// -> { "execute": "netdev_add",
/// "arguments": {"id": "net-0", "ifname": "tap0", "fds": 123 }}
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct netdev_add {
pub id: String,
#[serde(rename = "ifname")]
pub if_name: Option<String>,
pub fds: Option<String>,
pub dnssearch: Option<String>,
#[serde(rename = "type")]
pub net_type: Option<String>,
pub vhost: Option<String>,
pub vhostfds: Option<String>,
pub ifname: Option<String>,
pub downscript: Option<String>,
pub script: Option<String>,
pub queues: Option<u16>,
pub chardev: Option<String>,
}
pub type NetDevAddArgument = netdev_add;
impl Command for netdev_add {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AddrDataOptions {
pub path: String,
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AddrOptions {
#[serde(rename = "type")]
pub addr_type: String,
#[serde(rename = "data")]
pub addr_data: AddrDataOptions,
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct BackendDataOptions {
pub addr: AddrOptions,
pub server: bool,
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct BackendOptions {
#[serde(rename = "type")]
pub backend_type: String,
#[serde(rename = "data")]
pub backend_data: BackendDataOptions,
}
/// chardev-add
///
/// # Arguments
///
/// * `id` - the character device's ID, must be unique.
/// * `backend` - the chardev backend info.
///
/// Additional arguments depend on the type.
///
/// # Examples
///
/// ```text
/// -> { "execute": "chardev-add",
/// "arguments": { "id": "chardev_id", "backend": { "type": "socket", "data": {
/// "addr": { "type": "unix", "data": { "path": "/path/to/socket" } },
/// "server": false }}}}
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct chardev_add {
pub id: String,
pub backend: BackendOptions,
}
pub type CharDevAddArgument = chardev_add;
impl Command for chardev_add {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// chardev-remove
///
/// Remove a chardev backend.
///
/// # Arguments
///
/// * `id` - The ID of the character device.
///
/// # Errors
///
/// If `id` is not a valid chardev backend, DeviceNotFound
///
/// # Examples
///
/// ```text
/// -> { "execute": "chardev-remove", "arguments": { "id": "chardev_id" } }
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct chardev_remove {
pub id: String,
}
impl Command for chardev_remove {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// device_del
///
/// Remove a device from a guest
///
/// # Arguments
///
/// * `id` - the device's ID or QOM path.
///
/// # Errors
///
/// If `id` is not a valid device, DeviceNotFound.
///
/// # Notes
///
/// When this command completes, the device may not be removed from the
/// guest. Hot removal is an operation that requires guest cooperation.
/// This command merely requests that the guest begin the hot removal
/// process. Completion of the device removal process is signaled with a
/// DEVICE_DELETED event. Guest reset will automatically complete removal
/// for all devices.
///
/// # Examples
///
/// ```text
/// -> { "execute": "device_del",
/// "arguments": { "id": "net-0" } }
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct device_del {
pub id: String,
}
impl Command for device_del {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct blockdev_del {
#[serde(rename = "node-name")]
pub node_name: String,
}
impl Command for blockdev_del {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// netdev_del
///
/// Remove a network backend.
///
/// # Arguments
///
/// * `id` - The name of the network backend to remove.
///
/// # Errors
///
/// If `id` is not a valid network backend, DeviceNotFound
///
/// # Examples
///
/// ```text
/// -> { "execute": "netdev_del", "arguments": { "id": "net-0" } }
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct netdev_del {
pub id: String,
}
impl Command for netdev_del {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// query-hotpluggable-cpus:
///
/// # Returns
///
/// A list of Hotpluggable CPU objects.
///
/// # Examples
///
/// For pc machine type started with -smp 1,maxcpus=2:
/// ```text
/// -> { "execute": "query-hotpluggable-cpus" }
/// <- {"return": [
/// {
/// "type": host-x-cpu", "vcpus-count": 1,
/// "props": {"core-id": 0, "socket-id": 1, "thread-id": 0}
/// },
/// {
/// "qom-path": "/machine/unattached/device[0]",
/// "type": "host-x-cpu", "vcpus-count": 1,
/// "props": {"core-id": 0, "socket-id": 0, "thread-id": 0}
/// }
/// ]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct query_hotpluggable_cpus {}
impl Command for query_hotpluggable_cpus {
type Res = Vec<HotpluggableCPU>;
fn back(self) -> Vec<HotpluggableCPU> {
Default::default()
}
}
#[allow(clippy::upper_case_acronyms)]
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct HotpluggableCPU {
#[serde(rename = "type")]
pub type_: String,
#[serde(rename = "vcpus-count")]
pub vcpus_count: isize,
#[serde(rename = "props")]
pub props: CpuInstanceProperties,
#[serde(rename = "qom-path", default, skip_serializing_if = "Option::is_none")]
pub qom_path: Option<String>,
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CpuInstanceProperties {
#[serde(rename = "node-id", default, skip_serializing_if = "Option::is_none")]
pub node_id: Option<isize>,
#[serde(rename = "socket-id", default, skip_serializing_if = "Option::is_none")]
pub socket_id: Option<isize>,
#[cfg(target_arch = "x86_64")]
#[serde(rename = "die_id", default, skip_serializing_if = "Option::is_none")]
pub die_id: Option<isize>,
#[cfg(target_arch = "aarch64")]
#[serde(
rename = "cluster_id",
default,
skip_serializing_if = "Option::is_none"
)]
pub cluster_id: Option<isize>,
#[serde(rename = "thread-id", default, skip_serializing_if = "Option::is_none")]
pub thread_id: Option<isize>,
#[serde(rename = "core-id", default, skip_serializing_if = "Option::is_none")]
pub core_id: Option<isize>,
}
/// query-cpus:
///
/// This command causes vCPU threads to exit to userspace, which causes
/// a small interruption to guest CPU execution. This will have a negative
/// impact on realtime guests and other latency sensitive guest workloads.
/// It is recommended to use @query-cpus-fast instead of this command to
/// avoid the vCPU interruption.
///
/// # Returns
///
/// A list of information about each virtual CPU.
///
/// # Examples
///
/// ```text
/// -> { "execute": "query-cpus" }
/// <- { "return": [
/// {
/// "CPU":0,
/// "current":true,
/// "halted":false,
/// "qom_path":"/machine/unattached/device[0]",
/// "arch":"x86",
/// "thread_id":3134
/// },
/// {
/// "CPU":1,
/// "current":false,
/// "halted":true,
/// "qom_path":"/machine/unattached/device[2]",
/// "arch":"x86",
/// "thread_id":3135
/// }
/// ]
/// }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct query_cpus {}
impl Command for query_cpus {
type Res = Vec<CpuInfo>;
fn back(self) -> Vec<CpuInfo> {
Default::default()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CpuInfoCommon {
#[serde(rename = "current")]
pub current: bool,
#[serde(rename = "qom_path")]
pub qom_path: String,
#[serde(rename = "halted")]
pub halted: bool,
#[serde(rename = "props", default, skip_serializing_if = "Option::is_none")]
pub props: Option<CpuInstanceProperties>,
#[serde(rename = "CPU")]
pub CPU: isize,
#[serde(rename = "thread_id")]
pub thread_id: isize,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "arch")]
pub enum CpuInfo {
#[serde(rename = "x86")]
x86 {
#[serde(flatten)]
common: CpuInfoCommon,
#[serde(flatten)]
#[serde(rename = "x86")]
x86: CpuInfoX86,
},
#[serde(rename = "arm")]
Arm {
#[serde(flatten)]
common: CpuInfoCommon,
#[serde(flatten)]
#[serde(rename = "Arm")]
arm: CpuInfoArm,
},
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CpuInfoX86 {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CpuInfoArm {}
/// query-status
///
/// Query the run status of all VCPUs.
///
/// # Returns
///
/// `StatusInfo` reflecting all VCPUs.
///
/// # Examples
///
/// ```text
/// -> { "execute": "query-status" }
/// <- { "return": { "running": true,
/// "singlestep": false,
/// "status": "running" } }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct query_status {}
impl Command for query_status {
type Res = StatusInfo;
fn back(self) -> StatusInfo {
Default::default()
}
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct StatusInfo {
#[serde(rename = "singlestep")]
pub singlestep: bool,
#[serde(rename = "running")]
pub running: bool,
#[serde(rename = "status")]
pub status: RunState,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RunState {
#[serde(rename = "debug")]
debug,
#[serde(rename = "inmigrate")]
inmigrate,
#[serde(rename = "internal-error")]
internal_error,
#[serde(rename = "io-error")]
io_error,
#[serde(rename = "paused")]
paused,
#[serde(rename = "postmigrate")]
postmigrate,
#[serde(rename = "prelaunch")]
prelaunch,
#[serde(rename = "finish-migrate")]
finish_migrate,
#[serde(rename = "restore-vm")]
restore_vm,
#[serde(rename = "running")]
running,
#[serde(rename = "save-vm")]
save_vm,
#[serde(rename = "shutdown")]
shutdown,
#[serde(rename = "suspended")]
suspended,
#[serde(rename = "watchdog")]
watchdog,
#[serde(rename = "guest-panicked")]
guest_panicked,
#[serde(rename = "colo")]
colo,
#[serde(rename = "preconfig")]
preconfig,
}
impl Default for RunState {
fn default() -> Self {
RunState::debug
}
}
/// migrate
///
/// Migrates the current running guest to another VM or file.
///
/// # Arguments
///
/// * `uri` - the Uniform Resource Identifier of the destination VM or file.
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct migrate {
#[serde(rename = "uri")]
pub uri: String,
}
impl Command for migrate {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// query-migrate:
///
/// Returns information about current migration.
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_migrate {}
impl Command for query_migrate {
type Res = MigrationInfo;
fn back(self) -> MigrationInfo {
Default::default()
}
}
/// cancel-migrate:
///
/// Cancel migrate the current VM.
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct cancel_migrate {}
impl Command for cancel_migrate {
type Res = MigrationInfo;
fn back(self) -> MigrationInfo {
Default::default()
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct MigrationInfo {
#[serde(rename = "status", default, skip_serializing_if = "Option::is_none")]
pub status: Option<String>,
}
/// getfd
///
/// Receive a file descriptor via SCM rights and assign it a name
///
/// # Arguments
///
/// * `fdname` - File descriptor name.
///
/// # Examples
///
/// ```text
/// -> { "execute": "getfd", "arguments": { "fdname": "fd1" } }
/// <- { "return": {} }
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct getfd {
#[serde(rename = "fdname")]
pub fd_name: String,
}
impl Command for getfd {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// Shutdown
///
/// Emitted when the virtual machine has shut down, indicating that StratoVirt is
/// about to exit.
///
/// # Notes
///
/// If the command-line option "-no-shutdown" has been specified, StratoVirt
/// will not exit, and a STOP event will eventually follow the SHUTDOWN event
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct Shutdown {
/// If true, the shutdown was triggered by a guest request (such as
/// a guest-initiated ACPI shutdown request or other hardware-specific
/// action) rather than a host request (such as sending StratoVirt a SIGINT).
#[serde(rename = "guest")]
pub guest: bool,
pub reason: String,
}
/// Reset
///
/// Emitted when the virtual machine is reset
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct Reset {
/// If true, the reset was triggered by a guest request (such as
/// a guest-initiated ACPI reboot request or other hardware-specific action
/// ) rather than a host request (such as the QMP command system_reset).
#[serde(rename = "guest")]
pub guest: bool,
}
/// Stop
///
/// Emitted when the virtual machine is stopped
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct Stop {}
/// Resume
///
/// Emitted when the virtual machine resumes execution
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct Resume {}
/// DeviceDeleted
///
/// Emitted whenever the device removal completion is acknowledged by the guest.
/// At this point, it's safe to reuse the specified device ID. Device removal can
/// be initiated by the guest or by HMP/QMP commands.
///
/// # Examples
///
/// ```text
/// <- { "event": "DEVICE_DELETED",
/// "data": { "device": "virtio-net-mmio-0",
/// "path": "/machine/peripheral/virtio-net-mmio-0" },
/// "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct DeviceDeleted {
/// Device name.
#[serde(rename = "device", default, skip_serializing_if = "Option::is_none")]
pub device: Option<String>,
/// Device path.
#[serde(rename = "path")]
pub path: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, EnumIter, EnumVariantNames, EnumString)]
#[serde(tag = "event")]
pub enum QmpEvent {
#[serde(rename = "SHUTDOWN")]
Shutdown {
data: Shutdown,
timestamp: TimeStamp,
},
#[serde(rename = "RESET")]
Reset { data: Reset, timestamp: TimeStamp },
#[serde(rename = "STOP")]
Stop {
#[serde(default)]
data: Stop,
timestamp: TimeStamp,
},
#[serde(rename = "RESUME")]
Resume {
#[serde(default)]
data: Resume,
timestamp: TimeStamp,
},
#[serde(rename = "DEVICE_DELETED")]
DeviceDeleted {
data: DeviceDeleted,
timestamp: TimeStamp,
},
#[serde(rename = "BALLOON_CHANGED")]
BalloonChanged {
data: BalloonInfo,
timestamp: TimeStamp,
},
}
/// query-balloon:
///
/// Query the actual size of memory of VM.
///
/// # Returns
///
/// `BalloonInfo` includs the actual size of memory
///
/// # Example
///
/// ```text
/// -> { "execute": "query-balloon" }
/// <- {"return":{"actual":8589934592}}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_balloon {}
impl Command for query_balloon {
type Res = BalloonInfo;
fn back(self) -> BalloonInfo {
Default::default()
}
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct BalloonInfo {
pub actual: u64,
}
/// balloon:
///
/// Advice VM to change memory size with the argument `value`.
///
/// # Arguments
///
/// * `value` - Memoey size.
///
/// # Notes
///
/// This is only an advice instead of command to VM,
/// therefore, the VM changes its memory according to `value` and its condation.
///
/// # Example
///
/// ```text
/// -> { "execute": "balloon", "arguments": { "value": 589934492 } }
/// <- {"return":{}}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct balloon {
#[serde(rename = "value")]
pub value: u64,
}
impl Command for balloon {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// version:
///
/// Query version of StratoVirt.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-version" }
/// <- {"return":{"package":"StratoVirt-0.3.0","qemu":{"major":4,"micro":0,"minor":1}}}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_version {}
impl Command for query_version {
type Res = Version;
fn back(self) -> Version {
Default::default()
}
}
/// Query commands:
///
/// Query all qmp commands of StratoVirt.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-commands" }
/// <- {"return":[{"name":"qmp_capabilities"},{"name":"quit"},{"name":"stop"},
/// {"name":"cont"},{"name":"device_add"},{"name":"device_del"},{"name":"netdev_add"},
/// {"name":"netdev_del"},{"name":"query-hotpluggable-cpus"},{"name":"query-cpus"},
/// {"name":"query_status"},{"name":"getfd"},{"name":"blockdev_add"},
/// {"name":"blockdev_del"},{"name":"balloon"},{"name":"query_balloon"},
/// {"name":"migrate"},{"name":"query_migrate"},{"name":"query_version"},
/// {"name":"query_target"},{"name":"query_commands"}]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_commands {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct Cmd {
pub name: String,
}
impl Command for query_commands {
type Res = Vec<Cmd>;
fn back(self) -> Vec<Cmd> {
Default::default()
}
}
/// Query target:
///
/// Query the target platform where the StratoVirt is running.
///
/// # Example
///
/// ```text
/// # for X86 platform.
/// -> { "execute": "query-target" }
/// <- {"return":{"arch":"x86_64"}}
///
/// # for Aarch64 platform.
/// -> { "execute": "query-target" }
/// <- {"return":{"arch":"aarch64"}}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_target {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct Target {
pub arch: String,
}
impl Command for query_target {
type Res = Target;
fn back(self) -> Target {
Default::default()
}
}
/// Query machines:
///
/// Query machine information.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-machines" }
/// <- {"return":[{"cpu-max":255,"deprecated":false,"hotpluggable-cpus":true,"name":"none","numa-mem-supported":false},
/// {"cpu-max":255,"deprecated":false,"hotpluggable-cpus":true,"name":"microvm","numa-mem-supported":false},
/// {"cpu-max":255,"deprecated":false,"hotpluggable-cpus":true,"name":"standardvm","numa-mem-supported":false}]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_machines {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct MachineInfo {
#[serde(rename = "hotpluggable-cpus")]
pub hotplug: bool,
pub name: String,
#[serde(rename = "numa-mem-supported")]
pub numa_mem_support: bool,
#[serde(rename = "cpu-max")]
pub cpu_max: u8,
pub deprecated: bool,
}
impl Command for query_machines {
type Res = Vec<MachineInfo>;
fn back(self) -> Vec<MachineInfo> {
Default::default()
}
}
/// Query events:
///
/// Query all events of StratoVirt.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-events" }
/// <- {"return":[{"name":"Shutdown"},{"name":"Reset"},
/// {"name":"Stop"},{"name":"Resume"},{"name":"DeviceDeleted"},
/// {"name":"BalloonChanged"}]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct Events {
pub name: String,
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_events {}
impl Command for query_events {
type Res = Vec<Events>;
fn back(self) -> Vec<Events> {
Default::default()
}
}
/// Query KVM:
///
/// Query if KVM is enabled.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-kvm" }
/// <- {"return":{"enabled":true,"present":true}}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_kvm {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct KvmInfo {
pub enabled: bool,
pub present: bool,
}
impl Command for query_kvm {
type Res = KvmInfo;
fn back(self) -> KvmInfo {
Default::default()
}
}
/// List all Qom type.
///
/// # Example
///
/// ```text
/// -> { "execute": "qom-list-types" }
/// <- {"return":[{"name":"ioh3420","parent":"pcie-root-port-base"},
/// {"name":"pcie-root-port","parent":"pcie-root-port-base"},
/// {"name":"pcie-pci-bridge","parent":"base-pci-bridge"},
/// {"name":"pci-bridge","parent":"base-pci-bridge"}]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct list_type {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct TypeLists {
name: String,
parent: String,
}
impl TypeLists {
pub fn new(name: String, parent: String) -> Self {
TypeLists { name, parent }
}
}
impl Command for list_type {
type Res = Vec<TypeLists>;
fn back(self) -> Vec<TypeLists> {
Default::default()
}
}
/// Get device list properties.
///
/// # Example
///
/// ```text
/// -> { "execute": "device-list-properties", "arguments": {"typename": "virtio-blk-pci"} }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct device_list_properties {
pub typename: String,
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct DeviceProps {
pub name: String,
#[serde(rename = "type")]
pub prop_type: String,
}
impl Command for device_list_properties {
type Res = Vec<DeviceProps>;
fn back(self) -> Vec<DeviceProps> {
Default::default()
}
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct block_commit {}
impl Command for block_commit {
type Res = Vec<DeviceProps>;
fn back(self) -> Vec<DeviceProps> {
Default::default()
}
}
/// Query tpm models of StratoVirt.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-tpm-models" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_tpm_models {}
impl Command for query_tpm_models {
type Res = Vec<String>;
fn back(self) -> Vec<String> {
Default::default()
}
}
/// Query target of StratoVirt.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-tpm-types" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_tpm_types {}
impl Command for query_tpm_types {
type Res = Vec<String>;
fn back(self) -> Vec<String> {
Default::default()
}
}
/// Query command line options.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-command-line-options" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_command_line_options {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CmdParameter {
name: String,
help: String,
#[serde(rename = "type")]
paramter_type: String,
}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct CmdLine {
pub parameters: Vec<CmdParameter>,
pub option: String,
}
impl Command for query_command_line_options {
type Res = Vec<CmdLine>;
fn back(self) -> Vec<CmdLine> {
Default::default()
}
}
/// Query capabilities of migration.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-migrate-capabilities" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_migrate_capabilities {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct MigrateCapabilities {
pub state: bool,
pub capability: String,
}
impl Command for query_migrate_capabilities {
type Res = Vec<MigrateCapabilities>;
fn back(self) -> Vec<MigrateCapabilities> {
Default::default()
}
}
/// Query target of StratoVirt.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-qmp-schema" }
/// <- {"return":{}}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_qmp_schema {}
impl Command for query_qmp_schema {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// Query capabilities of sev.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-sev-capabilities" }
/// <- {"return":{}}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_sev_capabilities {}
impl Command for query_sev_capabilities {
type Res = Empty;
fn back(self) -> Empty {
Default::default()
}
}
/// List all Qom.
///
/// # Example
///
/// ```text
/// -> { "execute": "qom-list" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct qom_list {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct PropList {
pub name: String,
#[serde(rename = "type")]
pub prop_type: String,
}
impl Command for qom_list {
type Res = Vec<PropList>;
fn back(self) -> Vec<PropList> {
Default::default()
}
}
/// Query char devices.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-chardev" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_chardev {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct ChardevInfo {
#[serde(rename = "frontend-open")]
pub open: bool,
pub filename: String,
pub label: String,
}
impl Command for query_chardev {
type Res = Vec<ChardevInfo>;
fn back(self) -> Vec<ChardevInfo> {
Default::default()
}
}
/// Get qom properties.
///
/// # Example
///
/// ```text
/// -> { "execute": "qom_get" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct qom_get {}
impl Command for qom_get {
type Res = bool;
fn back(self) -> bool {
Default::default()
}
}
/// Query blocks of StratoVirt.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-block" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_block {}
impl Command for query_block {
type Res = Vec<Cmd>;
fn back(self) -> Vec<Cmd> {
Default::default()
}
}
/// Query named block node.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-named-block-nodes" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_named_block_nodes {}
impl Command for query_named_block_nodes {
type Res = Vec<Cmd>;
fn back(self) -> Vec<Cmd> {
Default::default()
}
}
/// Query status of blocks.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-blockstats" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_blockstats {}
impl Command for query_blockstats {
type Res = Vec<Cmd>;
fn back(self) -> Vec<Cmd> {
Default::default()
}
}
/// Query jobs of blocks.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-block_jobs" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_block_jobs {}
impl Command for query_block_jobs {
type Res = Vec<Cmd>;
fn back(self) -> Vec<Cmd> {
Default::default()
}
}
/// Query capabilities of gic.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-gic-capabilities" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_gic_capabilities {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct GicCap {
emulated: bool,
version: u32,
kernel: bool,
}
impl Command for query_gic_capabilities {
type Res = Vec<GicCap>;
fn back(self) -> Vec<GicCap> {
Default::default()
}
}
/// Query information of iothreads.
///
/// # Example
///
/// ```text
/// -> { "execute": "query-iothreads" }
/// <- {"return":[]}
/// ```
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct query_iothreads {}
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
pub struct IothreadInfo {
#[serde(rename = "poll-shrink")]
pub shrink: u32,
#[serde(rename = "thread-id")]
pub pid: u32,
#[serde(rename = "poll-grow")]
pub grow: u32,
#[serde(rename = "poll-max-ns")]
pub max: u32,
pub id: String,
}
impl Command for query_iothreads {
type Res = Vec<IothreadInfo>;
fn back(self) -> Vec<IothreadInfo> {
Default::default()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_qmp_unexpected_arguments() {
// qmp: quit.
let json_msg = r#"
{
"execute": "quit"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg == ret_msg);
// unexpected arguments for quit.
let json_msg = r#"
{
"execute": "quit" ,
"arguments": "isdf"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"invalid type: string "isdf", expected struct quit"#;
assert!(err_msg == ret_msg);
// qmp: stop.
let json_msg = r#"
{
"execute": "stop"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg == ret_msg);
// unexpected arguments for stop.
let json_msg = r#"
{
"execute": "stop" ,
"arguments": "isdf"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"invalid type: string "isdf", expected struct stop"#;
assert!(err_msg == ret_msg);
// qmp: cont.
let json_msg = r#"
{
"execute": "cont"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg == ret_msg);
// unexpected arguments for count.
let json_msg = r#"
{
"execute": "cont" ,
"arguments": "isdf"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"invalid type: string "isdf", expected struct cont"#;
assert!(err_msg == ret_msg);
// qmp: query-hotpluggable-cpus.
let json_msg = r#"
{
"execute": "query-hotpluggable-cpus"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg == ret_msg);
// unexpected arguments for query-hotpluggable-cpus.
let json_msg = r#"
{
"execute": "query-hotpluggable-cpus" ,
"arguments": "isdf"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"invalid type: string "isdf", expected struct query_hotpluggable_cpus"#;
assert!(err_msg == ret_msg);
// qmp: query-cpus.
let json_msg = r#"
{
"execute": "query-cpus"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg == ret_msg);
// unexpected arguments for query-cpus.
let json_msg = r#"
{
"execute": "query-cpus" ,
"arguments": "isdf"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"invalid type: string "isdf", expected struct query_cpus"#;
assert!(err_msg == ret_msg);
// qmp: query-ststus.
let json_msg = r#"
{
"execute": "query-status"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg == ret_msg);
// unexpected arguments for query-status.
let json_msg = r#"
{
"execute": "query-status" ,
"arguments": "isdf"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"invalid type: string "isdf", expected struct query_status"#;
assert!(err_msg == ret_msg);
}
#[test]
fn test_wrong_qmp_arguments() {
// right arguments for device_add.
let json_msg = r#"
{
"execute": "device_add" ,
"arguments": {
"id":"net-0",
"driver":"virtio-net-mmio",
"addr":"0x0"
}
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg.contains(ret_msg));
// unknow arguments for device_add.
let json_msg = r#"
{
"execute": "device_add" ,
"arguments": {
"id":"net-0",
"driver":"virtio-net-mmio",
"addr":"0x0",
"UnknowArg": "should go to error"
}
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"unknown field `UnknowArg`"#;
assert!(err_msg.contains(ret_msg));
// wrong spelling arguments for device_add.
let json_msg = r#"
{
"execute": "device_add" ,
"arguments": {
"id":"net-0",
"driv":"virtio-net-mmio",
"addr":"0x0"
}
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"unknown field `driv`"#;
assert!(err_msg.contains(ret_msg));
// right arguments for device_del.
let json_msg = r#"
{
"execute": "device_del" ,
"arguments": {
"id": "net-1"
}
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg.contains(ret_msg));
// wrong arguments for device_del.
let json_msg = r#"
{
"execute": "device_del" ,
"arguments": {
"value": "h8i"
}
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let unknow_msg = r#"unknown field `value`"#;
let expect_msg = r#"expected `id`"#;
assert!(err_msg.contains(unknow_msg));
assert!(err_msg.contains(expect_msg));
// missing arguments for getfd.
let json_msg = r#"
{
"execute": "getfd"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"missing field `arguments`"#;
assert!(err_msg == ret_msg);
// unexpected arguments for getfd.
let json_msg = r#"
{
"execute": "getfd" ,
"arguments": "isdf"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"invalid type: string "isdf", expected struct getfd"#;
assert!(err_msg == ret_msg);
// right arguments for getfd.
let json_msg = r#"
{
"execute": "getfd",
"arguments": {
"fdname": "fd1"
}
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg == ret_msg);
// right arguments for blockdev-add.
let json_msg = r#"
{
"execute": "blockdev-add",
"arguments": {
"node-name": "drive-0",
"file": {
"driver": "file",
"filename": "/path/to/block"
},
"cache": {
"direct": true
},
"read-only": false
}
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg == ret_msg);
// right arguments for device-add.
let json_msg = r#"
{
"execute": "device_add",
"arguments": {
"id": "drive-0",
"driver": "virtio-blk-mmio",
"addr": "0x1"
}
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg == ret_msg);
// right arguments for netdev-add.
let json_msg = r#"
{
"execute": "netdev_add",
"arguments": {
"id": "net-0",
"ifname":"tap0"
}
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let ret_msg = r#"ok"#;
assert!(err_msg == ret_msg);
}
#[test]
fn test_unsupported_commands() {
// unsupported qmp command.
let json_msg = r#"
{
"execute": "hello-world" ,
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let part_msg = r#"unknown variant `hello-world`"#;
assert!(err_msg.contains(part_msg));
// unsupported qmp command, and unknow field.
let json_msg = r#"
{
"execute": "hello-world" ,
"arguments": {
"msg": "hello",
}
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let part_msg = r#"unknown variant `hello-world`"#;
assert!(err_msg.contains(part_msg));
}
#[test]
fn test_qmp_commands() {
// query-version
let json_msg = r#"
{
"execute": "query-version"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let part_msg = r#"ok"#;
assert!(err_msg.contains(part_msg));
// query-target
let json_msg = r#"
{
"execute": "query-target"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let part_msg = r#"ok"#;
assert!(err_msg.contains(part_msg));
// query-commands
let json_msg = r#"
{
"execute": "query-commands"
}
"#;
let err_msg = match serde_json::from_str::<QmpCommand>(json_msg) {
Ok(_) => "ok".to_string(),
Err(e) => e.to_string(),
};
let part_msg = r#"ok"#;
assert!(err_msg.contains(part_msg));
}
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/openeuler-stratovirt.git
git@gitlife.ru:oschina-mirror/openeuler-stratovirt.git
oschina-mirror
openeuler-stratovirt
openeuler-stratovirt
v2.2.0-rc6