Coding style fixes

This commit is contained in:
wescoeur 2015-11-25 17:13:29 +01:00
parent 8cfc6f0b1d
commit 561b8f4eed

View File

@ -3,6 +3,7 @@ import moment from 'moment'
export const configurationSchema = {
type: 'object',
description: 'a array of emails (receivers)',
properties: {
to: {
type: 'array',
@ -65,26 +66,24 @@ class BackupReportsXoPlugin {
nCalls++
let vmName
let vm
try {
const vm = this._xo.getObject(call.params.id)
vmName = vm.name_label
} catch (e) {
vmName = 'Vm name not found'
}
vm = this._xo.getObject(call.params.id)
} catch (e) {}
const start = moment(call.start)
const end = moment(call.end)
const duration = moment.duration(end - start).humanize()
text.push([`### VM : ${vmName}`,
`UUID: ${call.params.id}`,
`Status: ${vmStatus}`,
`Start time: ${start.toString()}`,
`End time: ${end.toString()}`,
`Duration: ${duration}`
].join('\n - '))
text.push([
`### VM : ${vm ? vm.name_label : 'undefined'}`,
` - UUID: ${vm ? vm.uuid : 'undefined'}`,
` - Status: ${vmStatus}`,
` - Start time: ${String(start)}`,
` - End time: ${String(end)}`,
` - Duration: ${duration}`
].join('\n'))
})
// No backup calls.
@ -92,29 +91,27 @@ class BackupReportsXoPlugin {
return
}
const globalStatus = nSuccess === nCalls
? 'Success'
: 'Fail'
const globalStatus = nSuccess === nCalls ? 'Success' : 'Fail'
const start = moment(status.start)
const end = moment(status.end)
const duration = moment.duration(end - start).humanize()
// Global status.
text.unshift([`## Global status: ${globalStatus}`,
`Start time: ${start.toString()}`,
`End time: ${end.toString()}`,
`Duration: ${duration}`,
`Successful backed up VM number: ${nSuccess}`,
`Failed backed up VM: ${nCalls - nSuccess}`
].join('\n - '))
text.unshift([
`## Global status: ${globalStatus}`,
` - Start time: ${String(start)}`,
` - End time: ${String(end)}`,
` - Duration: ${duration}`,
` - Successful backed up VM number: ${nSuccess}`,
` - Failed backed up VM: ${nCalls - nSuccess}`
].join('\n'))
// TODO : Handle errors when `sendEmail` isn't present. (Plugin dependencies)
this._xo.sendEmail({
await this._xo.sendEmail({
to: this._receivers,
subject: 'Backup Reports (XenOrchestra)',
markdown: text.join('\n')
}).catch(e => console.error('Unable to send email: ', e))
})
}
}