From 3a76893d03b6efdc1ebe33ecdc41e75e670e2efd Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 19 Jun 2013 11:57:38 +0200 Subject: [PATCH] use interactive vnc shell to run system upgrade System upgrade almost always requires user input. --- PVE/API2/APT.pm | 51 -------------------------------------- PVE/API2/Nodes.pm | 20 ++++++++++++++- www/manager/Utils.js | 1 - www/manager/VNCConsole.js | 27 +++++++++++++++----- www/manager/Workspace.js | 10 +++++++- www/manager/node/APT.js | 20 +++++++++------ www/manager/node/Config.js | 11 +++++--- 7 files changed, 69 insertions(+), 71 deletions(-) diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm index ea970e50a..c23695a86 100644 --- a/PVE/API2/APT.pm +++ b/PVE/API2/APT.pm @@ -60,7 +60,6 @@ __PACKAGE__->register_method({ my $res = [ { id => 'update' }, - { id => 'upgrade' }, { id => 'changelog' }, ]; @@ -254,56 +253,6 @@ __PACKAGE__->register_method({ }}); -__PACKAGE__->register_method({ - name => 'upgrade', - path => 'upgrade', - method => 'POST', - description => "Install the newest versions of all packages (apt-get dist-upgrade).", - permissions => { - check => ['perm', '/nodes/{node}', [ 'Sys.Modify' ]], - }, - protected => 1, - proxyto => 'node', - parameters => { - additionalProperties => 0, - properties => { - node => get_standard_option('pve-node'), - }, - }, - returns => { - type => 'string', - }, - code => sub { - my ($param) = @_; - - my $rpcenv = PVE::RPCEnvironment::get(); - - my $authuser = $rpcenv->get_user(); - - my $realcmd = sub { - my $upid = shift; - - my $cmd = ['apt-get', 'dist-upgrade', '--assume-yes']; - - push @$cmd, '-o', 'Dpkg::Options::=--force-confdef'; - - push @$cmd, '-o', 'Dpkg::Options::=--force-confold'; - - print "starting apt-get dist-upgrade\n"; - - $ENV{DEBIAN_FRONTEND} = 'noninteractive'; - - PVE::Tools::run_command($cmd); - - &$update_pve_pkgstatus(); - - return; - }; - - return $rpcenv->fork_worker('aptupgrade', undef, $authuser, $realcmd); - - }}); - __PACKAGE__->register_method({ name => 'changelog', path => 'changelog', diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm index 04b08018c..da6026b46 100644 --- a/PVE/API2/Nodes.pm +++ b/PVE/API2/Nodes.pm @@ -576,6 +576,12 @@ __PACKAGE__->register_method ({ additionalProperties => 0, properties => { node => get_standard_option('pve-node'), + upgrade => { + type => 'boolean', + description => "Run 'apt-get dist-upgrade' instead of normal shell.", + optional => 1, + default => 0, + }, }, }, returns => { @@ -597,6 +603,8 @@ __PACKAGE__->register_method ({ raise_perm_exc("realm != pam") if $realm ne 'pam'; + raise_perm_exc('user != root@pam') if $param->{upgrade} && $user ne 'root@pam'; + my $node = $param->{node}; my $authpath = "/nodes/$node"; @@ -619,7 +627,17 @@ __PACKAGE__->register_method ({ my $remcmd = $remip ? ['/usr/bin/ssh', '-t', $remip] : []; - my $shcmd = $user eq 'root@pam' ? [ "/bin/bash", "-l" ] : [ "/bin/login" ]; + my $shcmd; + + if ($user eq 'root@pam') { + if ($param->{upgrade}) { + $shcmd = [ '/bin/bash', '-l', '-c', 'apt-get dist-upgrade; /bin/bash' ]; + } else { + $shcmd = [ '/bin/bash', '-l' ]; + } + } else { + $shcmd = [ '/bin/login' ]; + } my $timeout = 10; diff --git a/www/manager/Utils.js b/www/manager/Utils.js index 509b62947..cd527a0cf 100644 --- a/www/manager/Utils.js +++ b/www/manager/Utils.js @@ -503,7 +503,6 @@ Ext.define('PVE.Utils', { statics: { download: ['', gettext('Download') ], vzdump: ['', gettext('Backup') ], aptupdate: ['', gettext('Update package database') ], - aptupgrade: ['', gettext('System upgrade') ], startall: [ '', gettext('Start all VMs and Containers') ], stopall: [ '', gettext('Stop all VMs and Containers') ] }, diff --git a/www/manager/VNCConsole.js b/www/manager/VNCConsole.js index b610b6c81..8ffded8af 100644 --- a/www/manager/VNCConsole.js +++ b/www/manager/VNCConsole.js @@ -417,6 +417,8 @@ Ext.define('PVE.Shell', { extend: 'PVE.VNCConsole', alias: ['widget.pveShell'], + ugradeSystem: false, // set to true to run "apt-get dist-upgrade" + initComponent : function() { var me = this; @@ -432,24 +434,37 @@ Ext.define('PVE.Shell', { var applet = Ext.getDom(me.appletID); applet.sendRefreshRequest(); } - }, - { - text: gettext('Reload'), - handler: function () { me.reloadApplet(); } - }, + } + ]; + + if (!me.ugradeSystem) { + // we dont want to restart the upgrade script + tbar.push([ + { + text: gettext('Reload'), + handler: function () { me.reloadApplet(); } + }]); + } + + tbar.push([ { text: gettext('Shell'), handler: function() { PVE.Utils.openConoleWindow('shell', undefined, me.nodename); } } - ]; + ]); + Ext.apply(me, { tbar: tbar, url: "/nodes/" + me.nodename + "/vncshell" }); + if (me.ugradeSystem) { + me.params = { upgrade: 1 }; + } + me.callParent(); } }); diff --git a/www/manager/Workspace.js b/www/manager/Workspace.js index a561d1497..0b95b8384 100644 --- a/www/manager/Workspace.js +++ b/www/manager/Workspace.js @@ -141,12 +141,20 @@ Ext.define('PVE.ConsoleWorkspace', { toplevel: true }; } else if (consoleType === 'shell') { - me.title = "node '" + param.node; + me.title = "node '" + param.node + "'"; content = { xtype: 'pveShell', nodename: param.node, toplevel: true }; + } else if (consoleType === 'upgrade') { + me.title = Ext.String.format(gettext('System upgrade on node {0}'), "'" + param.node + "'"); + content = { + xtype: 'pveShell', + nodename: param.node, + ugradeSystem: true, + toplevel: true + }; } else { content = { border: false, diff --git a/www/manager/node/APT.js b/www/manager/node/APT.js index 144f26d23..172519dd7 100644 --- a/www/manager/node/APT.js +++ b/www/manager/node/APT.js @@ -80,14 +80,20 @@ Ext.define('PVE.node.APT', { var upgrade_btn = new PVE.button.Button({ text: gettext('Upgrade'), - dangerous: true, - confirmMsg: function(rec) { - return gettext('Are you sure you want to upgrade this node?'); - }, - handler: function(){ - PVE.Utils.checked_command(function() { apt_command('upgrade'); }); + disabled: !(PVE.UserName && PVE.UserName === 'root@pam'), + handler: function() { + PVE.Utils.checked_command(function() { + var url = Ext.urlEncode({ + console: 'upgrade', + node: nodename + }); + var nw = window.open("?" + url, '_blank', + "innerWidth=745,innerheight=427"); + nw.focus(); + }); } - }); + }); + var show_changelog = function(rec) { if (!rec || !rec.data || !(rec.data.ChangeLogUrl && rec.data.Package)) { diff --git a/www/manager/node/Config.js b/www/manager/node/Config.js index 4245cad06..8051f9b37 100644 --- a/www/manager/node/Config.js +++ b/www/manager/node/Config.js @@ -144,14 +144,17 @@ Ext.define('PVE.node.Config', { itemId: 'support', xtype: 'pveNodeSubscription', nodename: nodename - }, - { + } + ]); + + if (caps.nodes['Sys.Console']) { + me.items.push([{ title: gettext('Updates'), itemId: 'apt', xtype: 'pveNodeAPT', nodename: nodename - } - ]); + }]); + } me.callParent();