Guest User

Proxmox 2 / API / exec2

a guest
Apr 4th, 2012
200
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. +++ OpenVZ.pm   2012-04-04 16:08:38.000000000 +0200
  2. @@ -530,6 +530,7 @@
  3.         { subdir => 'initlog' },
  4.         { subdir => 'rrd' },
  5.         { subdir => 'rrddata' },
  6. +       { subdir => 'exec2' },
  7.         ];
  8.    
  9.     return $res;
  10. @@ -1413,4 +1414,58 @@
  11.     }
  12.      }});
  13.  
  14. +__PACKAGE__->register_method({
  15. +    name => 'vm_exec2',
  16. +    path => '{vmid}/exec2',
  17. +    method => 'POST',
  18. +    protected => 1,
  19. +    proxyto => 'node',
  20. +    description => "Execute command in container.",
  21. +    permissions => {
  22. +   check => ['perm', '/vms/{vmid}', [ 'VM.PowerMgmt' ]],
  23. +    },
  24. +    parameters => {
  25. +       additionalProperties => 1,
  26. +   properties => {
  27. +       node => get_standard_option('pve-node'),
  28. +       vmid => get_standard_option('pve-vmid'),
  29. +       execcmd => {
  30. +       type => 'string',
  31. +       description => "Command to execute insite CT",
  32. +       },
  33. +   },
  34. +    },
  35. +    returns => {
  36. +   type => 'string',
  37. +    },
  38. +    code => sub {
  39. +   my ($param) = @_;
  40. +
  41. +   my $rpcenv = PVE::RPCEnvironment::get();
  42. +
  43. +   my $authuser = $rpcenv->get_user();
  44. +
  45. +   my $node = extract_param($param, 'node');
  46. +
  47. +   my $vmid = extract_param($param, 'vmid');
  48. +
  49. +   my $execcmd = extract_param($param, 'execcmd');
  50. +
  51. +   die "CT $vmid not running\n" if !PVE::OpenVZ::check_running($vmid);
  52. +
  53. +   my $realcmd = sub {
  54. +       my $upid = shift;
  55. +
  56. +       syslog('info', "Exec CT $vmid: $upid\n");
  57. +
  58. +       my $cmd = ['vzctl', 'exec2', $vmid, $execcmd ];
  59. +       run_command($cmd);
  60. +      
  61. +       return;
  62. +   };
  63. +
  64. +       return $rpcenv->fork_worker('vzexec2', $vmid, $authuser, $realcmd);
  65. +    }});
  66. +
  67. +
  68.  1;
RAW Paste Data