static status (name, done) { Machine.command(['status', name], (err, stdout) => { if (err) done(err) else done(null, stdout.trim().toLowerCase()) }) }
static ssh (name, cmd, done) { if (Array.isArray(cmd)) { cmd = cmd.join(' ') } else if (typeof cmd !== 'string') { throw new TypeError('Command must be an array or string') } cmd = cmd.trim() if (!cmd) throw new TypeError('Command may not be empty') Machine.command(['ssh', name, cmd], done) }
static stop (name, done) { Machine.command(['stop', name], (err) => { if (HOST_NON_EXISTENT.test(err)) { done(new Error(`Docker host "${name}" does not exist`)) } else if (ALREADY_STOPPED.test(err)) { done() } else { done(err) } }) }
static create (name, driver, options, done) { if (typeof name !== 'string' || name === '') { throw new TypeError('name is required') } if (typeof driver !== 'string' || driver === '') { throw new TypeError('driver is required') } if (typeof options === 'function') { done = options options = {} } const args = ['create', '--driver', driver] for (const key in options) { if (hasOwnProperty.call(options, key)) { args.push(`--${key}`, options[key]) } } args.push(name) return Machine.command(args, done) }
Machine.command(args, function (err, stdout) { if (err) return done(err) if (!opts.parse) return done(null, stdout.trim())
static inspect (name, done) { Machine.command(['inspect', name], (err, stdout) => { if (err) return done(err) try { var data = JSON.parse(stdout.trim()) } catch (err) { return done(err) } done(null, merge({}, data)) }) }
Machine.command(args, (err, stdout) => { if (err) return done(err)
static start (name, done) { Machine.command(['start', name], (err) => { if (HOST_NON_EXISTENT.test(err)) { done(new Error(`Docker host "${name}" does not exist`)) } else if (ALREADY_RUNNING.test(err)) { done() } else { done(err) } }) }
static kill (name, done) { Machine.command(['kill', name], (err) => { if (HOST_NON_EXISTENT.test(err)) { done(new Error(`Docker host "${name}" does not exist`)) } else if (ALREADY_STOPPED.test(err)) { done() } else { done(err) } }) }