initial support for bhyve

This commit is contained in:
Josh Wilsdon 2018-02-09 17:52:57 -08:00
parent e7c02436df
commit 87d075bbbb
4 changed files with 43 additions and 8 deletions

View File

@ -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"',

View File

@ -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',

View File

@ -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"',

View File

@ -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'];