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

Dominik Csapak d.csapak at proxmox.com
Tue Jan 29 16:28:37 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 (snippets) 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

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 v2:
* rename scripts type to snippets
* move the path check to GuestHelpers
* remove the executable check from storage and add it in the api
  this will come in useful when we allow custom cloud init configs,
  as those do not have to be executable

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 'snippets'
  enable snippets content type for all directory based storages
  allow snippets 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 (2):
  add exec_hookscript to GuestHelpers
  add check_hookscript_volume_id to GuestHelpers

 PVE/GuestHelpers.pm | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 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     | 13 ++++++++++++-
 src/lxc-pve-poststop-hook |  3 +++
 3 files changed, 24 insertions(+), 1 deletion(-)

pve-manager:

Dominik Csapak (2):
  add snippets 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