]>
git.proxmox.com Git - pmg-api.git/blob - PMG/API2/Nodes.pm
1 package PMG
::API2
::NodeInfo
;
6 use Time
::Local
qw(timegm_nocheck);
10 use PVE
::JSONSchema
qw(get_standard_option);
11 use PVE
::RESTEnvironment
;
16 use PMG
::API2
::Services
;
17 use PMG
::API2
::Network
;
18 use PMG
::API2
::ClamAV
;
20 use base
qw(PVE::RESTHandler);
22 __PACKAGE__-
>register_method ({
23 subclass
=> "PMG::API2::ClamAV",
27 __PACKAGE__-
>register_method ({
28 subclass
=> "PMG::API2::Network",
32 __PACKAGE__-
>register_method ({
33 subclass
=> "PMG::API2::Tasks",
37 __PACKAGE__-
>register_method ({
38 subclass
=> "PMG::API2::Services",
42 __PACKAGE__-
>register_method ({
46 permissions
=> { user
=> 'all' },
47 description
=> "Node index.",
49 additionalProperties
=> 0,
51 node
=> get_standard_option
('pve-node'),
60 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
67 { name
=> 'services' },
71 { name
=> 'vncshell' },
77 __PACKAGE__-
>register_method({
81 protected
=> 1, # fixme: can we avoid that?
83 description
=> "Read node RRD statistics",
85 additionalProperties
=> 0,
87 node
=> get_standard_option
('pve-node'),
89 description
=> "Specify the time frame you are interested in.",
91 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
94 description
=> "The RRD consolidation function",
96 enum
=> [ 'AVERAGE', 'MAX' ],
111 return PMG
::Utils
::create_rrd_data
(
112 "pmg-node-v1.rrd", $param->{timeframe
}, $param->{cf
});
116 __PACKAGE__-
>register_method({
120 description
=> "Read system log",
124 additionalProperties
=> 0,
126 node
=> get_standard_option
('pve-node'),
139 pattern
=> '^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$',
140 description
=> "Display all log since this date-time string.",
145 pattern
=> '^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$',
146 description
=> "Display all log until this date-time string.",
157 description
=> "Line number",
161 description
=> "Line text",
170 my $restenv = PVE
::RESTEnvironment
::get
();
172 my ($count, $lines) = PVE
::Tools
::dump_journal
($param->{start
}, $param->{limit
},
173 $param->{since
}, $param->{'until'});
175 $restenv->set_result_attrib('total', $count);
180 __PACKAGE__-
>register_method ({
185 description
=> "Creates a VNC Shell proxy.",
187 additionalProperties
=> 0,
189 node
=> get_standard_option
('pve-node'),
193 description
=> "use websocket instead of standard vnc.",
199 additionalProperties
=> 0,
201 user
=> { type
=> 'string' },
202 ticket
=> { type
=> 'string' },
203 port
=> { type
=> 'integer' },
204 upid
=> { type
=> 'string' },
210 my $node = $param->{node
};
212 # we only implement the websocket based VNC here
213 my $websocket = $param->{websocket
} // 1;
214 die "standard VNC not implemented" if !$websocket;
216 my $authpath = "/nodes/$node";
218 my $restenv = PVE
::RESTEnvironment-
>get();
219 my $user = $restenv->get_user();
221 my $ticket = PMG
::Ticket
::assemble_vnc_ticket
($user, $authpath);
223 my $family = PVE
::Tools
::get_host_address_family
($node);
224 my $port = PVE
::Tools
::next_vnc_port
($family);
228 if ($user eq 'root@pam') {
229 $shcmd = [ '/bin/login', '-f', 'root' ];
231 $shcmd = [ '/bin/login' ];
234 my $cmd = ['/usr/bin/vncterm', '-rfbport', $port,
235 '-timeout', 10, '-notls', '-listen', 'localhost',
241 syslog
('info', "starting vnc proxy $upid\n");
243 my $cmdstr = join (' ', @$cmd);
244 syslog
('info', "launch command: $cmdstr");
247 foreach my $k (keys %ENV) {
248 next if $k eq 'PATH' || $k eq 'TERM' || $k eq 'USER' || $k eq 'HOME';
253 $ENV{PVE_VNC_TICKET
} = $ticket; # pass ticket to vncterm
255 PVE
::Tools
::run_command
($cmd, errmsg
=> "vncterm failed");
264 my $upid = $restenv->fork_worker('vncshell', "", $user, $realcmd);
266 PVE
::Tools
::wait_for_vnc_port
($port);
276 __PACKAGE__-
>register_method({
277 name
=> 'vncwebsocket',
278 path
=> 'vncwebsocket',
280 description
=> "Opens a weksocket for VNC traffic.",
282 additionalProperties
=> 0,
284 node
=> get_standard_option
('pve-node'),
286 description
=> "Ticket from previous call to vncproxy.",
291 description
=> "Port number returned by previous vncproxy call.",
301 port
=> { type
=> 'string' },
307 my $authpath = "/nodes/$param->{node}";
309 my $restenv = PVE
::RESTEnvironment-
>get();
310 my $user = $restenv->get_user();
312 PMG
::Ticket
::verify_vnc_ticket
($param->{vncticket
}, $user, $authpath);
314 my $port = $param->{port
};
316 return { port
=> $port };
319 __PACKAGE__-
>register_method({
323 description
=> "Read DNS settings.",
326 additionalProperties
=> 0,
328 node
=> get_standard_option
('pve-node'),
333 additionalProperties
=> 0,
336 description
=> "Search domain for host-name lookup.",
341 description
=> 'First name server IP address.',
346 description
=> 'Second name server IP address.',
351 description
=> 'Third name server IP address.',
360 my $res = PVE
::INotify
::read_file
('resolvconf');
365 __PACKAGE__-
>register_method({
366 name
=> 'update_dns',
369 description
=> "Write DNS settings.",
373 additionalProperties
=> 0,
375 node
=> get_standard_option
('pve-node'),
377 description
=> "Search domain for host-name lookup.",
381 description
=> 'First name server IP address.',
382 type
=> 'string', format
=> 'ip',
386 description
=> 'Second name server IP address.',
387 type
=> 'string', format
=> 'ip',
391 description
=> 'Third name server IP address.',
392 type
=> 'string', format
=> 'ip',
397 returns
=> { type
=> "null" },
401 PVE
::INotify
::update_file
('resolvconf', $param);
407 __PACKAGE__-
>register_method({
411 description
=> "Read server time and time zone settings.",
414 additionalProperties
=> 0,
416 node
=> get_standard_option
('pve-node'),
421 additionalProperties
=> 0,
424 description
=> "Time zone",
428 description
=> "Seconds since 1970-01-01 00:00:00 UTC.",
430 minimum
=> 1297163644,
433 description
=> "Seconds since 1970-01-01 00:00:00 (local time)",
435 minimum
=> 1297163644,
443 my $ltime = timegm_nocheck
(localtime($ctime));
445 timezone
=> PVE
::INotify
::read_file
('timezone'),
453 __PACKAGE__-
>register_method({
454 name
=> 'set_timezone',
457 description
=> "Set time zone.",
461 additionalProperties
=> 0,
463 node
=> get_standard_option
('pve-node'),
465 description
=> "Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names.",
470 returns
=> { type
=> "null" },
474 PVE
::INotify
::write_file
('timezone', $param->{timezone
});
480 package PMG
::API2
::Nodes
;
485 use PVE
::RESTHandler
;
486 use PVE
::JSONSchema
qw(get_standard_option);
488 use base
qw(PVE::RESTHandler);
490 __PACKAGE__-
>register_method ({
491 subclass
=> "PMG::API2::NodeInfo",
495 __PACKAGE__-
>register_method ({
499 permissions
=> { user
=> 'all' },
500 description
=> "Cluster node index.",
502 additionalProperties
=> 0,
511 links
=> [ { rel
=> 'child', href
=> "{node}" } ],
516 my $nodename = PVE
::INotify
::nodename
();
518 { node
=> $nodename },