Initial Commit
This commit is contained in:
41
app/services/hosts.service.js
Normal file
41
app/services/hosts.service.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const { Service } = require('flitter-di')
|
||||
const LocalHost = require('../classes/metal/LocalHost')
|
||||
const RemoteHost = require('../classes/metal/RemoteHost')
|
||||
|
||||
class hosts extends Service {
|
||||
static get services() {
|
||||
return [...super.services, 'configs']
|
||||
}
|
||||
|
||||
_running_hosts = []
|
||||
|
||||
get config() {
|
||||
return this.configs.get('hosts')
|
||||
}
|
||||
|
||||
get(name) {
|
||||
const config = this.config[name]
|
||||
config.name = name
|
||||
if ( !config ) {
|
||||
throw new Error(`Could not get host ${name}: No such host configured.`)
|
||||
}
|
||||
|
||||
if ( config.type === 'localhost' ) {
|
||||
const host = new LocalHost(config)
|
||||
this._running_hosts.push(host)
|
||||
return host
|
||||
} else if ( config.type === 'ssh' ) {
|
||||
const host = new RemoteHost(config)
|
||||
this._running_hosts.push(host)
|
||||
return host
|
||||
} else {
|
||||
throw new Error(`Unknown host type ${config.type} for host ${name}.`)
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
this._running_hosts.forEach(h => h._cleanup())
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = hosts
|
||||
Reference in New Issue
Block a user