Compare commits

...
This repository has been archived on 2020-01-20. You can view files and clone it, but cannot push or open issues or pull requests.

1 Commits

Author SHA1 Message Date
Josh Wilsdon
87d075bbbb initial support for bhyve 2018-02-09 17:52:57 -08:00
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 ...` * `triton fwrule instances ...`
*/ */
@ -111,6 +111,7 @@ function do_instances(subcmd, opts, args, cb) {
common.uuidToShortId(inst.image); common.uuidToShortId(inst.image);
inst.shortid = inst.id.split('-', 1)[0]; inst.shortid = inst.id.split('-', 1)[0];
var flags = []; var flags = [];
if (inst.brand === 'bhyve') flags.push('B');
if (inst.docker) flags.push('D'); if (inst.docker) flags.push('D');
if (inst.firewall_enabled) flags.push('F'); if (inst.firewall_enabled) flags.push('F');
if (inst.brand === 'kvm') flags.push('K'); if (inst.brand === 'kvm') flags.push('K');
@ -159,6 +160,7 @@ do_instances.help = [
'for convenience):', 'for convenience):',
' shortid* A short ID prefix.', ' shortid* A short ID prefix.',
' flags* Single letter flags summarizing some fields:', ' flags* Single letter flags summarizing some fields:',
' "B" the brand is "bhyve"',
' "D" docker instance', ' "D" docker instance',
' "F" firewall is enabled', ' "F" firewall is enabled',
' "K" the brand is "kvm"', ' "K" the brand is "kvm"',

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright 2017 Joyent, Inc. * Copyright 2018 Joyent, Inc.
* *
* `triton instance create ...` * `triton instance create ...`
*/ */
@ -376,6 +376,24 @@ function do_create(subcmd, opts, args, cb) {
function (net) { return net.id; }) 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) { if (ctx.volMounts) {
createOpts.volumes = ctx.volMounts; createOpts.volumes = ctx.volMounts;
} }
@ -447,7 +465,7 @@ function do_create(subcmd, opts, args, cb) {
var waiter = (opts.dry_run ? var waiter = (opts.dry_run ?
function dryWait(waitOpts, waitCb) { function dryWait(waitOpts, waitCb) {
setTimeout(function () { setTimeout(function () {
ctx.inst.state = 'running'; ctx.inst.state = ctx.expectState;
waitCb(null, ctx.inst); waitCb(null, ctx.inst);
}, 5000); }, 5000);
} : tritonapi.cloudapi.waitForMachineStates.bind( } : tritonapi.cloudapi.waitForMachineStates.bind(
@ -455,7 +473,7 @@ function do_create(subcmd, opts, args, cb) {
waiter({ waiter({
id: ctx.inst.id, id: ctx.inst.id,
states: ['running', 'failed'] states: [ctx.expectState, 'failed']
}, function (err, inst) { }, function (err, inst) {
if (distraction) { if (distraction) {
distraction.destroy(); distraction.destroy();
@ -465,12 +483,12 @@ function do_create(subcmd, opts, args, cb) {
} }
if (opts.json) { if (opts.json) {
console.log(JSON.stringify(inst)); console.log(JSON.stringify(inst));
} else if (inst.state === 'running') { } else if (inst.state === ctx.expectState) {
var dur = Date.now() - ctx.start; var dur = Date.now() - ctx.start;
console.log('Created instance %s (%s) in %s', console.log('Created instance %s (%s) in %s',
inst.name, inst.id, common.humanDurationFromMs(dur)); 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)', next(new Error(format('failed to create instance %s (%s)',
inst.name, inst.id))); inst.name, inst.id)));
} else { } else {
@ -492,6 +510,19 @@ do_create.options = [
{ {
group: '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'], names: ['name', 'n'],
helpArg: 'NAME', helpArg: 'NAME',

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2017, Joyent, Inc. * Copyright (c) 2018, Joyent, Inc.
* *
* `triton instance list ...` * `triton instance list ...`
*/ */
@ -152,6 +152,7 @@ function do_list(subcmd, opts, args, callback) {
var flags = []; var flags = [];
if (inst.docker) flags.push('D'); if (inst.docker) flags.push('D');
if (inst.firewall_enabled) flags.push('F'); if (inst.firewall_enabled) flags.push('F');
if (inst.brand === 'bhyve') flags.push('B');
if (inst.brand === 'kvm') flags.push('K'); if (inst.brand === 'kvm') flags.push('K');
inst.flags = flags.length ? flags.join('') : undefined; inst.flags = flags.length ? flags.join('') : undefined;
}); });
@ -208,6 +209,7 @@ do_list.help = [
'for convenience):', 'for convenience):',
' shortid* A short ID prefix.', ' shortid* A short ID prefix.',
' flags* Single letter flags summarizing some fields:', ' flags* Single letter flags summarizing some fields:',
' "B" the brand is "bhyve"',
' "D" docker instance', ' "D" docker instance',
' "F" firewall is enabled', ' "F" firewall is enabled',
' "K" the brand is "kvm"', ' "K" the brand is "kvm"',

View File

@ -133,7 +133,7 @@ do_create.help = [
'{{usage}}', '{{usage}}',
'', '',
'{{options}}', '{{options}}',
'Snapshot do not work for instances of type "kvm".' 'Snapshots do not work for instances of type "bhyve" or "kvm".'
].join('\n'); ].join('\n');
do_create.completionArgtypes = ['tritoninstance', 'none']; do_create.completionArgtypes = ['tritoninstance', 'none'];