Initial Commit

This commit is contained in:
garrettmills
2020-02-21 00:36:55 -06:00
commit e2016069f2
40 changed files with 4902 additions and 0 deletions

View 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