From 849b42240b82ca642a7e59e82fe5b029085f1bbe Mon Sep 17 00:00:00 2001 From: Jeff Emershaw Date: Thu, 8 Mar 2018 14:00:44 -0500 Subject: [PATCH] PUBAPI-1378 Provide UpdateFabricNetwork endpoint --- CHANGES.md | 3 +++ bin/sdc-fabric | 55 ++++++++++++++++++++++++++++++++++++++++++ lib/cli/fabric-nets.js | 45 ++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 104 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4e45984..1598e79 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ # node-smartdc Changelog +## 8.1.1 +- PUBAPI-1378 Provide UpdateFabricNetwork endpoint + ## 8.1.0 - PUBAPI-1219 - add --cns-enable and --cns-disable options to diff --git a/bin/sdc-fabric b/bin/sdc-fabric index fd7473c..4fc20b6 100755 --- a/bin/sdc-fabric +++ b/bin/sdc-fabric @@ -291,6 +291,61 @@ FabricNetwork.prototype.do_get.help = ( ); +FabricNetwork.prototype.do_update = function (subcmd, opts, args, callback) { + var self = this; + + if (opts.help) { + return this.do_help('help', {}, [subcmd], callback); + } + + if (args.length !== 1) { + return callback(new Error('network_id must be specified')); + } + + // to match up with the behavior of other node-smartdc commands, we also + // want to be able to accept CSV and JSON here + if (opts.resolvers && opts.resolvers.length === 1) { + try { + opts.resolvers = JSON.parse(opts.resolvers[0]); + } catch (e) { + opts.resolvers = opts.resolvers[0].split(','); + } + } + + if (opts.routes) { + opts.routes = JSON.parse(opts.routes); + } + + return this.cloudapi.getFabricNetwork(args[0], + function _afterGet(err, net) { + if (err) { + return commonCb(err); + } + + return self.cloudapi.updateFabricNetwork(net.vlan_id, args[0], opts, + commonCb); + }); +}; + +FabricNetwork.prototype.do_update.options = [ + OPTIONAL.name, + OPTIONAL.resolvers, + OPTIONAL.no_internet_nat, + OPTIONAL.gateway, + OPTIONAL.description, + OPTIONAL.routes, + HELP_OPT +]; + +FabricNetwork.prototype.do_update.help = ( + 'Update an existing fabric network.\n' + + '\n' + + 'Usage:\n' + + ' {{name}} update [OPTIONS]\n' + + '\n' + + '{{options}}' +); + FabricNetwork.prototype.do_create = function (subcmd, opts, args, callback) { var self = this; if (opts.help) { diff --git a/lib/cli/fabric-nets.js b/lib/cli/fabric-nets.js index 0bbce8f..3cb813b 100644 --- a/lib/cli/fabric-nets.js +++ b/lib/cli/fabric-nets.js @@ -46,6 +46,50 @@ function createFabricNetwork(account, options, callback) { }); } +/** + * Update a fabric network. + * + * Returns a JS object (the created network). + * + * @param {String} account (optional) the login name of the account. + * @param {Number} vlanId the ID of the VLAN the network is on. + * @param {String} network the ID of the network. + * @param {Object} options object to be passed to the API + * @param {Function} callback of the form f(err, network). + * @param {Boolean} noCache optional flag to force skipping the cache. + * @throws {TypeError} on bad input. + */ +function updateFabricNetwork(account, vlanId, network, options, + callback, noCache) { + var self = this; + var opts; + + if (typeof (options) === 'function') { + noCache = callback; + callback = options; + options = network; + network = vlanId; + vlanId = account; + account = this.account; + } + + if (typeof (network) === 'function') { + noCache = callback; + callback = network; + network = vlanId; + vlanId = account; + account = this.account; + } + account = validate.account(account); + validate.network(network); + opts = validate.networkOptions(options); + validate.callback(callback); + + return self._request(sprintf(paths.fabricNetwork, account, vlanId, + network), opts, function (req) { + return self._put(req, callback, noCache); + }); +} /** * Deletes a fabric network. @@ -160,6 +204,7 @@ function listFabricNetworks(account, options, callback, noCache) { module.exports = { createFabricNetwork: createFabricNetwork, + updateFabricNetwork: updateFabricNetwork, deleteFabricNetwork: deleteFabricNetwork, getFabricNetwork: getFabricNetwork, listFabricNetworks: listFabricNetworks diff --git a/package.json b/package.json index f1d765a..a103862 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Joyent, Inc. http://www.joyent.com", "name": "smartdc", "description": "Client SDK and CLI for the Joyent SmartDataCenter API", - "version": "8.1.0", + "version": "8.1.1", "repository": { "type": "git", "url": "git://github.com/joyent/node-smartdc.git"