]>
git.proxmox.com Git - pmg-api.git/blob - PMG/API2/Nodes.pm
1 package PMG
::API2
::NodeInfo
;
8 use PVE
::JSONSchema
qw(get_standard_option);
9 use PVE
::RESTEnvironment
;
14 use base
qw(PVE::RESTHandler);
16 __PACKAGE__-
>register_method ({
20 permissions
=> { user
=> 'all' },
21 description
=> "Node index.",
23 additionalProperties
=> 0,
25 node
=> get_standard_option
('pve-node'),
34 links
=> [ { rel
=> 'child', href
=> "{name}" } ],
40 { name
=> 'vncshell' },
46 __PACKAGE__-
>register_method ({
50 description
=> "Creates a VNC Shell proxy.",
52 additionalProperties
=> 0,
54 node
=> get_standard_option
('pve-node'),
58 description
=> "use websocket instead of standard vnc.",
64 additionalProperties
=> 0,
66 user
=> { type
=> 'string' },
67 ticket
=> { type
=> 'string' },
68 port
=> { type
=> 'integer' },
69 upid
=> { type
=> 'string' },
75 my $node = $param->{node
};
77 # we only implement the websocket based VNC here
78 my $websocket = $param->{websocket
} // 1;
79 die "standard VNC not implemented" if !$websocket;
81 my $authpath = "/nodes/$node";
83 my $restenv = PVE
::RESTEnvironment-
>get();
84 my $user = $restenv->get_user();
86 my $ticket = PMG
::Ticket
::assemble_vnc_ticket
($user, $authpath);
88 my $family = PVE
::Tools
::get_host_address_family
($node);
89 my $port = PVE
::Tools
::next_vnc_port
($family);
91 my $cmd = ['/usr/bin/vncterm', '-rfbport', $port,
92 '-timeout', 10, '-notls', '-listen', 'localhost',
93 '-c', '/usr/bin/top'];
98 syslog
('info', "starting vnc proxy $upid\n");
100 my $cmdstr = join (' ', @$cmd);
101 syslog
('info', "launch command: $cmdstr");
104 foreach my $k (keys %ENV) {
105 next if $k eq 'PATH' || $k eq 'TERM' || $k eq 'USER' || $k eq 'HOME';
110 $ENV{PVE_VNC_TICKET
} = $ticket; # pass ticket to vncterm
112 PVE
::Tools
::run_command
($cmd, errmsg
=> "vncterm failed");
121 my $upid = $restenv->fork_worker('vncshell', "", $user, $realcmd);
123 PVE
::Tools
::wait_for_vnc_port
($port);
133 __PACKAGE__-
>register_method({
134 name
=> 'vncwebsocket',
135 path
=> 'vncwebsocket',
137 description
=> "Opens a weksocket for VNC traffic.",
139 additionalProperties
=> 0,
141 node
=> get_standard_option
('pve-node'),
143 description
=> "Ticket from previous call to vncproxy.",
148 description
=> "Port number returned by previous vncproxy call.",
158 port
=> { type
=> 'string' },
164 my $authpath = "/nodes/$param->{node}";
166 my $restenv = PVE
::RESTEnvironment-
>get();
167 my $user = $restenv->get_user();
169 PMG
::Ticket
::verify_vnc_ticket
($param->{vncticket
}, $user, $authpath);
171 my $port = $param->{port
};
173 return { port
=> $port };
177 package PMG
::API2
::Nodes
;
182 use PVE
::RESTHandler
;
183 use PVE
::JSONSchema
qw(get_standard_option);
185 use base
qw(PVE::RESTHandler);
187 __PACKAGE__-
>register_method ({
188 subclass
=> "PMG::API2::NodeInfo",
192 __PACKAGE__-
>register_method ({
196 permissions
=> { user
=> 'all' },
197 description
=> "Cluster node index.",
199 additionalProperties
=> 0,
208 links
=> [ { rel
=> 'child', href
=> "{node}" } ],
213 my $nodename = PVE
::INotify
::nodename
();
215 { node
=> $nodename },