]>
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
;
19 use PMG
::API2
::Postfix
;
21 use base
qw(PVE::RESTHandler);
23 __PACKAGE__-
>register_method ({
24 subclass
=> "PMG::API2::Postfix",
28 __PACKAGE__-
>register_method ({
29 subclass
=> "PMG::API2::ClamAV",
33 __PACKAGE__-
>register_method ({
34 subclass
=> "PMG::API2::Network",
38 __PACKAGE__-
>register_method ({
39 subclass
=> "PMG::API2::Tasks",
43 __PACKAGE__-
>register_method ({
44 subclass
=> "PMG::API2::Services",
48 __PACKAGE__-
>register_method ({
52 permissions
=> { user
=> 'all' },
53 description
=> "Node index.",
55 additionalProperties
=> 0,
57 node
=> get_standard_option
('pve-node'),
66 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
73 { name
=> 'postfix' },
74 { name
=> 'services' },
78 { name
=> 'vncshell' },
79 { name
=> 'rrddata' },
85 __PACKAGE__-
>register_method({
89 protected
=> 1, # fixme: can we avoid that?
91 description
=> "Read node RRD statistics",
93 additionalProperties
=> 0,
95 node
=> get_standard_option
('pve-node'),
97 description
=> "Specify the time frame you are interested in.",
99 enum
=> [ 'hour', 'day', 'week', 'month', 'year' ],
102 description
=> "The RRD consolidation function",
104 enum
=> [ 'AVERAGE', 'MAX' ],
119 return PMG
::Utils
::create_rrd_data
(
120 "pmg-node-v1.rrd", $param->{timeframe
}, $param->{cf
});
124 __PACKAGE__-
>register_method({
128 description
=> "Read system log",
132 additionalProperties
=> 0,
134 node
=> get_standard_option
('pve-node'),
147 pattern
=> '^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$',
148 description
=> "Display all log since this date-time string.",
153 pattern
=> '^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$',
154 description
=> "Display all log until this date-time string.",
165 description
=> "Line number",
169 description
=> "Line text",
178 my $restenv = PVE
::RESTEnvironment
::get
();
180 my ($count, $lines) = PVE
::Tools
::dump_journal
($param->{start
}, $param->{limit
},
181 $param->{since
}, $param->{'until'});
183 $restenv->set_result_attrib('total', $count);
188 __PACKAGE__-
>register_method ({
193 description
=> "Creates a VNC Shell proxy.",
195 additionalProperties
=> 0,
197 node
=> get_standard_option
('pve-node'),
201 description
=> "use websocket instead of standard vnc.",
207 additionalProperties
=> 0,
209 user
=> { type
=> 'string' },
210 ticket
=> { type
=> 'string' },
211 port
=> { type
=> 'integer' },
212 upid
=> { type
=> 'string' },
218 my $node = $param->{node
};
220 # we only implement the websocket based VNC here
221 my $websocket = $param->{websocket
} // 1;
222 die "standard VNC not implemented" if !$websocket;
224 my $authpath = "/nodes/$node";
226 my $restenv = PVE
::RESTEnvironment-
>get();
227 my $user = $restenv->get_user();
229 my $ticket = PMG
::Ticket
::assemble_vnc_ticket
($user, $authpath);
231 my $family = PVE
::Tools
::get_host_address_family
($node);
232 my $port = PVE
::Tools
::next_vnc_port
($family);
236 if ($user eq 'root@pam') {
237 $shcmd = [ '/bin/login', '-f', 'root' ];
239 $shcmd = [ '/bin/login' ];
242 my $cmd = ['/usr/bin/vncterm', '-rfbport', $port,
243 '-timeout', 10, '-notls', '-listen', 'localhost',
249 syslog
('info', "starting vnc proxy $upid\n");
251 my $cmdstr = join (' ', @$cmd);
252 syslog
('info', "launch command: $cmdstr");
255 foreach my $k (keys %ENV) {
256 next if $k eq 'PATH' || $k eq 'TERM' || $k eq 'USER' || $k eq 'HOME';
261 $ENV{PVE_VNC_TICKET
} = $ticket; # pass ticket to vncterm
263 PVE
::Tools
::run_command
($cmd, errmsg
=> "vncterm failed");
272 my $upid = $restenv->fork_worker('vncshell', "", $user, $realcmd);
274 PVE
::Tools
::wait_for_vnc_port
($port);
284 __PACKAGE__-
>register_method({
285 name
=> 'vncwebsocket',
286 path
=> 'vncwebsocket',
288 description
=> "Opens a weksocket for VNC traffic.",
290 additionalProperties
=> 0,
292 node
=> get_standard_option
('pve-node'),
294 description
=> "Ticket from previous call to vncproxy.",
299 description
=> "Port number returned by previous vncproxy call.",
309 port
=> { type
=> 'string' },
315 my $authpath = "/nodes/$param->{node}";
317 my $restenv = PVE
::RESTEnvironment-
>get();
318 my $user = $restenv->get_user();
320 PMG
::Ticket
::verify_vnc_ticket
($param->{vncticket
}, $user, $authpath);
322 my $port = $param->{port
};
324 return { port
=> $port };
327 __PACKAGE__-
>register_method({
331 description
=> "Read DNS settings.",
334 additionalProperties
=> 0,
336 node
=> get_standard_option
('pve-node'),
341 additionalProperties
=> 0,
344 description
=> "Search domain for host-name lookup.",
349 description
=> 'First name server IP address.',
354 description
=> 'Second name server IP address.',
359 description
=> 'Third name server IP address.',
368 my $res = PVE
::INotify
::read_file
('resolvconf');
373 __PACKAGE__-
>register_method({
374 name
=> 'update_dns',
377 description
=> "Write DNS settings.",
381 additionalProperties
=> 0,
383 node
=> get_standard_option
('pve-node'),
385 description
=> "Search domain for host-name lookup.",
389 description
=> 'First name server IP address.',
390 type
=> 'string', format
=> 'ip',
394 description
=> 'Second name server IP address.',
395 type
=> 'string', format
=> 'ip',
399 description
=> 'Third name server IP address.',
400 type
=> 'string', format
=> 'ip',
405 returns
=> { type
=> "null" },
409 PVE
::INotify
::update_file
('resolvconf', $param);
415 __PACKAGE__-
>register_method({
419 description
=> "Read server time and time zone settings.",
422 additionalProperties
=> 0,
424 node
=> get_standard_option
('pve-node'),
429 additionalProperties
=> 0,
432 description
=> "Time zone",
436 description
=> "Seconds since 1970-01-01 00:00:00 UTC.",
438 minimum
=> 1297163644,
441 description
=> "Seconds since 1970-01-01 00:00:00 (local time)",
443 minimum
=> 1297163644,
451 my $ltime = timegm_nocheck
(localtime($ctime));
453 timezone
=> PVE
::INotify
::read_file
('timezone'),
461 __PACKAGE__-
>register_method({
462 name
=> 'set_timezone',
465 description
=> "Set time zone.",
469 additionalProperties
=> 0,
471 node
=> get_standard_option
('pve-node'),
473 description
=> "Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names.",
478 returns
=> { type
=> "null" },
482 PVE
::INotify
::write_file
('timezone', $param->{timezone
});
488 package PMG
::API2
::Nodes
;
493 use PVE
::RESTHandler
;
494 use PVE
::JSONSchema
qw(get_standard_option);
496 use base
qw(PVE::RESTHandler);
498 __PACKAGE__-
>register_method ({
499 subclass
=> "PMG::API2::NodeInfo",
503 __PACKAGE__-
>register_method ({
507 permissions
=> { user
=> 'all' },
508 description
=> "Cluster node index.",
510 additionalProperties
=> 0,
519 links
=> [ { rel
=> 'child', href
=> "{node}" } ],
524 my $nodename = PVE
::INotify
::nodename
();
526 { node
=> $nodename },