feat(vm.snapshot): copy ACLs from VM to snapshot (#495)
See vatesfr/xo-web#1865 Also, correctly remove ACLs on VM deletion.
This commit is contained in:
committed by
Julien Fontanet
parent
f65b9f695e
commit
dfee98b66b
@@ -1,6 +1,5 @@
|
||||
$assign = require 'lodash/assign'
|
||||
$debug = (require 'debug') 'xo:api:vm'
|
||||
$filter = require 'lodash/filter'
|
||||
$findIndex = require 'lodash/findIndex'
|
||||
$findWhere = require 'lodash/find'
|
||||
concat = require 'lodash/concat'
|
||||
@@ -23,6 +22,7 @@ startsWith = require 'lodash/startsWith'
|
||||
formatXml: $js2xml,
|
||||
isArray: $isArray,
|
||||
map,
|
||||
mapFilter,
|
||||
mapToArray,
|
||||
noop,
|
||||
parseSize,
|
||||
@@ -301,6 +301,16 @@ delete_ = $coroutine ({vm, delete_disks: deleteDisks}) ->
|
||||
|
||||
xapi = @getXapi(vm)
|
||||
|
||||
@getAllAcls().then((acls) =>
|
||||
Promise.all(mapFilter(acls, (acl) =>
|
||||
if (acl.object == vm.id)
|
||||
return pCatch.call(
|
||||
@removeAcl(acl.subject, acl.object, acl.action),
|
||||
noop
|
||||
)
|
||||
))
|
||||
)
|
||||
|
||||
# Update IP pools
|
||||
yield Promise.all(map(vm.VIFs, (vifId) =>
|
||||
vif = xapi.getObject(vifId)
|
||||
@@ -642,6 +652,18 @@ snapshot = $coroutine ({vm, name}) ->
|
||||
yield checkPermissionOnSrs.call(this, vm)
|
||||
|
||||
snapshot = yield @getXapi(vm).snapshotVm(vm._xapiRef, name ? "#{vm.name_label}_#{new Date().toISOString()}")
|
||||
|
||||
# Copy VM's ACLs to the snapshot
|
||||
@getAllAcls().then((acls) =>
|
||||
Promise.all(mapFilter(acls, (acl) =>
|
||||
if (acl.object == vm.id)
|
||||
return pCatch.call(
|
||||
@addAcl(acl.subject, snapshot.$id, acl.action),
|
||||
noop
|
||||
)
|
||||
))
|
||||
)
|
||||
|
||||
return snapshot.$id
|
||||
|
||||
snapshot.params = {
|
||||
|
||||
Reference in New Issue
Block a user