Add support for routines; state messages
This commit is contained in:
@@ -23,6 +23,13 @@ class CommandState extends State {
|
||||
}
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Failed to execute the command "${this._config.cmd}" on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `The command check was not successful.`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = CommandState
|
||||
|
||||
25
app/classes/state/os/IsAliveState.js
Normal file
25
app/classes/state/os/IsAliveState.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const State = require('../State')
|
||||
|
||||
class IsAliveState extends State {
|
||||
async apply() {
|
||||
throw new Error('IsAliveState cannot be applied. It is a check measure only.')
|
||||
}
|
||||
|
||||
async check() {
|
||||
return this._host.is_alive()
|
||||
}
|
||||
|
||||
async reverse() {
|
||||
throw new Error('IsAliveState cannot be reversed. It is a check measure only.')
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Unable to connect to host "${this._host.name}".`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = IsAliveState
|
||||
@@ -19,6 +19,14 @@ class PackageAbsentState extends State {
|
||||
async apply() {
|
||||
return this._host.packages.uninstall(this._config.package)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The package "${this._config.package}" still exists on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackageAbsentState
|
||||
|
||||
@@ -23,6 +23,14 @@ class PackageCacheClearedState extends State {
|
||||
async reverse() {
|
||||
this.output.warn(`Package cache cleared state does not currently support reversal. (Host: ${this._host.name})`)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Failed to clear package cache on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `The package cache on host "${this._host.name}" has not been cleared.`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackageCacheClearedState
|
||||
|
||||
@@ -19,6 +19,14 @@ class PackageState extends State {
|
||||
async reverse() {
|
||||
return this._host.packages.uninstall(this._config.package)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `The package "${this._config.package}" is not installed on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = PackageState
|
||||
|
||||
@@ -23,6 +23,14 @@ class ServiceDaemonReloadState extends State {
|
||||
async reverse() {
|
||||
this.output.warn(`Service daemon reload state does not currently support reversal. (Host: ${this._host.name})`)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Unable to reload service daemon on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `The service daemon on host "${this._host.name}" has not been reloaded.`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceDaemonReloadState
|
||||
|
||||
@@ -24,6 +24,14 @@ class ServiceRestartState extends State {
|
||||
async reverse() {
|
||||
this.output.warn(`Service restart state does not currently support reversal. (Host: ${this._host.name})`)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Unable to restart service "${this._config.service}" on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `The service "${this._config.service}" on host "${this._host.name}" has not been restarted.`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceRestartState
|
||||
|
||||
@@ -24,6 +24,15 @@ class ServiceState extends State {
|
||||
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
|
||||
return this._host.services.stop(...services)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
|
||||
return `The service(s) ${services.join(', ')} do not all exist on the host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return this.failure_message()
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceState
|
||||
|
||||
@@ -24,6 +24,14 @@ class ServiceStoppedState extends State {
|
||||
const services = Array.isArray(this._config.service) ? this._config.service : [this._config.service]
|
||||
return this._host.services.stop(...services)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Unable to stop service "${this._config.service}" on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `The service "${this._config.service}" on host "${this._host.name}" has not been stopped.`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = ServiceStoppedState
|
||||
|
||||
@@ -24,6 +24,14 @@ class UpdateState extends State {
|
||||
async reverse() {
|
||||
this.output.warn(`Update state does not currently support reversing package updates. (Host: ${this._host.name})`)
|
||||
}
|
||||
|
||||
failure_message() {
|
||||
return `Unable to update packages on host "${this._host.name}."`
|
||||
}
|
||||
|
||||
check_message() {
|
||||
return `There are package updates pending on the host "${this._host.name}."`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = UpdateState
|
||||
|
||||
Reference in New Issue
Block a user