PVE的current接口分析笔记
1、收到http的get请求
pve:node的节点名称
100:虚拟机ID
https://192.168.13.130:8006/api2/json/nodes/pve/qemu/100/status/current

2、nodes.pm通过PVE::API2::Qemu引用qemu.pm
__PACKAGE__->register_method({subclass => "PVE::API2::Qemu",path => 'qemu',
});
3、找到status/current注册的函数
代码处理
__PACKAGE__->register_method({name => 'vm_status',path => '{vmid}/status/current',method => 'GET',proxyto => 'node',protected => 1, # qemu pid files are only readable by rootdescription => "Get virtual machine status.",permissions => {check => ['perm', '/vms/{vmid}', ['VM.Audit']],},parameters => {additionalProperties => 0,properties => {node => get_standard_option('pve-node'),vmid => get_standard_option('pve-vmid'),},},returns => {type => 'object',properties => {%$PVE::QemuServer::vmstatus_return_properties,ha => {description => "HA manager service status.",type => 'object',},spice => {description => "QEMU VGA configuration supports spice.",type => 'boolean',optional => 1,},agent => {description => "QEMU Guest Agent is enabled in config.",type => 'boolean',optional => 1,},clipboard => {description => 'Enable a specific clipboard. If not set, depending on'. ' the display type the SPICE one will be added.',type => 'string',enum => ['vnc'],optional => 1,},},},code => sub {my ($param) = @_;# test if VM existsmy $conf = PVE::QemuConfig->load_config($param->{vmid});my $vmstatus = PVE::QemuServer::vmstatus($param->{vmid}, 1);my $status = $vmstatus->{ $param->{vmid} };$status->{ha} = PVE::HA::Config::get_service_status("vm:$param->{vmid}");if ($conf->{vga}) {my $vga = PVE::QemuServer::parse_vga($conf->{vga});my $spice = defined($vga->{type}) && $vga->{type} =~ /^virtio/;$spice ||= PVE::QemuServer::vga_conf_has_spice($conf->{vga});$status->{spice} = 1 if $spice;$status->{clipboard} = $vga->{clipboard};}$status->{agent} = 1 if PVE::QemuServer::get_qga_key($conf, 'enabled');return $status;},
});
返回的内容
{
"data": {
"qmpstatus": "stopped",
"vmid": 100,
"disk": 0,
"mem": 0,
"uptime": 0,
"maxdisk": 53687091200,
"status": "stopped",
"ha": {
"managed": 0
},
"maxmem": 2147483648,
"diskread": 0,
"template": 1,
"cpus": 4,
"name": "kylin-v10-desktop",
"netin": 0,
"cpu": 0,
"diskwrite": 0,
"netout": 0
}
}
