Skip to content

Commit

Permalink
ZAPI-781 Pass server NIC tag information to NAPI
Browse files Browse the repository at this point in the history
Reviewed by: Marsell Kukuljevic <marsell@joyent.com>
Reviewed by: Josh Wilsdon <jwilsdon@joyent.com>
Approved by: Josh Wilsdon <jwilsdon@joyent.com>
  • Loading branch information
melloc committed Jun 1, 2017
1 parent 590a4e0 commit 65a88b2
Show file tree
Hide file tree
Showing 3 changed files with 234 additions and 214 deletions.
123 changes: 3 additions & 120 deletions lib/workflows/add-nics.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

var async; // stub to keep jsl happy
var common = require('./job-common');
var VERSION = '7.1.0';
var VERSION = '7.2.0';


/*
Expand All @@ -45,123 +45,6 @@ function setupRequest(job, cb) {
}


/*
* Get server object so we can check if it has the corresponding NIC tags
*/
function getServerNicTags(job, cb) {
var cnapi = new sdcClients.CNAPI({
url: cnapiUrl,
headers: { 'x-request-id': job.params['x-request-id'] }
});

// Goes inside the "NIC Names" array and extracts the NIC Tags for each NIC
function mapNics(object) {
var nics = [];

for (var key in object) {
var subNics = object[key]['NIC Names'];
nics = nics.concat(subNics);
}

return nics;
}

// Goes inside the "Overlay Nic Tags" array and extracts the NIC Tags for
// each vnic
function mapVnics(object) {
var nics = [];
if (!object) {
object = {};
}

for (var key in object) {
var subNics = object[key]['Overlay Nic Tags'];
nics = nics.concat(subNics);
}

return nics;
}

cnapi.getServer(job.params.server_uuid, function (err, server) {
if (err) {
return cb(err);
}

job.serverNicTags =
mapNics(server.sysinfo['Network Interfaces']).concat(
mapVnics(server.sysinfo['Virtual Network Interfaces']));

return cb();
});
}


/*
* Checks that the server has the NIC tags for every network or NIC that was
* passed.
*/
function checkServerNicTags(job, cb) {
var napi = new sdcClients.NAPI({
url: napiUrl,
headers: { 'x-request-id': job.params['x-request-id'] }
});

function done(err) {
if (err) {
cb(err);
} else {
cb(null, 'Server has all the required NIC tags');
}
}

var macs = job.params.macs;

// If 'macs' was passed, we're dealing with pre-created NICs, so we need
// to pull the NICs from NAPI first.
if (macs) {
async.mapSeries(macs, function (mac, next) {
napi.getNic(mac, function (err, nic) {
if (err) {
return next(err);
}

var msg;
var nicTag = nic.nic_tag;

if (!nicTag) {
msg = 'NIC does not have a tag';
return next(new Error(msg));
}

// this hack is to split the nic tag off from the vnet_id,
// which fabric nics have embedded in their nic_tag attribute
var overlay = nicTag.match(/^(.+)\/\d+$/);
nicTag = overlay ? overlay[1] : nicTag;

if (job.serverNicTags.indexOf(nicTag) === -1) {
msg = 'Server does not have NIC tag: ' + nicTag;
return next(new Error(msg));
}

return next();
});
}, done);

// Otherwise we're dealing with networks. nicTags for these networks were
// loaded by the common.validateNetworks() task below.
} else {
for (var i = 0; i !== job.nicTags.length; i++) {
var tag = job.nicTags[i];

if (job.serverNicTags.indexOf(tag) === -1) {
return done(new Error('Server does not have NIC tag: ' + tag));
}
}

return done();
}
}


var workflow = module.exports = {
name: 'add-nics-' + VERSION,
Expand All @@ -188,13 +71,13 @@ var workflow = module.exports = {
name: 'cnapi.get_server_nic_tags',
timeout: 10,
retry: 1,
body: getServerNicTags,
body: common.getServerNicTags,
modules: { sdcClients: 'sdc-clients' }
}, {
name: 'napi.check_server_nic_tags',
timeout: 10,
retry: 1,
body: checkServerNicTags,
body: common.checkServerNicTags,
modules: { sdcClients: 'sdc-clients', async: 'async' }
}, {
name: 'napi.provision_nics',
Expand Down
Loading

0 comments on commit 65a88b2

Please sign in to comment.