[pve-devel] r5450 - in pve-manager/pve2: lib/PVE lib/PVE/API2 www/manager www/manager/data www/manager/form www/manager/window
svn-commits at proxmox.com
svn-commits at proxmox.com
Thu Jan 27 14:04:56 CET 2011
Author: dietmar
Date: 2011-01-27 14:04:56 +0100 (Thu, 27 Jan 2011)
New Revision: 5450
Added:
pve-manager/pve2/lib/PVE/API2/Nodes.pm
Modified:
pve-manager/pve2/lib/PVE/API2.pm
pve-manager/pve2/lib/PVE/API2/Cluster.pm
pve-manager/pve2/lib/PVE/API2/Makefile.am
pve-manager/pve2/lib/PVE/APIDaemon.pm
pve-manager/pve2/lib/PVE/REST.pm
pve-manager/pve2/www/manager/KVMConfig.js
pve-manager/pve2/www/manager/PVECache.js
pve-manager/pve2/www/manager/PVEConsole.js
pve-manager/pve2/www/manager/PVEUtils.js
pve-manager/pve2/www/manager/ResourceTree.js
pve-manager/pve2/www/manager/Workspace.js
pve-manager/pve2/www/manager/data/ObjectStore.js
pve-manager/pve2/www/manager/form/ModifyDirStorage.js
pve-manager/pve2/www/manager/window/LoginWindow.js
Log:
better console support, more API changes
Modified: pve-manager/pve2/lib/PVE/API2/Cluster.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Cluster.pm 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/lib/PVE/API2/Cluster.pm 2011-01-27 13:04:56 UTC (rev 5450)
@@ -21,7 +21,7 @@
name => 'index',
path => '',
method => 'GET',
- description => "Cluster node index.",
+ description => "Cluster index.",
parameters => {
additionalProperties => 0,
properties => {},
@@ -38,65 +38,12 @@
my ($param) = @_;
my $result = [
- { name => 'nodes' },
{ name => 'log' },
];
return $result;
}});
-__PACKAGE__->register_method ({
- name => 'nodes',
- path => 'nodes',
- method => 'GET',
- description => "Cluster node index.",
- parameters => {
- additionalProperties => 0,
- properties => {},
- },
- returns => {
- type => 'array',
- items => {
- type => "object",
- properties => {},
- },
- },
- code => sub {
- my ($param) = @_;
-
-
- my $clinfo = PVE::Cluster::get_clinfo();
- my $result = [];
-
- my $nodename = PVE::INotify::nodename();
- my $nodelist = $clinfo->{nodelist};
-
- if (!$nodelist) {
- push @$result, {
- name => $nodename,
- cpu => 0.5,
- maxcpu => 16,
- uptime => 20*3600*24,
- mem => 0,
- maxmem => 10
- };
- return $result;
- }
-
- foreach my $node (keys %$nodelist) {
- push @$result, {
- name => $node,
- cpu => 0.1,
- maxcpu => 8,
- uptime => 10*3600*24,
- mem => 0,
- maxmem => 10
- };
- }
-
- return $result;
- }});
-
__PACKAGE__->register_method({
name => 'log',
path => 'log',
Modified: pve-manager/pve2/lib/PVE/API2/Makefile.am
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Makefile.am 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/lib/PVE/API2/Makefile.am 2011-01-27 13:04:56 UTC (rev 5450)
@@ -4,6 +4,7 @@
pvelib_DATA = \
Cluster.pm \
+ Nodes.pm \
VM.pm
CLEANFILES = *~
Added: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm (rev 0)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm 2011-01-27 13:04:56 UTC (rev 5450)
@@ -0,0 +1,113 @@
+package PVE::API2::Nodes::Nodeinfo;
+
+use strict;
+use warnings;
+
+use PVE::SafeSyslog;
+use PVE::Cluster;
+use PVE::RESTHandler;
+use PVE::RPCEnvironment;
+use PVE::JSONSchema qw(get_standard_option);
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method ({
+ name => 'index',
+ path => '',
+ method => 'GET',
+ description => "Cluster index.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {},
+ },
+ links => [ { rel => 'child', href => "{name}" } ],
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $result = [
+ { name => 'syslog' },
+ ];
+
+ return $result;
+ }});
+
+
+package PVE::API2::Nodes;
+
+use strict;
+use warnings;
+
+use PVE::SafeSyslog;
+use PVE::Cluster;
+use PVE::RESTHandler;
+use PVE::RPCEnvironment;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method ({
+ subclass => "PVE::API2::Nodes::Nodeinfo",
+ path => '{node}',
+});
+
+__PACKAGE__->register_method ({
+ name => 'index',
+ path => '',
+ method => 'GET',
+ description => "Cluster node index.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {},
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {},
+ },
+ links => [ { rel => 'child', href => "{name}" } ],
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $clinfo = PVE::Cluster::get_clinfo();
+ my $result = [];
+
+ my $nodename = PVE::INotify::nodename();
+ my $nodelist = $clinfo->{nodelist};
+
+ if (!$nodelist) {
+ push @$result, {
+ name => $nodename,
+ cpu => 0.5,
+ maxcpu => 16,
+ uptime => 20*3600*24,
+ mem => 0,
+ maxmem => 10
+ };
+ return $result;
+ }
+
+ foreach my $node (keys %$nodelist) {
+ push @$result, {
+ name => $node,
+ cpu => 0.1,
+ maxcpu => 8,
+ uptime => 10*3600*24,
+ mem => 0,
+ maxmem => 10
+ };
+ }
+
+ return $result;
+ }});
+
+1;
Modified: pve-manager/pve2/lib/PVE/API2.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2.pm 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/lib/PVE/API2.pm 2011-01-27 13:04:56 UTC (rev 5450)
@@ -11,6 +11,7 @@
# preload classes
use PVE::API2::VM;
use PVE::API2::Cluster;
+use PVE::API2::Nodes;
use PVE::API2::Storage;
use PVE::API2::AccessControl;
@@ -25,6 +26,11 @@
});
__PACKAGE__->register_method ({
+ subclass => "PVE::API2::Nodes",
+ path => 'nodes',
+});
+
+__PACKAGE__->register_method ({
subclass => "PVE::API2::Storage",
path => 'storage',
});
Modified: pve-manager/pve2/lib/PVE/APIDaemon.pm
===================================================================
--- pve-manager/pve2/lib/PVE/APIDaemon.pm 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/lib/PVE/APIDaemon.pm 2011-01-27 13:04:56 UTC (rev 5450)
@@ -203,6 +203,13 @@
$c->send_response(HTTP::Response->new($code, $msg));
}
+my $known_methods = {
+ GET => 1,
+ POST => 1,
+ PUT => 1,
+ DELETE => 1,
+};
+
sub handle_requests {
my ($self, $rpcenv) = @_;
@@ -235,6 +242,13 @@
my $method = $r->method();
+ syslog('info', "perl method $method");
+
+ if (!$known_methods->{$method}) {
+ $c->send_error(HTTP_NOT_IMPLEMENTED);
+ last;
+ }
+
my $uri = $r->uri->path();
syslog('info', "start $method $uri");
@@ -253,6 +267,7 @@
my $parser = HTTP::Request::Params->new({req => $r});
my $params = $parser->params;
+ syslog('info', "PA: " . Dumper($params));
PVE::Cluster::cfs_update();
Modified: pve-manager/pve2/lib/PVE/REST.pm
===================================================================
--- pve-manager/pve2/lib/PVE/REST.pm 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/lib/PVE/REST.pm 2011-01-27 13:04:56 UTC (rev 5450)
@@ -37,11 +37,19 @@
sub create_ticket {
my ($user, $pw) = @_;
+ # NOTE: $pw is allowed to be a ticket
+
my $euid = $>;
my $ticket;
eval {
- $user = PVE::AccessControl::authenticate_user($user, $pw);
+ my $tmp;
+ if (($tmp = PVE::AccessControl::verify_ticket($pw, 1)) &&
+ ($tmp eq $user)) {
+ # got valid ticket
+ } else {
+ $user = PVE::AccessControl::authenticate_user($user, $pw);
+ }
$ticket = PVE::AccessControl::assemble_ticket($user);
};
my $err = $@;
@@ -254,8 +262,6 @@
return OK;
}
-my $sslcert;
-
sub rest_handler {
my ($method, $abs_uri, $rel_uri, $ticket, $params) = @_;
@@ -269,24 +275,21 @@
#syslog('info', "ticket auth $user $pw");
- eval {
- $sslcert = PVE::Tools::file_get_contents("/etc/pve/pve-root-ca.pem", 8192)
- if !$sslcert;
- };
- my $err = $@;
-
- if ($err) {
- syslog('err', $err);
+ if (!($ticket = create_ticket($user, $pw))) {
return { status => HTTP_UNAUTHORIZED };
}
-
- if ($ticket = create_ticket($user, $pw)) {
- PVE::Cluster::log_msg('info', "root", "successful auth for user '$user'");
- return { status => HTTP_OK, ticket => $ticket,
- data => { ticket => $ticket, cert => $sslcert }};
+
+ if (defined($params->{path}) || defined($params->{permissions})) {
+ if (!($params->{path} && $params->{permissions} &&
+ PVE::AccessControl::check_permissions($user, $params->{path},
+ $params->{permissions}))) {
+ return { status => HTTP_UNAUTHORIZED };
+ }
}
- return { status => HTTP_UNAUTHORIZED };
+ PVE::Cluster::log_msg('info', "root", "successful auth for user '$user'");
+ return { status => HTTP_OK, ticket => $ticket,
+ data => { ticket => $ticket }};
}
my ($username, $age);
@@ -359,12 +362,23 @@
return wantarray ? ($rel_uri, $format) : $rel_uri;
}
+my $known_methods = {
+ GET => 1,
+ POST => 1,
+ PUT => 1,
+ DELETE => 1,
+};
+
sub handler {
my($r) = @_;
syslog('info', "perl handler called");
my $method = $r->method;
+
+ return HTTP_NOT_IMPLEMENTED
+ if !$known_methods->{$method};
+
my $cgi = CGI->new ($r);
my $params = $cgi->Vars();
Modified: pve-manager/pve2/www/manager/KVMConfig.js
===================================================================
--- pve-manager/pve2/www/manager/KVMConfig.js 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/www/manager/KVMConfig.js 2011-01-27 13:04:56 UTC (rev 5450)
@@ -5,13 +5,14 @@
initComponent : function() {
var self = this;
- var vmid = self.vmid;
+ var vmid = self.confdata.id;
+ var node = self.confdata.node || 'localhost';
if (!vmid)
throw "no vmid specified";
Ext.apply(self, {
- title: "Virtual machine 'KVM " + vmid + "'",
+ title: "Virtual machine 'KVM " + vmid + " on node " + node + "'",
layout: 'fit',
border: false,
items: [
@@ -41,8 +42,8 @@
xtype: 'pveConsole',
title: 'Console',
id: 'console',
- //autoScroll: true,
vmid: vmid,
+ node: node,
border: false
},
{
Modified: pve-manager/pve2/www/manager/PVECache.js
===================================================================
--- pve-manager/pve2/www/manager/PVECache.js 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/www/manager/PVECache.js 2011-01-27 13:04:56 UTC (rev 5450)
@@ -4,8 +4,6 @@
var defaults = {};
- var logindata = {};
-
var pvecache = {
startUpdate: function() {
@@ -14,14 +12,6 @@
});
},
- set_login_data: function(data) {
- logindata = data;
- },
-
- sslcert: function() {
- return logindata.cert;
- },
-
nodestore: function(){
var fields = PVE.Utils.get_field_defaults(['name', 'storage', 'cpu', 'maxcpu',
@@ -31,7 +21,7 @@
itype: 'node',
idProperty: 'name',
autoDestroy: false,
- url: '/api2/json/cluster/nodes',
+ url: '/api2/json/nodes',
fields: fields
});
Modified: pve-manager/pve2/www/manager/PVEConsole.js
===================================================================
--- pve-manager/pve2/www/manager/PVEConsole.js 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/www/manager/PVEConsole.js 2011-01-27 13:04:56 UTC (rev 5450)
@@ -1,7 +1,7 @@
Ext.ns("PVE");
PVE_vnc_console_event = function(appletid, action, err) {
-// console.log("TESTINIT param1 " + appletid + " action " + action);
+ //console.log("TESTINIT param1 " + appletid + " action " + action);
var el = Ext.get(appletid);
if (!el)
@@ -11,6 +11,8 @@
// el.remove();
} else if (action === "error") {
// console.log("TESTERROR: " + err);
+// var compid = appletid.replace("-vncapp", "");
+// var comp = Ext.getCmp(compid);
}
//Ext.get('mytestid').remove();
@@ -22,12 +24,11 @@
var self = this;
var vmid = self.vmid;
+ var node = self.node;
if (!vmid)
throw "no vmid specified";
- var port = 5910;
- var ticket = "TEST";
var myid = self.id + "-vncapp";
//console.log("consoleid " + self.id);
@@ -37,8 +38,9 @@
var applet = Ext.getDom(myid);
//console.log("resize " + myid + " " + applet);
-
- if (!applet) // try again when dom element is available
+
+ // try again when dom element is available
+ if (!(applet && Ext.isFunction(applet.getPreferredSize)))
return resize_window.defer(1000, this);
var tbh = self.tbar.getHeight();
@@ -78,11 +80,71 @@
resize_window.defer(1000, this);
};
- if (self.toplevel) {
- resize_window.defer(2000, window);
- //self.on('afterrender', resize_window, window);
- }
+ var box = new Ext.BoxComponent({
+ border: false,
+ html: ""
+ });
+ var resize_box = function() {
+ var applet = Ext.getDom(myid);
+ // try again when dom element is available
+ if (!(applet && Ext.isFunction(applet.getPreferredSize)))
+ return resize_box.defer(1000, this);
+
+ var ps = applet.getPreferredSize();
+ applet.width = ps.width;
+ applet.height = ps.height;
+
+ resize_box.defer(1000, this);
+ };
+
+ var start_vnc_viewer = function(param) {
+ var cert = param.cert;
+ cert = cert.replace(/\n/g, "|");
+
+ box.update({
+ id: myid,
+ border: false,
+ tag: 'applet',
+ code: 'com.tigervnc.vncviewer.VncViewer',
+ archive: '/vncterm/VncViewer.jar',
+ // NOTE: set size to '100%' - else resize does not work
+ width: "100%",
+ height: "100%",
+ cn: [
+ {tag: 'param', name: 'id', value: myid},
+ {tag: 'param', name: 'PORT', value: param.port},
+ {tag: 'param', name: 'PASSWORD', value: param.ticket},
+ {tag: 'param', name: 'USERNAME', value: param.user},
+ {tag: 'param', name: 'Show Controls', value: 'No'},
+ {tag: 'param', name: 'Offer Relogin', value: 'No'},
+ {tag: 'param', name: 'PVECert', value: cert}
+ ]
+ });
+ if (self.toplevel) {
+ resize_window.defer(1000, window);
+ } else {
+ resize_box.defer(1000, self);
+ }
+ };
+
+ var reload = function() {
+ Ext.Ajax.request({
+ url: "/api2/json/vms/qemu/vncproxy",
+ params: { node: node, vmid: vmid },
+ method: 'POST',
+ failure: function(response, opts) {
+ box.update("Error " + response.status + ": " + response.statusText);
+ },
+ success: function(response, opts) {
+ var obj = Ext.decode(response.responseText);
+ start_vnc_viewer(obj.data);
+ }
+ });
+ };
+
+ box.on("afterrender", reload);
+
var tbar = [
{ text: 'Start'},
{ text: 'Stop'},
@@ -93,49 +155,32 @@
}
},
'->',
+ {
+ text: 'Reload',
+ handler: reload
+ },
{
text: 'New Window',
handler: function() {
- var url = "?console=" + vmid;
- //var port = 5910;
- //var ticket = "TEST";
- //window.location = "vnc://" + location.host + ":" + port + '/' + ticket;
- var nw = window.open(url, '_blank', "innerWidth=745,innerheight=427");
+ var url = Ext.urlEncode({
+ console: vmid,
+ node: node
+ }, "?");
+ var nw = window.open(url, '_blank',
+ "innerWidth=745,innerheight=427");
nw.focus();
}
}
];
- var cert = PVE.Cache.sslcert();
- var certparam = "PVECert_null";
- if (cert) {
- cert = cert.replace(/\n/g, "|");
- certparam = "PVECert";
- }
-
Ext.apply(self, {
layout: 'fit',
+ autoScroll: self.toplevel ? false : true,
tbar: tbar,
- items: {
- border: false,
- bodyCfg: {
- id: myid,
- tag: 'applet',
- code: 'com.tigervnc.vncviewer.VncViewer',
- archive: '/vncterm/VncViewer.jar',
- cn: [
- {tag: 'param', name: 'id', value: myid},
- {tag: 'param', name: 'PORT', value: port},
- {tag: 'param', name: 'PASSWORD', value: ticket},
- {tag: 'param', name: 'Show Controls', value: 'No'},
- {tag: 'param', name: certparam, value: cert}
- ]
- }
- }
+ items: box
});
-
PVE.Console.superclass.initComponent.call(self);
}
Modified: pve-manager/pve2/www/manager/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/manager/PVEUtils.js 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/www/manager/PVEUtils.js 2011-01-27 13:04:56 UTC (rev 5450)
@@ -1,6 +1,9 @@
// avoid errors when running without development tools
if (typeof console == "undefined") {
- var console = { log: function() {} };
+ var console = {
+ dir: function() {},
+ log: function() {}
+ };
}
Ext.ns("PVE");
Modified: pve-manager/pve2/www/manager/ResourceTree.js
===================================================================
--- pve-manager/pve2/www/manager/ResourceTree.js 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/www/manager/ResourceTree.js 2011-01-27 13:04:56 UTC (rev 5450)
@@ -51,7 +51,7 @@
cls: 'x-tree-node-computer',
target: {
xtype: 'pveKVMConfig',
- vmid: info.itemid
+ confdata: info.data
}
});
} else {
Modified: pve-manager/pve2/www/manager/Workspace.js
===================================================================
--- pve-manager/pve2/www/manager/Workspace.js 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/www/manager/Workspace.js 2011-01-27 13:04:56 UTC (rev 5450)
@@ -11,9 +11,10 @@
region:'center'
};
- var buildConsoleView = function(vmid) {
+ var buildConsoleView = function(param) {
return new PVE.Console({
- vmid: vmid,
+ vmid: param.console,
+ node: param.node,
toplevel: true,
layout: 'fit',
border: false
@@ -68,7 +69,7 @@
if (hrefcomp.length == 2) {
var param = Ext.urlDecode(hrefcomp[1]);
if (param.console !== undefined) {
- content = buildConsoleView(param.console);
+ content = buildConsoleView(param);
} else {
content = buildDefaultView();
}
Modified: pve-manager/pve2/www/manager/data/ObjectStore.js
===================================================================
--- pve-manager/pve2/www/manager/data/ObjectStore.js 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/www/manager/data/ObjectStore.js 2011-01-27 13:04:56 UTC (rev 5450)
@@ -7,5 +7,5 @@
PVE.data.ObjectStore.superclass.constructor.call(this, Ext.apply(config, {
reader: new PVE.data.ObjectReader(config)
}));
- },
+ }
});
Modified: pve-manager/pve2/www/manager/form/ModifyDirStorage.js
===================================================================
--- pve-manager/pve2/www/manager/form/ModifyDirStorage.js 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/www/manager/form/ModifyDirStorage.js 2011-01-27 13:04:56 UTC (rev 5450)
@@ -10,7 +10,7 @@
var items_col1 = [
{
xtype: 'hidden',
- name: 'digest',
+ name: 'digest'
},
{
xtype: 'textfield',
Modified: pve-manager/pve2/www/manager/window/LoginWindow.js
===================================================================
--- pve-manager/pve2/www/manager/window/LoginWindow.js 2011-01-27 12:07:05 UTC (rev 5449)
+++ pve-manager/pve2/www/manager/window/LoginWindow.js 2011-01-27 13:04:56 UTC (rev 5450)
@@ -19,7 +19,6 @@
var handler = this.handler || Ext.emptyFn;
handler.call(this.scope || this);
this.destroy();
- PVE.Cache.set_login_data(resp.result.data);
}
});
}
More information about the pve-devel
mailing list