]>
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 description
=> "Read system log",
85 additionalProperties
=> 0,
87 node
=> get_standard_option
('pve-node'),
100 pattern
=> '^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$',
101 description
=> "Display all log since this date-time string.",
106 pattern
=> '^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$',
107 description
=> "Display all log until this date-time string.",
118 description
=> "Line number",
122 description
=> "Line text",
131 my $restenv = PVE
::RESTEnvironment
::get
();
133 my ($count, $lines) = PVE
::Tools
::dump_journal
($param->{start
}, $param->{limit
},
134 $param->{since
}, $param->{'until'});
136 $restenv->set_result_attrib('total', $count);
141 __PACKAGE__-
>register_method ({
146 description
=> "Creates a VNC Shell proxy.",
148 additionalProperties
=> 0,
150 node
=> get_standard_option
('pve-node'),
154 description
=> "use websocket instead of standard vnc.",
160 additionalProperties
=> 0,
162 user
=> { type
=> 'string' },
163 ticket
=> { type
=> 'string' },
164 port
=> { type
=> 'integer' },
165 upid
=> { type
=> 'string' },
171 my $node = $param->{node
};
173 # we only implement the websocket based VNC here
174 my $websocket = $param->{websocket
} // 1;
175 die "standard VNC not implemented" if !$websocket;
177 my $authpath = "/nodes/$node";
179 my $restenv = PVE
::RESTEnvironment-
>get();
180 my $user = $restenv->get_user();
182 my $ticket = PMG
::Ticket
::assemble_vnc_ticket
($user, $authpath);
184 my $family = PVE
::Tools
::get_host_address_family
($node);
185 my $port = PVE
::Tools
::next_vnc_port
($family);
187 my $cmd = ['/usr/bin/vncterm', '-rfbport', $port,
188 '-timeout', 10, '-notls', '-listen', 'localhost',
189 '-c', '/usr/bin/top'];
194 syslog
('info', "starting vnc proxy $upid\n");
196 my $cmdstr = join (' ', @$cmd);
197 syslog
('info', "launch command: $cmdstr");
200 foreach my $k (keys %ENV) {
201 next if $k eq 'PATH' || $k eq 'TERM' || $k eq 'USER' || $k eq 'HOME';
206 $ENV{PVE_VNC_TICKET
} = $ticket; # pass ticket to vncterm
208 PVE
::Tools
::run_command
($cmd, errmsg
=> "vncterm failed");
217 my $upid = $restenv->fork_worker('vncshell', "", $user, $realcmd);
219 PVE
::Tools
::wait_for_vnc_port
($port);
229 __PACKAGE__-
>register_method({
230 name
=> 'vncwebsocket',
231 path
=> 'vncwebsocket',
233 description
=> "Opens a weksocket for VNC traffic.",
235 additionalProperties
=> 0,
237 node
=> get_standard_option
('pve-node'),
239 description
=> "Ticket from previous call to vncproxy.",
244 description
=> "Port number returned by previous vncproxy call.",
254 port
=> { type
=> 'string' },
260 my $authpath = "/nodes/$param->{node}";
262 my $restenv = PVE
::RESTEnvironment-
>get();
263 my $user = $restenv->get_user();
265 PMG
::Ticket
::verify_vnc_ticket
($param->{vncticket
}, $user, $authpath);
267 my $port = $param->{port
};
269 return { port
=> $port };
272 __PACKAGE__-
>register_method({
276 description
=> "Read DNS settings.",
279 additionalProperties
=> 0,
281 node
=> get_standard_option
('pve-node'),
286 additionalProperties
=> 0,
289 description
=> "Search domain for host-name lookup.",
294 description
=> 'First name server IP address.',
299 description
=> 'Second name server IP address.',
304 description
=> 'Third name server IP address.',
313 my $res = PVE
::INotify
::read_file
('resolvconf');
318 __PACKAGE__-
>register_method({
319 name
=> 'update_dns',
322 description
=> "Write DNS settings.",
326 additionalProperties
=> 0,
328 node
=> get_standard_option
('pve-node'),
330 description
=> "Search domain for host-name lookup.",
334 description
=> 'First name server IP address.',
335 type
=> 'string', format
=> 'ip',
339 description
=> 'Second name server IP address.',
340 type
=> 'string', format
=> 'ip',
344 description
=> 'Third name server IP address.',
345 type
=> 'string', format
=> 'ip',
350 returns
=> { type
=> "null" },
354 PVE
::INotify
::update_file
('resolvconf', $param);
360 __PACKAGE__-
>register_method({
364 description
=> "Read server time and time zone settings.",
367 additionalProperties
=> 0,
369 node
=> get_standard_option
('pve-node'),
374 additionalProperties
=> 0,
377 description
=> "Time zone",
381 description
=> "Seconds since 1970-01-01 00:00:00 UTC.",
383 minimum
=> 1297163644,
386 description
=> "Seconds since 1970-01-01 00:00:00 (local time)",
388 minimum
=> 1297163644,
396 my $ltime = timegm_nocheck
(localtime($ctime));
398 timezone
=> PVE
::INotify
::read_file
('timezone'),
406 __PACKAGE__-
>register_method({
407 name
=> 'set_timezone',
410 description
=> "Set time zone.",
414 additionalProperties
=> 0,
416 node
=> get_standard_option
('pve-node'),
418 description
=> "Time zone. The file '/usr/share/zoneinfo/zone.tab' contains the list of valid names.",
423 returns
=> { type
=> "null" },
427 PVE
::INotify
::write_file
('timezone', $param->{timezone
});
433 package PMG
::API2
::Nodes
;
438 use PVE
::RESTHandler
;
439 use PVE
::JSONSchema
qw(get_standard_option);
441 use base
qw(PVE::RESTHandler);
443 __PACKAGE__-
>register_method ({
444 subclass
=> "PMG::API2::NodeInfo",
448 __PACKAGE__-
>register_method ({
452 permissions
=> { user
=> 'all' },
453 description
=> "Cluster node index.",
455 additionalProperties
=> 0,
464 links
=> [ { rel
=> 'child', href
=> "{node}" } ],
469 my $nodename = PVE
::INotify
::nodename
();
471 { node
=> $nodename },