1 package PVE
::API2
::Nodes
::Nodeinfo
;
9 use HTTP
::Status
qw(:constants);
11 use POSIX
qw(LONG_MAX);
12 use Time
::Local
qw(timegm_nocheck);
18 use PVE
::AccessControl
;
19 use PVE
::Cluster
qw(cfs_read_file);
20 use PVE
::DataCenterConfig
;
21 use PVE
::Exception
qw(raise raise_perm_exc raise_param_exc);
24 use PVE
::HA
::Env
::PVE2
;
26 use PVE
::JSONSchema
qw(get_standard_option);
32 use PVE
::RPCEnvironment
;
41 use PVE
::API2
::Capabilities
;
43 use PVE
::API2
::Certificates
;
45 use PVE
::API2
::Firewall
::Host
;
46 use PVE
::API2
::Hardware
;
47 use PVE
::API2
::LXC
::Status
;
49 use PVE
::API2
::Network
;
50 use PVE
::API2
::NodeConfig
;
51 use PVE
::API2
::Qemu
::CPU
;
53 use PVE
::API2
::Replication
;
54 use PVE
::API2
::Services
;
55 use PVE
::API2
::Storage
::Scan
;
56 use PVE
::API2
::Storage
::Status
;
57 use PVE
::API2
::Subscription
;
59 use PVE
::API2
::VZDump
;
63 require PVE
::API2
::Network
::SDN
::Zones
::Status
;
67 use base
qw(PVE::RESTHandler);
69 my $verify_command_item_desc = {
70 description
=> "An array of objects describing endpoints, methods and arguments.",
76 description
=> "A relative path to an API endpoint on this node.",
81 description
=> "A method related to the API endpoint (GET, POST etc.).",
83 pattern
=> "(GET|POST|PUT|DELETE)",
87 description
=> "A set of parameter names and their values.",
95 PVE
::JSONSchema
::register_format
('pve-command-batch', \
&verify_command_batch
);
96 sub verify_command_batch
{
97 my ($value, $noerr) = @_;
98 my $commands = eval { decode_json
($value); };
100 return if $noerr && $@;
101 die "commands param did not contain valid JSON: $@" if $@;
103 eval { PVE
::JSONSchema
::validate
($commands, $verify_command_item_desc) };
105 return $commands if !$@;
108 die "commands is not a valid array of commands: $@";
111 __PACKAGE__-
>register_method ({
112 subclass
=> "PVE::API2::Qemu",
116 __PACKAGE__-
>register_method ({
117 subclass
=> "PVE::API2::LXC",
121 __PACKAGE__-
>register_method ({
122 subclass
=> "PVE::API2::Ceph",
126 __PACKAGE__-
>register_method ({
127 subclass
=> "PVE::API2::VZDump",
131 __PACKAGE__-
>register_method ({
132 subclass
=> "PVE::API2::Services",
136 __PACKAGE__-
>register_method ({
137 subclass
=> "PVE::API2::Subscription",
138 path
=> 'subscription',
141 __PACKAGE__-
>register_method ({
142 subclass
=> "PVE::API2::Network",
146 __PACKAGE__-
>register_method ({
147 subclass
=> "PVE::API2::Tasks",
151 __PACKAGE__-
>register_method ({
152 subclass
=> "PVE::API2::Storage::Scan",
156 __PACKAGE__-
>register_method ({
157 subclass
=> "PVE::API2::Hardware",
161 __PACKAGE__-
>register_method ({
162 subclass
=> "PVE::API2::Capabilities",
163 path
=> 'capabilities',
166 __PACKAGE__-
>register_method ({
167 subclass
=> "PVE::API2::Storage::Status",
171 __PACKAGE__-
>register_method ({
172 subclass
=> "PVE::API2::Disks",
176 __PACKAGE__-
>register_method ({
177 subclass
=> "PVE::API2::APT",
181 __PACKAGE__-
>register_method ({
182 subclass
=> "PVE::API2::Firewall::Host",
186 __PACKAGE__-
>register_method ({
187 subclass
=> "PVE::API2::Replication",
188 path
=> 'replication',
191 __PACKAGE__-
>register_method ({
192 subclass
=> "PVE::API2::Certificates",
193 path
=> 'certificates',
197 __PACKAGE__-
>register_method ({
198 subclass
=> "PVE::API2::NodeConfig",
203 __PACKAGE__-
>register_method ({
204 subclass
=> "PVE::API2::Network::SDN::Zones::Status",
208 __PACKAGE__-
>register_method ({
212 permissions
=> { user
=> 'all' },
213 description
=> "SDN index.",
215 additionalProperties
=> 0,
217 node
=> get_standard_option
('pve-node'),
226 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
238 __PACKAGE__-
>register_method ({
242 permissions
=> { user
=> 'all' },
243 description
=> "Node index.",
245 additionalProperties
=> 0,
247 node
=> get_standard_option
('pve-node'),
256 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
262 { name
=> 'aplinfo' },
264 { name
=> 'capabilities' },
266 { name
=> 'certificates' },
267 { name
=> 'config' },
270 { name
=> 'firewall' },
272 { name
=> 'journal' },
274 { name
=> 'netstat' },
275 { name
=> 'network' },
277 { name
=> 'query-url-metadata' },
278 { name
=> 'replication' },
279 { name
=> 'report' },
280 { name
=> 'rrd' }, # fixme: remove?
281 { name
=> 'rrddata' },# fixme: remove?
283 { name
=> 'services' },
284 { name
=> 'spiceshell' },
285 { name
=> 'startall' },
286 { name
=> 'status' },
287 { name
=> 'stopall' },
288 { name
=> 'storage' },
289 { name
=> 'subscription' },
290 { name
=> 'syslog' },
292 { name
=> 'termproxy' },
294 { name
=> 'version' },
295 { name
=> 'vncshell' },
296 { name
=> 'vzdump' },
297 { name
=> 'wakeonlan' },
300 push @$result, { name
=> 'sdn' } if $have_sdn;
305 __PACKAGE__-
>register_method ({
310 permissions
=> { user
=> 'all' },
311 description
=> "API version details",
313 additionalProperties
=> 0,
315 node
=> get_standard_option
('pve-node'),
323 description
=> 'The current installed pve-manager package version',
327 description
=> 'The current installed Proxmox VE Release',
331 description
=> 'The short git commit hash ID from which this version was build',
336 my ($resp, $param) = @_;
338 return PVE
::pvecfg
::version_info
();
341 __PACKAGE__-
>register_method({
346 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
348 description
=> "Read node status",
351 additionalProperties
=> 0,
353 node
=> get_standard_option
('pve-node'),
370 my ($uptime, $idle) = PVE
::ProcFSTools
::read_proc_uptime
();
371 $res->{uptime
} = $uptime;
373 my ($avg1, $avg5, $avg15) = PVE
::ProcFSTools
::read_loadavg
();
374 $res->{loadavg
} = [ $avg1, $avg5, $avg15];
376 my ($sysname, $nodename, $release, $version, $machine) = POSIX
::uname
();
378 $res->{kversion
} = "$sysname $release $version";
380 $res->{cpuinfo
} = PVE
::ProcFSTools
::read_cpuinfo
();
382 my $stat = PVE
::ProcFSTools
::read_proc_stat
();
383 $res->{cpu
} = $stat->{cpu
};
384 $res->{wait} = $stat->{wait};
386 my $meminfo = PVE
::ProcFSTools
::read_meminfo
();
388 free
=> $meminfo->{memfree
},
389 total
=> $meminfo->{memtotal
},
390 used
=> $meminfo->{memused
},
394 shared
=> $meminfo->{memshared
},
398 free
=> $meminfo->{swapfree
},
399 total
=> $meminfo->{swaptotal
},
400 used
=> $meminfo->{swapused
},
403 $res->{pveversion
} = PVE
::pvecfg
::package() . "/" .
404 PVE
::pvecfg
::version_text
();
406 my $dinfo = df
('/', 1); # output is bytes
409 total
=> $dinfo->{blocks
},
410 avail
=> $dinfo->{bavail
},
411 used
=> $dinfo->{used
},
412 free
=> $dinfo->{blocks
} - $dinfo->{used
},
418 __PACKAGE__-
>register_method({
423 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
425 description
=> "Read tap/vm network device interface counters",
428 additionalProperties
=> 0,
430 node
=> get_standard_option
('pve-node'),
445 my $netdev = PVE
::ProcFSTools
::read_proc_net_dev
();
446 foreach my $dev (sort keys %$netdev) {
447 next if $dev !~ m/^(?:tap|veth)([1-9]\d*)i(\d+)$/;
448 my ($vmid, $netid) = ($1, $2);
453 in => $netdev->{$dev}->{transmit
},
454 out
=> $netdev->{$dev}->{receive
},
461 __PACKAGE__-
>register_method({
466 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
468 description
=> "Execute multiple commands in order.",
470 protected
=> 1, # avoid problems with proxy code
472 additionalProperties
=> 0,
474 node
=> get_standard_option
('pve-node'),
476 description
=> "JSON encoded array of commands.",
478 verbose_description
=> "JSON encoded array of commands, where each command is an object with the following properties:\n"
479 . PVE
::RESTHandler
::dump_properties
($verify_command_item_desc->{items
}->{properties
}, 'full'),
480 format
=> "pve-command-batch",
495 my $rpcenv = PVE
::RPCEnvironment
::get
();
496 my $user = $rpcenv->get_user();
497 # just parse the json again, it should already be validated
498 my $commands = eval { decode_json
($param->{commands
}); };
500 foreach my $cmd (@$commands) {
504 my $path = "nodes/$param->{node}/$cmd->{path}";
507 my ($handler, $info) = PVE
::API2-
>find_handler($cmd->{method}, $path, $uri_param);
508 if (!$handler || !$info) {
509 die "no handler for '$path'\n";
512 foreach my $p (keys %{$cmd->{args
}}) {
513 raise_param_exc
({ $p => "duplicate parameter" }) if defined($uri_param->{$p});
514 $uri_param->{$p} = $cmd->{args
}->{$p};
517 # check access permissions
518 $rpcenv->check_api2_permissions($info->{permissions
}, $user, $uri_param);
522 data
=> $handler->handle($info, $uri_param),
526 my $resp = { status
=> HTTP_INTERNAL_SERVER_ERROR
};
527 if (ref($err) eq "PVE::Exception") {
528 $resp->{status
} = $err->{code
} if $err->{code
};
529 $resp->{errors
} = $err->{errors
} if $err->{errors
};
530 $resp->{message
} = $err->{msg
};
532 $resp->{message
} = $err;
542 __PACKAGE__-
>register_method({
547 check
=> ['perm', '/nodes/{node}', [ 'Sys.PowerMgmt' ]],
550 description
=> "Reboot or shutdown a node.",
553 additionalProperties
=> 0,
555 node
=> get_standard_option
('pve-node'),
557 description
=> "Specify the command.",
559 enum
=> [qw(reboot shutdown)],
563 returns
=> { type
=> "null" },
567 if ($param->{command
} eq 'reboot') {
568 system ("(sleep 2;/sbin/reboot)&");
569 } elsif ($param->{command
} eq 'shutdown') {
570 system ("(sleep 2;/sbin/poweroff)&");
576 __PACKAGE__-
>register_method({
581 check
=> ['perm', '/nodes/{node}', [ 'Sys.PowerMgmt' ]],
584 description
=> "Try to wake a node via 'wake on LAN' network packet.",
586 additionalProperties
=> 0,
588 node
=> get_standard_option
('pve-node', {
589 description
=> 'target node for wake on LAN packet',
591 my $members = PVE
::Cluster
::get_members
();
592 return [ grep { !$members->{$_}->{online
} } keys %$members ];
599 format
=> 'mac-addr',
600 description
=> 'MAC address used to assemble the WoL magic packet.',
605 my $node = $param->{node
};
607 die "'$node' is local node, cannot wake my self!\n"
608 if $node eq 'localhost' || $node eq PVE
::INotify
::nodename
();
610 PVE
::Cluster
::check_node_exists
($node);
612 my $config = PVE
::NodeConfig
::load_config
($node);
613 my $mac_addr = $config->{wakeonlan
};
614 if (!defined($mac_addr)) {
615 die "No wake on LAN MAC address defined for '$node'!\n";
619 my $packet = chr(0xff) x
6 . pack('H*', $mac_addr) x
16;
621 my $addr = gethostbyname('255.255.255.255');
622 my $port = getservbyname('discard', 'udp');
623 my $to = Socket
::pack_sockaddr_in
($port, $addr);
625 socket(my $sock, Socket
::AF_INET
, Socket
::SOCK_DGRAM
, Socket
::IPPROTO_UDP
)
626 || die "Unable to open socket: $!\n";
627 setsockopt($sock, Socket
::SOL_SOCKET
, Socket
::SO_BROADCAST
, 1)
628 || die "Unable to set socket option: $!\n";
630 send($sock, $packet, 0, $to)
631 || die "Unable to send packet: $!\n";
635 return $config->{wakeonlan
};
638 __PACKAGE__-
>register_method({
642 protected
=> 1, # fixme: can we avoid that?
644 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
646 description
=> "Read node RRD statistics (returns PNG)",
648 additionalProperties
=> 0,
650 node
=> get_standard_option
('pve-node'),
652 description
=> "Specify the time frame you are interested in.",
654 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
657 description
=> "The list of datasources you want to display.",
658 type
=> 'string', format
=> 'pve-configid-list',
661 description
=> "The RRD consolidation function",
663 enum
=> [ 'AVERAGE', 'MAX' ],
671 filename
=> { type
=> 'string' },
677 return PVE
::RRD
::create_rrd_graph
(
678 "pve2-node/$param->{node}", $param->{timeframe
},
679 $param->{ds
}, $param->{cf
});
683 __PACKAGE__-
>register_method({
687 protected
=> 1, # fixme: can we avoid that?
689 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
691 description
=> "Read node RRD statistics",
693 additionalProperties
=> 0,
695 node
=> get_standard_option
('pve-node'),
697 description
=> "Specify the time frame you are interested in.",
699 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
702 description
=> "The RRD consolidation function",
704 enum
=> [ 'AVERAGE', 'MAX' ],
719 return PVE
::RRD
::create_rrd_data
(
720 "pve2-node/$param->{node}", $param->{timeframe
}, $param->{cf
});
723 __PACKAGE__-
>register_method({
727 description
=> "Read system log",
730 check
=> ['perm', '/nodes/{node}', [ 'Sys.Syslog' ]],
734 additionalProperties
=> 0,
736 node
=> get_standard_option
('pve-node'),
749 pattern
=> '^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$',
750 description
=> "Display all log since this date-time string.",
755 pattern
=> '^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$',
756 description
=> "Display all log until this date-time string.",
760 description
=> "Service ID",
773 description
=> "Line number",
777 description
=> "Line text",
786 my $rpcenv = PVE
::RPCEnvironment
::get
();
787 my $user = $rpcenv->get_user();
788 my $node = $param->{node
};
791 if ($param->{service
}) {
792 my $service_aliases = {
793 'postfix' => 'postfix@-',
796 $service = $service_aliases->{$param->{service
}} // $param->{service
};
799 my ($count, $lines) = PVE
::Tools
::dump_journal
($param->{start
}, $param->{limit
},
800 $param->{since
}, $param->{until}, $service);
802 $rpcenv->set_result_attrib('total', $count);
807 __PACKAGE__-
>register_method({
811 description
=> "Read Journal",
814 check
=> ['perm', '/nodes/{node}', [ 'Sys.Syslog' ]],
818 additionalProperties
=> 0,
820 node
=> get_standard_option
('pve-node'),
824 description
=> "Display all log since this UNIX epoch. Conflicts with 'startcursor'.",
830 description
=> "Display all log until this UNIX epoch. Conflicts with 'endcursor'.",
834 description
=> "Limit to the last X lines. Conflicts with a range.",
840 description
=> "Start after the given Cursor. Conflicts with 'since'",
845 description
=> "End before the given Cursor. Conflicts with 'until'",
860 my $rpcenv = PVE
::RPCEnvironment
::get
();
861 my $user = $rpcenv->get_user();
863 my $cmd = ["/usr/bin/mini-journalreader", "-j"];
864 push @$cmd, '-n', $param->{lastentries
} if $param->{lastentries
};
865 push @$cmd, '-b', $param->{since
} if $param->{since
};
866 push @$cmd, '-e', $param->{until} if $param->{until};
867 push @$cmd, '-f', PVE
::Tools
::shellquote
($param->{startcursor
}) if $param->{startcursor
};
868 push @$cmd, '-t', PVE
::Tools
::shellquote
($param->{endcursor
}) if $param->{endcursor
};
869 push @$cmd, ' | gzip ';
871 open(my $fh, "-|", join(' ', @$cmd))
872 or die "could not start mini-journalreader";
878 'content-type' => 'application/json',
879 'content-encoding' => 'gzip',
886 my $shell_cmd_map = {
888 cmd
=> [ '/bin/login', '-f', 'root' ],
891 cmd
=> [ '/usr/bin/pveupgrade', '--shell' ],
894 cmd
=> [ '/usr/bin/pveceph', 'install' ],
899 sub get_shell_command
{
900 my ($user, $shellcmd, $args) = @_;
903 if ($user eq 'root@pam') {
904 if (defined($shellcmd) && exists($shell_cmd_map->{$shellcmd})) {
905 my $def = $shell_cmd_map->{$shellcmd};
906 $cmd = [ @{$def->{cmd
}} ]; # clone
907 if (defined($args) && $def->{allow_args
}) {
908 push @$cmd, split("\0", $args);
911 $cmd = [ '/bin/login', '-f', 'root' ];
914 # non-root must always login for now, we do not have a superuser role!
915 $cmd = [ '/bin/login' ];
920 my $get_vnc_connection_info = sub {
925 my ($remip, $family);
926 if ($node ne 'localhost' && $node ne PVE
::INotify
::nodename
()) {
927 ($remip, $family) = PVE
::Cluster
::remote_node_ip
($node);
928 $remote_cmd = ['/usr/bin/ssh', '-e', 'none', '-t', $remip , '--'];
930 $family = PVE
::Tools
::get_host_address_family
($node);
932 my $port = PVE
::Tools
::next_vnc_port
($family);
934 return ($port, $remote_cmd);
937 __PACKAGE__-
>register_method ({
943 description
=> "Restricted to users on realm 'pam'",
944 check
=> ['perm', '/nodes/{node}', [ 'Sys.Console' ]],
946 description
=> "Creates a VNC Shell proxy.",
948 additionalProperties
=> 0,
950 node
=> get_standard_option
('pve-node'),
953 description
=> "Run specific command or default to login.",
954 enum
=> [keys %$shell_cmd_map],
960 description
=> "Add parameters to a command. Encoded as null terminated strings.",
968 description
=> "use websocket instead of standard vnc.",
972 description
=> "sets the width of the console in pixels.",
979 description
=> "sets the height of the console in pixels.",
987 additionalProperties
=> 0,
989 user
=> { type
=> 'string' },
990 ticket
=> { type
=> 'string' },
991 cert
=> { type
=> 'string' },
992 port
=> { type
=> 'integer' },
993 upid
=> { type
=> 'string' },
999 my $rpcenv = PVE
::RPCEnvironment
::get
();
1000 my ($user, undef, $realm) = PVE
::AccessControl
::verify_username
($rpcenv->get_user());
1002 raise_perm_exc
("realm != pam") if $realm ne 'pam';
1004 if (defined($param->{cmd
}) && $param->{cmd
} eq 'upgrade' && $user ne 'root@pam') {
1005 raise_perm_exc
('user != root@pam');
1008 my $node = $param->{node
};
1010 my $authpath = "/nodes/$node";
1011 my $ticket = PVE
::AccessControl
::assemble_vnc_ticket
($user, $authpath);
1013 $sslcert = PVE
::Tools
::file_get_contents
("/etc/pve/pve-root-ca.pem", 8192)
1016 my ($port, $remcmd) = $get_vnc_connection_info->($node);
1018 my $shcmd = get_shell_command
($user, $param->{cmd
}, $param->{'cmd-opts'});
1022 my $cmd = ['/usr/bin/vncterm',
1024 '-timeout', $timeout,
1025 '-authpath', $authpath,
1026 '-perm', 'Sys.Console',
1029 push @$cmd, '-width', $param->{width
} if $param->{width
};
1030 push @$cmd, '-height', $param->{height
} if $param->{height
};
1032 if ($param->{websocket
}) {
1033 $ENV{PVE_VNC_TICKET
} = $ticket; # pass ticket to vncterm
1034 push @$cmd, '-notls', '-listen', 'localhost';
1037 push @$cmd, '-c', @$remcmd, @$shcmd;
1042 syslog
('info', "starting vnc proxy $upid\n");
1044 my $cmdstr = join (' ', @$cmd);
1045 syslog
('info', "launch command: $cmdstr");
1048 foreach my $k (keys %ENV) {
1049 next if $k eq 'PVE_VNC_TICKET';
1050 next if $k eq 'PATH' || $k eq 'TERM' || $k eq 'USER' || $k eq 'HOME' || $k eq 'LANG' || $k eq 'LANGUAGE';
1055 PVE
::Tools
::run_command
($cmd, errmsg
=> "vncterm failed", keeplocale
=> 1);
1058 syslog
('err', $err);
1064 my $upid = $rpcenv->fork_worker('vncshell', "", $user, $realcmd);
1066 PVE
::Tools
::wait_for_vnc_port
($port);
1077 __PACKAGE__-
>register_method ({
1078 name
=> 'termproxy',
1079 path
=> 'termproxy',
1083 description
=> "Restricted to users on realm 'pam'",
1084 check
=> ['perm', '/nodes/{node}', [ 'Sys.Console' ]],
1086 description
=> "Creates a VNC Shell proxy.",
1088 additionalProperties
=> 0,
1090 node
=> get_standard_option
('pve-node'),
1093 description
=> "Run specific command or default to login.",
1094 enum
=> [keys %$shell_cmd_map],
1100 description
=> "Add parameters to a command. Encoded as null terminated strings.",
1108 additionalProperties
=> 0,
1110 user
=> { type
=> 'string' },
1111 ticket
=> { type
=> 'string' },
1112 port
=> { type
=> 'integer' },
1113 upid
=> { type
=> 'string' },
1119 my $rpcenv = PVE
::RPCEnvironment
::get
();
1120 my ($user, undef, $realm) = PVE
::AccessControl
::verify_username
($rpcenv->get_user());
1121 raise_perm_exc
("realm $realm != pam") if $realm ne 'pam';
1123 my $node = $param->{node
};
1124 my $authpath = "/nodes/$node";
1125 my $ticket = PVE
::AccessControl
::assemble_vnc_ticket
($user, $authpath);
1127 my ($port, $remcmd) = $get_vnc_connection_info->($node);
1129 my $shcmd = get_shell_command
($user, $param->{cmd
}, $param->{'cmd-opts'});
1134 syslog
('info', "starting termproxy $upid\n");
1137 '/usr/bin/termproxy',
1139 '--path', $authpath,
1140 '--perm', 'Sys.Console',
1143 push @$cmd, @$remcmd, @$shcmd;
1145 PVE
::Tools
::run_command
($cmd);
1147 my $upid = $rpcenv->fork_worker('vncshell', "", $user, $realcmd);
1149 PVE
::Tools
::wait_for_vnc_port
($port);
1159 __PACKAGE__-
>register_method({
1160 name
=> 'vncwebsocket',
1161 path
=> 'vncwebsocket',
1164 description
=> "Restricted to users on realm 'pam'. You also need to pass a valid ticket (vncticket).",
1165 check
=> ['perm', '/nodes/{node}', [ 'Sys.Console' ]],
1167 description
=> "Opens a websocket for VNC traffic.",
1169 additionalProperties
=> 0,
1171 node
=> get_standard_option
('pve-node'),
1173 description
=> "Ticket from previous call to vncproxy.",
1178 description
=> "Port number returned by previous vncproxy call.",
1188 port
=> { type
=> 'string' },
1194 my $rpcenv = PVE
::RPCEnvironment
::get
();
1196 my ($user, undef, $realm) = PVE
::AccessControl
::verify_username
($rpcenv->get_user());
1198 raise_perm_exc
("realm != pam") if $realm ne 'pam';
1200 my $authpath = "/nodes/$param->{node}";
1202 PVE
::AccessControl
::verify_vnc_ticket
($param->{vncticket
}, $user, $authpath);
1204 my $port = $param->{port
};
1206 return { port
=> $port };
1209 __PACKAGE__-
>register_method ({
1210 name
=> 'spiceshell',
1211 path
=> 'spiceshell',
1216 description
=> "Restricted to users on realm 'pam'",
1217 check
=> ['perm', '/nodes/{node}', [ 'Sys.Console' ]],
1219 description
=> "Creates a SPICE shell.",
1221 additionalProperties
=> 0,
1223 node
=> get_standard_option
('pve-node'),
1224 proxy
=> get_standard_option
('spice-proxy', { optional
=> 1 }),
1227 description
=> "Run specific command or default to login.",
1228 enum
=> [keys %$shell_cmd_map],
1234 description
=> "Add parameters to a command. Encoded as null terminated strings.",
1241 returns
=> get_standard_option
('remote-viewer-config'),
1245 my $rpcenv = PVE
::RPCEnvironment
::get
();
1246 my $authuser = $rpcenv->get_user();
1248 my ($user, undef, $realm) = PVE
::AccessControl
::verify_username
($authuser);
1250 raise_perm_exc
("realm != pam") if $realm ne 'pam';
1252 if (defined($param->{cmd
}) && $param->{cmd
} eq 'upgrade' && $user ne 'root@pam') {
1253 raise_perm_exc
('user != root@pam');
1256 my $node = $param->{node
};
1257 my $proxy = $param->{proxy
};
1259 my $authpath = "/nodes/$node";
1260 my $permissions = 'Sys.Console';
1262 my $shcmd = get_shell_command
($user, $param->{cmd
}, $param->{'cmd-opts'});
1264 my $title = "Shell on '$node'";
1266 return PVE
::API2Tools
::run_spiceterm
($authpath, $permissions, 0, $node, $proxy, $title, $shcmd);
1269 __PACKAGE__-
>register_method({
1274 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
1276 description
=> "Read DNS settings.",
1279 additionalProperties
=> 0,
1281 node
=> get_standard_option
('pve-node'),
1286 additionalProperties
=> 0,
1289 description
=> "Search domain for host-name lookup.",
1294 description
=> 'First name server IP address.',
1299 description
=> 'Second name server IP address.',
1304 description
=> 'Third name server IP address.',
1313 my $res = PVE
::INotify
::read_file
('resolvconf');
1318 __PACKAGE__-
>register_method({
1319 name
=> 'update_dns',
1322 description
=> "Write DNS settings.",
1324 check
=> ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
1329 additionalProperties
=> 0,
1331 node
=> get_standard_option
('pve-node'),
1333 description
=> "Search domain for host-name lookup.",
1337 description
=> 'First name server IP address.',
1338 type
=> 'string', format
=> 'ip',
1342 description
=> 'Second name server IP address.',
1343 type
=> 'string', format
=> 'ip',
1347 description
=> 'Third name server IP address.',
1348 type
=> 'string', format
=> 'ip',
1353 returns
=> { type
=> "null" },
1357 PVE
::INotify
::update_file
('resolvconf', $param);
1362 __PACKAGE__-
>register_method({
1367 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
1369 description
=> "Read server time and time zone settings.",
1372 additionalProperties
=> 0,
1374 node
=> get_standard_option
('pve-node'),
1379 additionalProperties
=> 0,
1382 description
=> "Time zone",
1386 description
=> "Seconds since 1970-01-01 00:00:00 UTC.",
1388 minimum
=> 1297163644,
1389 renderer
=> 'timestamp',
1392 description
=> "Seconds since 1970-01-01 00:00:00 (local time)",
1394 minimum
=> 1297163644,
1395 renderer
=> 'timestamp_gmt',
1403 my $ltime = timegm_nocheck
(localtime($ctime));
1405 timezone
=> PVE
::INotify
::read_file
('timezone'),
1407 localtime => $ltime,
1413 __PACKAGE__-
>register_method({
1414 name
=> 'set_timezone',
1417 description
=> "Set time zone.",
1419 check
=> ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
1424 additionalProperties
=> 0,
1426 node
=> get_standard_option
('pve-node'),
1428 description
=> "Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names.",
1433 returns
=> { type
=> "null" },
1437 PVE
::INotify
::write_file
('timezone', $param->{timezone
});
1442 __PACKAGE__-
>register_method({
1449 description
=> "Get list of appliances.",
1452 additionalProperties
=> 0,
1454 node
=> get_standard_option
('pve-node'),
1467 my $list = PVE
::APLInfo
::load_data
();
1470 for my $appliance (values %{$list->{all
}}) {
1471 next if $appliance->{'package'} eq 'pve-web-news';
1472 push @$res, $appliance;
1478 __PACKAGE__-
>register_method({
1479 name
=> 'apl_download',
1483 check
=> ['perm', '/storage/{storage}', ['Datastore.AllocateTemplate']],
1485 description
=> "Download appliance templates.",
1489 additionalProperties
=> 0,
1491 node
=> get_standard_option
('pve-node'),
1492 storage
=> get_standard_option
('pve-storage-id', {
1493 description
=> "The storage where the template will be stored",
1494 completion
=> \
&PVE
::Storage
::complete_storage_enabled
,
1498 description
=> "The template which will downloaded",
1500 completion
=> \
&complete_templet_repo
,
1504 returns
=> { type
=> "string" },
1508 my $rpcenv = PVE
::RPCEnvironment
::get
();
1509 my $user = $rpcenv->get_user();
1511 my $node = $param->{node
};
1512 my $template = $param->{template
};
1514 my $list = PVE
::APLInfo
::load_data
();
1515 my $appliance = $list->{all
}->{$template};
1516 raise_param_exc
({ template
=> "no such template"}) if !$appliance;
1518 my $cfg = PVE
::Storage
::config
();
1519 my $scfg = PVE
::Storage
::storage_check_enabled
($cfg, $param->{storage
}, $node);
1521 die "unknown template type '$appliance->{type}'\n"
1522 if !($appliance->{type
} eq 'openvz' || $appliance->{type
} eq 'lxc');
1524 die "storage '$param->{storage}' does not support templates\n"
1525 if !$scfg->{content
}->{vztmpl
};
1527 my $tmpldir = PVE
::Storage
::get_vztmpl_dir
($cfg, $param->{storage
});
1530 my $dccfg = PVE
::Cluster
::cfs_read_file
('datacenter.cfg');
1532 PVE
::Tools
::download_file_from_url
("$tmpldir/$template", $appliance->{location
}, {
1534 sha512sum
=> $appliance->{sha512sum
},
1535 md5sum
=> $appliance->{md5sum
},
1536 http_proxy
=> $dccfg->{http_proxy
},
1540 my $upid = $rpcenv->fork_worker('download', $template, $user, $worker);
1545 __PACKAGE__-
>register_method({
1546 name
=> 'query_url_metadata',
1547 path
=> 'query-url-metadata',
1549 description
=> "Query metadata of an URL: file size, file name and mime type.",
1552 check
=> ['perm', '/', [ 'Sys.Audit', 'Sys.Modify' ]],
1555 additionalProperties
=> 0,
1557 node
=> get_standard_option
('pve-node'),
1559 description
=> "The URL to query the metadata from.",
1561 pattern
=> 'https?://.*',
1563 'verify-certificates' => {
1564 description
=> "If false, no SSL/TLS certificates will be verified.",
1580 renderer
=> 'bytes',
1592 my $url = $param->{url
};
1594 my $ua = LWP
::UserAgent-
>new();
1595 $ua->agent("Proxmox VE");
1597 my $dccfg = PVE
::Cluster
::cfs_read_file
('datacenter.cfg');
1598 if ($dccfg->{http_proxy
}) {
1599 $ua->proxy('http', $dccfg->{http_proxy
});
1602 my $verify = $param->{'verify-certificates'} // 1;
1605 verify_hostname
=> 0,
1606 SSL_verify_mode
=> IO
::Socket
::SSL
::SSL_VERIFY_NONE
,
1610 my $req = HTTP
::Request-
>new(HEAD
=> $url);
1611 my $res = $ua->request($req);
1613 die "invalid server response: '" . $res->status_line() . "'\n" if ($res->code() != 200);
1615 my $size = $res->header("Content-Length");
1616 my $disposition = $res->header("Content-Disposition");
1617 my $type = $res->header("Content-Type");
1621 if ($disposition && ($disposition =~ m/filename="([^"]*)"/ || $disposition =~ m/filename=([^;]*)/)) {
1623 } elsif ($url =~ m!^[^?]+/([^?/]*)(?:\?.*)?$!) {
1627 # Content-Type: text/html; charset=utf-8
1628 if ($type && $type =~ m/^([^;]+);/) {
1633 $ret->{filename
} = $filename if $filename;
1634 $ret->{size
} = $size + 0 if $size;
1635 $ret->{mimetype
} = $type if $type;
1640 __PACKAGE__-
>register_method({
1645 check
=> ['perm', '/nodes/{node}', [ 'Sys.Audit' ]],
1648 description
=> "Gather various systems information about a node",
1651 additionalProperties
=> 0,
1653 node
=> get_standard_option
('pve-node'),
1660 return PVE
::Report
::generate
();
1663 # returns a list of VMIDs, those can be filtered by
1664 # * current parent node
1666 # * guest is a template (default: skip)
1667 # * guest is HA manged (default: skip)
1668 my $get_filtered_vmlist = sub {
1669 my ($nodename, $vmfilter, $templates, $ha_managed) = @_;
1671 my $vmlist = PVE
::Cluster
::get_vmlist
();
1674 if (defined($vmfilter)) {
1675 $vms_allowed = { map { $_ => 1 } PVE
::Tools
::split_list
($vmfilter) };
1679 foreach my $vmid (keys %{$vmlist->{ids
}}) {
1680 next if defined($vms_allowed) && !$vms_allowed->{$vmid};
1682 my $d = $vmlist->{ids
}->{$vmid};
1683 next if $nodename && $d->{node
} ne $nodename;
1687 if ($d->{type
} eq 'lxc') {
1688 $class = 'PVE::LXC::Config';
1689 } elsif ($d->{type
} eq 'qemu') {
1690 $class = 'PVE::QemuConfig';
1692 die "unknown virtual guest type '$d->{type}'\n";
1695 my $conf = $class->load_config($vmid);
1696 return if !$templates && $class->is_template($conf);
1697 return if !$ha_managed && PVE
::HA
::Config
::vm_is_ha_managed
($vmid);
1699 $res->{$vmid}->{conf
} = $conf;
1700 $res->{$vmid}->{type
} = $d->{type
};
1701 $res->{$vmid}->{class} = $class;
1709 # return all VMs which should get started/stopped on power up/down
1710 my $get_start_stop_list = sub {
1711 my ($nodename, $autostart, $vmfilter) = @_;
1713 # do not skip HA vms on force or if a specific VMID set is wanted
1714 my $include_ha_managed = defined($vmfilter) ?
1 : 0;
1716 my $vmlist = $get_filtered_vmlist->($nodename, $vmfilter, undef, $include_ha_managed);
1719 foreach my $vmid (keys %$vmlist) {
1720 my $conf = $vmlist->{$vmid}->{conf
};
1721 next if $autostart && !$conf->{onboot
};
1723 my $startup = $conf->{startup
} ? PVE
::JSONSchema
::pve_parse_startup_order
($conf->{startup
}) : {};
1724 my $order = $startup->{order
} = $startup->{order
} // LONG_MAX
;
1726 $resList->{$order}->{$vmid} = $startup;
1727 $resList->{$order}->{$vmid}->{type
} = $vmlist->{$vmid}->{type
};
1733 my $remove_locks_on_startup = sub {
1734 my ($nodename) = @_;
1736 my $vmlist = &$get_filtered_vmlist($nodename, undef, undef, 1);
1738 foreach my $vmid (keys %$vmlist) {
1739 my $conf = $vmlist->{$vmid}->{conf
};
1740 my $class = $vmlist->{$vmid}->{class};
1743 if ($class->has_lock($conf, 'backup')) {
1744 $class->remove_lock($vmid, 'backup');
1745 my $msg = "removed left over backup lock from '$vmid'!";
1746 warn "$msg\n"; # prints to task log
1747 syslog
('warning', $msg);
1753 __PACKAGE__-
>register_method ({
1759 check
=> ['perm', '/', [ 'VM.PowerMgmt' ]],
1762 description
=> "Start all VMs and containers located on this node (by default only those with onboot=1).",
1764 additionalProperties
=> 0,
1766 node
=> get_standard_option
('pve-node'),
1771 description
=> "Issue start command even if virtual guest have 'onboot' not set or set to off.",
1774 description
=> "Only consider guests from this comma separated list of VMIDs.",
1775 type
=> 'string', format
=> 'pve-vmid-list',
1786 my $rpcenv = PVE
::RPCEnvironment
::get
();
1787 my $authuser = $rpcenv->get_user();
1789 my $nodename = $param->{node
};
1790 $nodename = PVE
::INotify
::nodename
() if $nodename eq 'localhost';
1792 my $force = $param->{force
};
1796 $rpcenv->{type
} = 'priv'; # to start tasks in background
1798 if (!PVE
::Cluster
::check_cfs_quorum
(1)) {
1799 print "waiting for quorum ...\n";
1802 } while (!PVE
::Cluster
::check_cfs_quorum
(1));
1803 print "got quorum\n";
1806 eval { # remove backup locks, but avoid running into a scheduled backup job
1807 PVE
::Tools
::lock_file
('/var/run/vzdump.lock', 10, $remove_locks_on_startup, $nodename);
1810 my $autostart = $force ?
undef : 1;
1811 my $startList = &$get_start_stop_list($nodename, $autostart, $param->{vms
});
1813 # Note: use numeric sorting with <=>
1814 foreach my $order (sort {$a <=> $b} keys %$startList) {
1815 my $vmlist = $startList->{$order};
1817 foreach my $vmid (sort {$a <=> $b} keys %$vmlist) {
1818 my $d = $vmlist->{$vmid};
1820 PVE
::Cluster
::check_cfs_quorum
(); # abort when we loose quorum
1823 my $default_delay = 0;
1827 if ($d->{type
} eq 'lxc') {
1829 return if PVE
::LXC
::check_running
($vmid);
1830 print STDERR
"Starting CT $vmid\n";
1831 $upid = PVE
::API2
::LXC
::Status-
>vm_start({node
=> $nodename, vmid
=> $vmid });
1832 } elsif ($d->{type
} eq 'qemu') {
1834 $default_delay = 3; # to reduce load
1835 return if PVE
::QemuServer
::check_running
($vmid, 1);
1836 print STDERR
"Starting VM $vmid\n";
1837 $upid = PVE
::API2
::Qemu-
>vm_start({node
=> $nodename, vmid
=> $vmid });
1839 die "unknown VM type '$d->{type}'\n";
1842 my $res = PVE
::Tools
::upid_decode
($upid);
1843 while (PVE
::ProcFSTools
::check_process_running
($res->{pid
})) {
1847 my $status = PVE
::Tools
::upid_read_status
($upid);
1848 if (!PVE
::Tools
::upid_status_is_error
($status)) {
1849 # use default delay to reduce load
1850 my $delay = defined($d->{up
}) ?
int($d->{up
}) : $default_delay;
1852 print STDERR
"Waiting for $delay seconds (startup delay)\n" if $d->{up
};
1853 for (my $i = 0; $i < $delay; $i++) {
1858 print STDERR
"Starting $typeText $vmid failed: $status\n";
1867 return $rpcenv->fork_worker('startall', undef, $authuser, $code);
1870 my $create_stop_worker = sub {
1871 my ($nodename, $type, $vmid, $down_timeout) = @_;
1873 if ($type eq 'lxc') {
1874 return if !PVE
::LXC
::check_running
($vmid);
1875 my $timeout = int($down_timeout // 60);
1876 print STDERR
"Stopping CT $vmid (timeout = $timeout seconds)\n";
1877 return PVE
::API2
::LXC
::Status-
>vm_shutdown(
1878 { node
=> $nodename, vmid
=> $vmid, timeout
=> $timeout, forceStop
=> 1 }
1880 } elsif ($type eq 'qemu') {
1881 return if !PVE
::QemuServer
::check_running
($vmid, 1);
1882 my $timeout = int($down_timeout // 3 * 60);
1883 print STDERR
"Stopping VM $vmid (timeout = $timeout seconds)\n";
1884 return PVE
::API2
::Qemu-
>vm_shutdown(
1885 { node
=> $nodename, vmid
=> $vmid, timeout
=> $timeout, forceStop
=> 1 }
1888 die "unknown VM type '$type'\n";
1892 __PACKAGE__-
>register_method ({
1898 check
=> ['perm', '/', [ 'VM.PowerMgmt' ]],
1901 description
=> "Stop all VMs and Containers.",
1903 additionalProperties
=> 0,
1905 node
=> get_standard_option
('pve-node'),
1907 description
=> "Only consider Guests with these IDs.",
1908 type
=> 'string', format
=> 'pve-vmid-list',
1919 my $rpcenv = PVE
::RPCEnvironment
::get
();
1920 my $authuser = $rpcenv->get_user();
1922 my $nodename = $param->{node
};
1923 $nodename = PVE
::INotify
::nodename
() if $nodename eq 'localhost';
1927 $rpcenv->{type
} = 'priv'; # to start tasks in background
1929 my $stopList = &$get_start_stop_list($nodename, undef, $param->{vms
});
1931 my $cpuinfo = PVE
::ProcFSTools
::read_cpuinfo
();
1932 my $datacenterconfig = cfs_read_file
('datacenter.cfg');
1933 # if not set by user spawn max cpu count number of workers
1934 my $maxWorkers = $datacenterconfig->{max_workers
} || $cpuinfo->{cpus
};
1936 foreach my $order (sort {$b <=> $a} keys %$stopList) {
1937 my $vmlist = $stopList->{$order};
1940 my $finish_worker = sub {
1942 my $d = $workers->{$pid};
1944 delete $workers->{$pid};
1946 syslog
('info', "end task $d->{upid}");
1949 foreach my $vmid (sort {$b <=> $a} keys %$vmlist) {
1950 my $d = $vmlist->{$vmid};
1951 my $upid = eval { $create_stop_worker->($nodename, $d->{type
}, $vmid, $d->{down
}) };
1955 my $res = PVE
::Tools
::upid_decode
($upid, 1);
1958 my $pid = $res->{pid
};
1960 $workers->{$pid} = { type
=> $d->{type
}, upid
=> $upid, vmid
=> $vmid };
1961 while (scalar(keys %$workers) >= $maxWorkers) {
1962 foreach my $p (keys %$workers) {
1963 if (!PVE
::ProcFSTools
::check_process_running
($p)) {
1964 &$finish_worker($p);
1970 while (scalar(keys %$workers)) {
1971 foreach my $p (keys %$workers) {
1972 if (!PVE
::ProcFSTools
::check_process_running
($p)) {
1973 &$finish_worker($p);
1980 syslog
('info', "all VMs and CTs stopped");
1985 return $rpcenv->fork_worker('stopall', undef, $authuser, $code);
1988 my $create_migrate_worker = sub {
1989 my ($nodename, $type, $vmid, $target, $with_local_disks) = @_;
1992 if ($type eq 'lxc') {
1993 my $online = PVE
::LXC
::check_running
($vmid) ?
1 : 0;
1994 print STDERR
"Migrating CT $vmid\n";
1995 $upid = PVE
::API2
::LXC-
>migrate_vm({node
=> $nodename, vmid
=> $vmid, target
=> $target,
1996 restart
=> $online });
1997 } elsif ($type eq 'qemu') {
1998 print STDERR
"Check VM $vmid: ";
2000 my $online = PVE
::QemuServer
::check_running
($vmid, 1) ?
1 : 0;
2001 my $preconditions = PVE
::API2
::Qemu-
>migrate_vm_precondition({node
=> $nodename, vmid
=> $vmid, target
=> $target});
2002 my $invalidConditions = '';
2003 if ($online && !$with_local_disks && scalar @{$preconditions->{local_disks
}}) {
2004 $invalidConditions .= "\n Has local disks: " .
2005 join(', ', map { $_->{volid
} } @{$preconditions->{local_disks
}});
2008 if (@{$preconditions->{local_resources
}}) {
2009 $invalidConditions .= "\n Has local resources: " . join(', ', @{$preconditions->{local_resources
}});
2012 if ($invalidConditions && $invalidConditions ne '') {
2013 print STDERR
"skip VM $vmid - precondition check failed:";
2014 die "$invalidConditions\n";
2016 print STDERR
"precondition check passed\n";
2017 print STDERR
"Migrating VM $vmid\n";
2025 $params->{'with-local-disks'} = $with_local_disks if defined($with_local_disks);
2027 $upid = PVE
::API2
::Qemu-
>migrate_vm($params);
2029 die "unknown VM type '$type'\n";
2032 my $res = PVE
::Tools
::upid_decode
($upid);
2037 __PACKAGE__-
>register_method ({
2038 name
=> 'migrateall',
2039 path
=> 'migrateall',
2044 check
=> ['perm', '/', [ 'VM.Migrate' ]],
2046 description
=> "Migrate all VMs and Containers.",
2048 additionalProperties
=> 0,
2050 node
=> get_standard_option
('pve-node'),
2051 target
=> get_standard_option
('pve-node', { description
=> "Target node." }),
2053 description
=> "Maximal number of parallel migration job." .
2054 " If not set use 'max_workers' from datacenter.cfg," .
2055 " one of both must be set!",
2061 description
=> "Only consider Guests with these IDs.",
2062 type
=> 'string', format
=> 'pve-vmid-list',
2065 "with-local-disks" => {
2067 description
=> "Enable live storage migration for local disk",
2078 my $rpcenv = PVE
::RPCEnvironment
::get
();
2079 my $authuser = $rpcenv->get_user();
2081 my $nodename = $param->{node
};
2082 $nodename = PVE
::INotify
::nodename
() if $nodename eq 'localhost';
2084 my $target = $param->{target
};
2085 my $with_local_disks = $param->{'with-local-disks'};
2086 raise_param_exc
({ target
=> "target is local node."}) if $target eq $nodename;
2088 PVE
::Cluster
::check_cfs_quorum
();
2090 PVE
::Cluster
::check_node_exists
($target);
2092 my $datacenterconfig = cfs_read_file
('datacenter.cfg');
2093 # prefer parameter over datacenter cfg settings
2094 my $maxWorkers = $param->{maxworkers
} || $datacenterconfig->{max_workers
} ||
2095 die "either 'maxworkers' parameter or max_workers in datacenter.cfg must be set!\n";
2098 $rpcenv->{type
} = 'priv'; # to start tasks in background
2100 my $vmlist = &$get_filtered_vmlist($nodename, $param->{vms
}, 1, 1);
2101 if (!scalar(keys %$vmlist)) {
2102 warn "no virtual guests matched, nothing to do..\n";
2107 my $workers_started = 0;
2108 foreach my $vmid (sort keys %$vmlist) {
2109 my $d = $vmlist->{$vmid};
2111 eval { $pid = &$create_migrate_worker($nodename, $d->{type
}, $vmid, $target, $with_local_disks); };
2116 $workers->{$pid} = 1;
2117 while (scalar(keys %$workers) >= $maxWorkers) {
2118 foreach my $p (keys %$workers) {
2119 if (!PVE
::ProcFSTools
::check_process_running
($p)) {
2120 delete $workers->{$p};
2126 while (scalar(keys %$workers)) {
2127 foreach my $p (keys %$workers) {
2128 # FIXME: what about PID re-use ?!?!
2129 if (!PVE
::ProcFSTools
::check_process_running
($p)) {
2130 delete $workers->{$p};
2135 if ($workers_started <= 0) {
2136 die "no migrations worker started...\n";
2138 print STDERR
"All jobs finished, used $workers_started workers in total.\n";
2142 return $rpcenv->fork_worker('migrateall', undef, $authuser, $code);
2146 __PACKAGE__-
>register_method ({
2147 name
=> 'get_etc_hosts',
2153 check
=> ['perm', '/', [ 'Sys.Audit' ]],
2155 description
=> "Get the content of /etc/hosts.",
2157 additionalProperties
=> 0,
2159 node
=> get_standard_option
('pve-node'),
2165 digest
=> get_standard_option
('pve-config-digest'),
2168 description
=> 'The content of /etc/hosts.'
2175 return PVE
::INotify
::read_file
('etchosts');
2179 __PACKAGE__-
>register_method ({
2180 name
=> 'write_etc_hosts',
2186 check
=> ['perm', '/nodes/{node}', [ 'Sys.Modify' ]],
2188 description
=> "Write /etc/hosts.",
2190 additionalProperties
=> 0,
2192 node
=> get_standard_option
('pve-node'),
2193 digest
=> get_standard_option
('pve-config-digest'),
2196 description
=> 'The target content of /etc/hosts.'
2206 PVE
::Tools
::lock_file
('/var/lock/pve-etchosts.lck', undef, sub {
2207 if ($param->{digest
}) {
2208 my $hosts = PVE
::INotify
::read_file
('etchosts');
2209 PVE
::Tools
::assert_if_modified
($hosts->{digest
}, $param->{digest
});
2211 PVE
::INotify
::write_file
('etchosts', $param->{data
});
2218 # bash completion helper
2220 sub complete_templet_repo
{
2221 my ($cmdname, $pname, $cvalue) = @_;
2223 my $repo = PVE
::APLInfo
::load_data
();
2225 foreach my $templ (keys %{$repo->{all
}}) {
2226 next if $templ !~ m/^$cvalue/;
2233 package PVE
::API2
::Nodes
;
2238 use PVE
::SafeSyslog
;
2240 use PVE
::RESTHandler
;
2241 use PVE
::RPCEnvironment
;
2243 use PVE
::JSONSchema
qw(get_standard_option);
2245 use base
qw(PVE::RESTHandler);
2247 __PACKAGE__-
>register_method ({
2248 subclass
=> "PVE::API2::Nodes::Nodeinfo",
2252 __PACKAGE__-
>register_method ({
2256 permissions
=> { user
=> 'all' },
2257 description
=> "Cluster node index.",
2259 additionalProperties
=> 0,
2267 node
=> get_standard_option
('pve-node'),
2269 description
=> "Node status.",
2271 enum
=> ['unknown', 'online', 'offline'],
2274 description
=> "CPU utilization.",
2277 renderer
=> 'fraction_as_percentage',
2280 description
=> "Number of available CPUs.",
2285 description
=> "Used memory in bytes.",
2288 renderer
=> 'bytes',
2291 description
=> "Number of available memory in bytes.",
2294 renderer
=> 'bytes',
2297 description
=> "Support level.",
2302 description
=> "Node uptime in seconds.",
2305 renderer
=> 'duration',
2307 ssl_fingerprint
=> {
2308 description
=> "The SSL fingerprint for the node certificate.",
2314 links
=> [ { rel
=> 'child', href
=> "{node}" } ],
2319 my $rpcenv = PVE
::RPCEnvironment
::get
();
2320 my $authuser = $rpcenv->get_user();
2322 my $clinfo = PVE
::Cluster
::get_clinfo
();
2325 my $nodelist = PVE
::Cluster
::get_nodelist
();
2326 my $members = PVE
::Cluster
::get_members
();
2327 my $rrd = PVE
::Cluster
::rrd_dump
();
2329 foreach my $node (@$nodelist) {
2330 my $can_audit = $rpcenv->check($authuser, "/nodes/$node", [ 'Sys.Audit' ], 1);
2331 my $entry = PVE
::API2Tools
::extract_node_stats
($node, $members, $rrd, !$can_audit);
2333 $entry->{ssl_fingerprint
} = eval { PVE
::Cluster
::get_node_fingerprint
($node) };