[pve-devel] [PATCH v2] implement hookscripts for guests

Dominik Csapak d.csapak at proxmox.com
Thu Jan 24 12:30:50 CET 2019


this series implements a first version of hookscripts for guests

for this we do the following:

* add a new content type for storages (scripts) to have a place
  for the scripts we can reference
* add it do directory storages
* execute hook scripts on
  - pre start (cancel start if hookscript does not exit cleanly)
  - post start
  - pre stop (may not be called if vm gets stopped from within)
  - post stop

  with parameters 'id' and 'phase'
* show the content type on the gui
* show the hookscript (if set) on the gui

for now only root can set those scripts (via api or qm/pct), but
putting them into a storage leaves us open the possibility for
a privilege that the user can have

i am not really sure about the 'scripts' name for the content
type, as we may want to use it also for e.g. custom cloud-init
configs or something similar, does anyone have a better idea?

dependcy wise it is relatively straight forward:

manager depends on
qemu-server/container/storage

qemu-server/container depends on
guest-common/storage

after (a version of) this series gets applied, i will write
some documentation about it (with an example script) and mark
it 'experimental' and note that the calling convention and
the exact phases/points in time are not fixed yet and subject to change,
since we may want to change it in the future until we know
exactly what our users need

changes from v1:
* implemented suggestions by thomas regarding spacing, etc.
* fail exec_hookscript when stop_on_error is set and
  the script is not exectuable or does not exist
* fail setting hookscript when it does not exist
* check correctly for root at pam for containers

pve-storage:

Dominik Csapak (3):
  add new content type 'scripts'
  enable scripts content type for all directory based storages
  allow scripts by default for new dir storages

 PVE/API2/Disks/Directory.pm |  2 +-
 PVE/Storage.pm              | 48 +++++++++++++++++++++++++++++++++++++++++++--
 PVE/Storage/CIFSPlugin.pm   |  2 +-
 PVE/Storage/CephFSPlugin.pm |  2 +-
 PVE/Storage/DirPlugin.pm    |  2 +-
 PVE/Storage/NFSPlugin.pm    |  2 +-
 PVE/Storage/Plugin.pm       |  5 ++++-
 7 files changed, 55 insertions(+), 8 deletions(-)

pve-guest-common:

Dominik Csapak (1):
  add exec_hookscript to GuestHelpers

 PVE/GuestHelpers.pm | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

qemu-server:

Dominik Csapak (1):
  add hookscripts to vms

 PVE/API2/Qemu.pm  |  8 ++++++++
 PVE/CLI/qm.pm     |  2 ++
 PVE/QemuServer.pm | 12 ++++++++++++
 3 files changed, 22 insertions(+)

pve-container:

Dominik Csapak (1):
  add hookscript to containers

 src/PVE/LXC.pm            |  9 +++++++++
 src/PVE/LXC/Config.pm     | 19 ++++++++++++++++++-
 src/lxc-pve-poststop-hook |  3 +++
 3 files changed, 30 insertions(+), 1 deletion(-)

pve-manager:

Dominik Csapak (2):
  add scripts content type to the gui
  show hookscript in gui

 www/manager6/Utils.js                    | 3 ++-
 www/manager6/form/ContentTypeSelector.js | 2 +-
 www/manager6/lxc/Options.js              | 3 +++
 www/manager6/qemu/Options.js             | 3 +++
 www/manager6/storage/CephFSEdit.js       | 2 +-
 www/manager6/storage/GlusterFsEdit.js    | 2 +-
 6 files changed, 11 insertions(+), 4 deletions(-)

-- 
2.11.0





More information about the pve-devel mailing list