TRITON-42 node-triton should support nics when creating an instance
Reviewed by: Michael Zeller <mike.zeller@joyent.com> Reviewed by: Trent Mick <trentm@gmail.com> Approved by: Trent Mick <trentm@gmail.com>
This commit is contained in:
parent
8e6cf27121
commit
06812c9cd4
@ -13,6 +13,13 @@ Known issues:
|
||||
`triton instance enable-deletion-protection ...`, and
|
||||
`triton instance disable-deletion-protection ...`. This flag is only supported
|
||||
on cloudapi versions 8.7.0 or above.
|
||||
- [TRITON-59] node-triton should support nic operations
|
||||
`triton instance nic get ...`
|
||||
`triton instance nic create ...`
|
||||
`triton instance nic list ...`
|
||||
`triton instance nic delete ...`
|
||||
- [TRITON-42] node-triton should support nics when creating an instance, e.g.
|
||||
`triton instance create --nic <Network Object> IMAGE PACKAGE`
|
||||
|
||||
## 5.9.0
|
||||
|
||||
|
@ -1427,9 +1427,9 @@ function ipv4ToLong(ip) {
|
||||
* ]
|
||||
* }
|
||||
* Note: "1234" is used as the UUID for this example, but would actually cause
|
||||
* `parseNicsCLI` to throw as it is not a valid UUID.
|
||||
* `parseNicStr` to throw as it is not a valid UUID.
|
||||
*/
|
||||
function parseNicsCLI(nic) {
|
||||
function parseNicStr(nic) {
|
||||
assert.arrayOfString(nic);
|
||||
|
||||
var obj = objFromKeyValueArgs(nic, {
|
||||
@ -1502,6 +1502,6 @@ module.exports = {
|
||||
readStdin: readStdin,
|
||||
validateObject: validateObject,
|
||||
ipv4ToLong: ipv4ToLong,
|
||||
parseNicsCLI: parseNicsCLI
|
||||
parseNicStr: parseNicStr
|
||||
};
|
||||
// vim: set softtabstop=4 shiftwidth=4:
|
||||
|
@ -19,6 +19,8 @@ var common = require('../common');
|
||||
var distractions = require('../distractions');
|
||||
var errors = require('../errors');
|
||||
var mat = require('../metadataandtags');
|
||||
var NETWORK_OBJECT_FIELDS =
|
||||
require('../cloudapi2').CloudApi.prototype.NETWORK_OBJECT_FIELDS;
|
||||
|
||||
function parseVolMount(volume) {
|
||||
var components;
|
||||
@ -83,6 +85,9 @@ function do_create(subcmd, opts, args, cb) {
|
||||
return;
|
||||
} else if (args.length !== 2) {
|
||||
return cb(new errors.UsageError('incorrect number of args'));
|
||||
} else if (opts.nic && opts.network) {
|
||||
return cb(new errors.UsageError(
|
||||
'--network and --nic cannot be specified together'));
|
||||
}
|
||||
|
||||
var log = this.top.log;
|
||||
@ -224,6 +229,47 @@ function do_create(subcmd, opts, args, cb) {
|
||||
next();
|
||||
},
|
||||
|
||||
/*
|
||||
* Parse any nics given via `--nic`
|
||||
*/
|
||||
function parseNics(ctx, next) {
|
||||
if (!opts.nic) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
ctx.nics = [];
|
||||
var i;
|
||||
var networksSeen = {};
|
||||
var nic;
|
||||
var nics = opts.nic;
|
||||
|
||||
log.trace({nics: nics}, 'parsing nics');
|
||||
|
||||
for (i = 0; i < nics.length; i++) {
|
||||
nic = nics[i].split(',');
|
||||
|
||||
try {
|
||||
nic = common.parseNicStr(nic);
|
||||
if (networksSeen[nic.ipv4_uuid]) {
|
||||
throw new errors.UsageError(format(
|
||||
'only 1 ip on a network allowed '
|
||||
+ '(network %s specified multiple times)',
|
||||
nic.ipv4_uuid));
|
||||
}
|
||||
networksSeen[nic.ipv4_uuid] = true;
|
||||
ctx.nics.push(nic);
|
||||
} catch (err) {
|
||||
next(err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
log.trace({nics: ctx.nics}, 'parsed nics');
|
||||
|
||||
next();
|
||||
},
|
||||
|
||||
/*
|
||||
* Determine `ctx.locality` according to what CloudAPI supports
|
||||
* based on `ctx.affinities` parsed earlier.
|
||||
@ -371,11 +417,17 @@ function do_create(subcmd, opts, args, cb) {
|
||||
var createOpts = {
|
||||
name: opts.name,
|
||||
image: ctx.img.id,
|
||||
'package': ctx.pkg && ctx.pkg.id,
|
||||
networks: ctx.nets && ctx.nets.map(
|
||||
function (net) { return net.id; })
|
||||
'package': ctx.pkg && ctx.pkg.id
|
||||
};
|
||||
|
||||
if (ctx.nets) {
|
||||
createOpts.networks = ctx.nets.map(function (net) {
|
||||
return net.id;
|
||||
});
|
||||
} else if (ctx.nics) {
|
||||
createOpts.networks = ctx.nics;
|
||||
}
|
||||
|
||||
if (ctx.volMounts) {
|
||||
createOpts.volumes = ctx.volMounts;
|
||||
}
|
||||
@ -539,6 +591,15 @@ do_create.options = [
|
||||
'This option can be used multiple times.',
|
||||
completionType: 'tritonnetwork'
|
||||
},
|
||||
{
|
||||
names: ['nic'],
|
||||
type: 'arrayOfString',
|
||||
helpArg: 'NICOPTS',
|
||||
help: 'A network interface object containing comma separated ' +
|
||||
'key=value pairs (Network object format). ' +
|
||||
'This option can be used multiple times for multiple NICs. ' +
|
||||
'Valid keys are: ' + Object.keys(NETWORK_OBJECT_FIELDS).join(', ')
|
||||
},
|
||||
{
|
||||
// TODO: add boolNegationPrefix:'no-' when that cmdln pull is in
|
||||
names: ['firewall'],
|
||||
|
@ -59,7 +59,7 @@ function do_create(subcmd, opts, args, cb) {
|
||||
}
|
||||
|
||||
try {
|
||||
netObj = common.parseNicsCLI(netObjArgs);
|
||||
netObj = common.parseNicStr(netObjArgs);
|
||||
} catch (err) {
|
||||
cb(err);
|
||||
return;
|
||||
|
Reference in New Issue
Block a user