You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
maestro/app/services/hosts.service.js

43 lines
1.1 KiB

4 years ago
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', 'app']
4 years ago
}
_running_hosts = []
get config() {
return this.configs.get('hosts')
}
get(name) {
const config = this.config[name]
if ( !config ) {
throw new Error(`Could not get host ${name}: No such host configured.`)
}
config.name = name
4 years ago
if ( config.type === 'localhost' ) {
const host = this.app.di().make(LocalHost, config)
4 years ago
this._running_hosts.push(host)
return host
} else if ( config.type === 'ssh' ) {
const host = this.app.di().make(RemoteHost, config)
4 years ago
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