Moving rollingSnapshot form xapi to xo
This commit is contained in:
parent
a5590b090c
commit
76a44459cf
@ -472,9 +472,7 @@ exports.snapshot = snapshot
|
||||
|
||||
rollingSnapshot = $coroutine ({vm, tag, depth}) ->
|
||||
yield checkPermissionsForSnapshot.call(this, vm)
|
||||
|
||||
snapshot = yield @getXAPI(vm).rollingSnapshotVm(vm.ref, tag, depth)
|
||||
return snapshot.$id
|
||||
yield @rollingSnapshotVm(vm, tag, depth)
|
||||
|
||||
rollingSnapshot.params = {
|
||||
id: { type: 'string' }
|
||||
|
29
src/xapi.js
29
src/xapi.js
@ -1,8 +1,6 @@
|
||||
import createDebug from 'debug'
|
||||
import d3TimeFormat from 'd3-time-format'
|
||||
import escapeStringRegexp from 'escape-string-regexp'
|
||||
import eventToPromise from 'event-to-promise'
|
||||
import filter from 'lodash.filter'
|
||||
import find from 'lodash.find'
|
||||
import got from 'got'
|
||||
import includes from 'lodash.includes'
|
||||
@ -25,8 +23,7 @@ import {
|
||||
mapToArray,
|
||||
noop,
|
||||
parseXml,
|
||||
pFinally,
|
||||
safeDateFormat
|
||||
pFinally
|
||||
} from './utils'
|
||||
import {JsonRpcError} from './api-errors'
|
||||
|
||||
@ -979,35 +976,17 @@ export default class Xapi extends XapiBase {
|
||||
}
|
||||
}
|
||||
|
||||
async snapshotVm (vmId) {
|
||||
async snapshotVm (vmId, nameLabel = undefined) {
|
||||
return await this._getOrWaitObject(
|
||||
await this._snapshotVm(
|
||||
this.getObject(vmId)
|
||||
this.getObject(vmId),
|
||||
nameLabel
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// =================================================================
|
||||
|
||||
async rollingSnapshotVm (vmId, tag, depth) {
|
||||
const vm = this.getObject(vmId)
|
||||
const reg = new RegExp('^rollingSnapshot_[^_]+_' + escapeStringRegexp(tag))
|
||||
const snapshots = sortBy(filter(vm.$snapshots, snapshot => reg.test(snapshot.name_label)), 'name_label')
|
||||
|
||||
const date = safeDateFormat(new Date())
|
||||
|
||||
const ref = await this._snapshotVm(vm, `rollingSnapshot_${date}_${tag}_${vm.name_label}`)
|
||||
|
||||
const promises = []
|
||||
for (let surplus = snapshots.length - (depth - 1); surplus > 0; surplus--) {
|
||||
const oldSnap = snapshots.shift()
|
||||
promises.push(this.deleteVm(oldSnap.uuid, true))
|
||||
}
|
||||
await Promise.all(promises)
|
||||
|
||||
return await this._getOrWaitObject(ref)
|
||||
}
|
||||
|
||||
async _createVbd (vm, vdi, {
|
||||
bootable = false,
|
||||
position = undefined,
|
||||
|
18
src/xo.js
18
src/xo.js
@ -794,6 +794,24 @@ export default class Xo extends EventEmitter {
|
||||
return backupFullPath
|
||||
}
|
||||
|
||||
async rollingSnapshotVm (vm, tag, depth) {
|
||||
const xapi = this.getXAPI(vm)
|
||||
vm = xapi.getObject(vm.id)
|
||||
|
||||
const reg = new RegExp('^rollingSnapshot_[^_]+_' + escapeStringRegexp(tag))
|
||||
const snapshots = sortBy(filter(vm.$snapshots, snapshot => reg.test(snapshot.name_label)), 'name_label')
|
||||
const date = safeDateFormat(new Date())
|
||||
|
||||
await xapi.snapshotVm(vm, `rollingSnapshot_${date}_${tag}_${vm.name_label}`)
|
||||
|
||||
const promises = []
|
||||
for (let surplus = snapshots.length - (depth - 1); surplus > 0; surplus--) {
|
||||
const oldSnap = snapshots.shift()
|
||||
promises.push(xapi.deleteVm(oldSnap.uuid, true))
|
||||
}
|
||||
await Promise.all(promises)
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
async createAuthenticationToken ({userId}) {
|
||||
|
Loading…
Reference in New Issue
Block a user