From 87d075bbbb40f97df2142b8e6ba48cd226db2462 Mon Sep 17 00:00:00 2001 From: Josh Wilsdon Date: Fri, 9 Feb 2018 17:52:57 -0800 Subject: [PATCH] initial support for bhyve --- lib/do_fwrule/do_instances.js | 4 ++- lib/do_instance/do_create.js | 41 +++++++++++++++++++++--- lib/do_instance/do_list.js | 4 ++- lib/do_instance/do_snapshot/do_create.js | 2 +- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/lib/do_fwrule/do_instances.js b/lib/do_fwrule/do_instances.js index 53bc6bf..b549f16 100644 --- a/lib/do_fwrule/do_instances.js +++ b/lib/do_fwrule/do_instances.js @@ -5,7 +5,7 @@ */ /* - * Copyright 2016 Joyent, Inc. + * Copyright 2018 Joyent, Inc. * * `triton fwrule instances ...` */ @@ -111,6 +111,7 @@ function do_instances(subcmd, opts, args, cb) { common.uuidToShortId(inst.image); inst.shortid = inst.id.split('-', 1)[0]; var flags = []; + if (inst.brand === 'bhyve') flags.push('B'); if (inst.docker) flags.push('D'); if (inst.firewall_enabled) flags.push('F'); if (inst.brand === 'kvm') flags.push('K'); @@ -159,6 +160,7 @@ do_instances.help = [ 'for convenience):', ' shortid* A short ID prefix.', ' flags* Single letter flags summarizing some fields:', + ' "B" the brand is "bhyve"', ' "D" docker instance', ' "F" firewall is enabled', ' "K" the brand is "kvm"', diff --git a/lib/do_instance/do_create.js b/lib/do_instance/do_create.js index 47b7e18..1f86900 100644 --- a/lib/do_instance/do_create.js +++ b/lib/do_instance/do_create.js @@ -5,7 +5,7 @@ */ /* - * Copyright 2017 Joyent, Inc. + * Copyright 2018 Joyent, Inc. * * `triton instance create ...` */ @@ -376,6 +376,24 @@ function do_create(subcmd, opts, args, cb) { function (net) { return net.id; }) }; + ctx.expectState = 'running'; + if (opts.autoboot) { + if (['true', 'false'].indexOf(opts.autoboot) === -1) { + cb(new errors.UsageError('invalid argument to --autoboot ' + + 'argument must be "true" or "false"')); + return; + } + createOpts.autoboot = (opts.autoboot === 'true' ? true : false); + + if (!createOpts.autoboot) { + // If we're not going to boot, wait for 'stopped' instead. + ctx.expectState = 'stopped'; + } + } + + if (opts.brand) { + createOpts.brand = opts.brand; + } if (ctx.volMounts) { createOpts.volumes = ctx.volMounts; } @@ -447,7 +465,7 @@ function do_create(subcmd, opts, args, cb) { var waiter = (opts.dry_run ? function dryWait(waitOpts, waitCb) { setTimeout(function () { - ctx.inst.state = 'running'; + ctx.inst.state = ctx.expectState; waitCb(null, ctx.inst); }, 5000); } : tritonapi.cloudapi.waitForMachineStates.bind( @@ -455,7 +473,7 @@ function do_create(subcmd, opts, args, cb) { waiter({ id: ctx.inst.id, - states: ['running', 'failed'] + states: [ctx.expectState, 'failed'] }, function (err, inst) { if (distraction) { distraction.destroy(); @@ -465,12 +483,12 @@ function do_create(subcmd, opts, args, cb) { } if (opts.json) { console.log(JSON.stringify(inst)); - } else if (inst.state === 'running') { + } else if (inst.state === ctx.expectState) { var dur = Date.now() - ctx.start; console.log('Created instance %s (%s) in %s', inst.name, inst.id, common.humanDurationFromMs(dur)); } - if (inst.state !== 'running') { + if (inst.state !== ctx.expectState) { next(new Error(format('failed to create instance %s (%s)', inst.name, inst.id))); } else { @@ -492,6 +510,19 @@ do_create.options = [ { group: 'Create options' }, + { + names: ['autoboot'], + helpArg: 'true|false', + type: 'string', + help: 'Whether or not to boot this instance when creating it ' + + '(default: true).' + }, + { + names: ['brand'], + helpArg: 'BRAND', + type: 'string', + help: 'Override the default brand for this instance.' + }, { names: ['name', 'n'], helpArg: 'NAME', diff --git a/lib/do_instance/do_list.js b/lib/do_instance/do_list.js index 2619a3a..23e7c22 100644 --- a/lib/do_instance/do_list.js +++ b/lib/do_instance/do_list.js @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2017, Joyent, Inc. + * Copyright (c) 2018, Joyent, Inc. * * `triton instance list ...` */ @@ -152,6 +152,7 @@ function do_list(subcmd, opts, args, callback) { var flags = []; if (inst.docker) flags.push('D'); if (inst.firewall_enabled) flags.push('F'); + if (inst.brand === 'bhyve') flags.push('B'); if (inst.brand === 'kvm') flags.push('K'); inst.flags = flags.length ? flags.join('') : undefined; }); @@ -208,6 +209,7 @@ do_list.help = [ 'for convenience):', ' shortid* A short ID prefix.', ' flags* Single letter flags summarizing some fields:', + ' "B" the brand is "bhyve"', ' "D" docker instance', ' "F" firewall is enabled', ' "K" the brand is "kvm"', diff --git a/lib/do_instance/do_snapshot/do_create.js b/lib/do_instance/do_snapshot/do_create.js index de7b5cf..3a377e8 100644 --- a/lib/do_instance/do_snapshot/do_create.js +++ b/lib/do_instance/do_snapshot/do_create.js @@ -133,7 +133,7 @@ do_create.help = [ '{{usage}}', '', '{{options}}', - 'Snapshot do not work for instances of type "kvm".' + 'Snapshots do not work for instances of type "bhyve" or "kvm".' ].join('\n'); do_create.completionArgtypes = ['tritoninstance', 'none'];