Skip to content

Commit

Permalink
#86 want support for additional "external" NIC tags (#103)
Browse files Browse the repository at this point in the history
Actually-authored-by: Alex Wilson <[email protected]>
Reviewed by: Dan McDonald <[email protected]>
Reviewed by: Brian Bennett <[email protected]>
  • Loading branch information
bahamat authored May 24, 2021
1 parent 3f1a70a commit a227b98
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 13 deletions.
22 changes: 14 additions & 8 deletions lib/endpoints/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

/*
* Copyright (c) 2019, Joyent, Inc.
* Copyright 2021 Joyent, Inc.
* Copyright 2021 The University of Queensland
*/

var assert = require('assert-plus');
Expand Down Expand Up @@ -136,7 +137,7 @@ function translateErr(err) {


// Note here "net" can be a network, fabric network or network_pool from NAPI
function translateNetwork(net) {
function translateNetwork(req, net) {
assert.object(net, 'net');

var obj = {
Expand All @@ -151,6 +152,11 @@ function translateNetwork(net) {
isPublic = false;
} else {
isPublic = netconfig.isNetExternal(net);
req.config.extra_external_tags.forEach(function (tag) {
if (netconfig.isNetTagged(net, tag)) {
isPublic = true;
}
});
}

obj['public'] = isPublic;
Expand Down Expand Up @@ -254,7 +260,7 @@ function listNetworks(req, res, next) {
// assuming this list never gets too big
return skipNetworkUuids.indexOf(n.uuid) === -1;
}).map(function (pool) {
return translateNetwork(pool);
return translateNetwork(req, pool);
});

req.log.debug({
Expand Down Expand Up @@ -282,7 +288,7 @@ function getNetwork(req, res, next) {
resources.getRoleTags(req, res);
}

network = translateNetwork(net[0]);
network = translateNetwork(req, net[0]);

req.log.debug({
network: network,
Expand Down Expand Up @@ -597,7 +603,7 @@ function updateFabricNetwork(req, res, next) {
return;
}

res.send(translateNetwork(network));
res.send(translateNetwork(req, network));
next();
});
}
Expand Down Expand Up @@ -707,7 +713,7 @@ function listFabricNetworks(req, res, next) {

res.send(networks.map(function _translateNetwork(network) {
assert.object(network, 'network');
return translateNetwork(network);
return translateNetwork(req, network);
}));

next();
Expand Down Expand Up @@ -747,7 +753,7 @@ function createFabricNetwork(req, res, next) {
return;
}

res.send(201, translateNetwork(network));
res.send(201, translateNetwork(req, network));
next();
});
}
Expand All @@ -774,7 +780,7 @@ function getFabricNetwork(req, res, next) {
return;
}

res.send(translateNetwork(network));
res.send(translateNetwork(req, network));
next();
});
}
Expand Down
15 changes: 14 additions & 1 deletion lib/middleware/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

/*
* Copyright (c) 2019, Joyent, Inc.
* Copyright 2021 Joyent, Inc.
* Copyright 2021 The University of Queensland
*/


Expand Down Expand Up @@ -102,6 +103,12 @@ function loadNetworks(req, res, next) {
externalNetworks.push(pool.uuid);
} else if (netconf.isNetInternal(pool) || isFabric === true) {
internalNetworks.push(pool.uuid);
} else {
req.config.extra_external_tags.forEach(function (tag) {
if (netconf.isNetTagged(pool, tag)) {
externalNetworks.push(pool.uuid);
}
});
}
});

Expand All @@ -127,6 +134,12 @@ function loadNetworks(req, res, next) {
externalNetworks.push(net.uuid);
} else if (netconf.isNetInternal(net) || net.fabric === true) {
internalNetworks.push(net.uuid);
} else {
req.config.extra_external_tags.forEach(function (tag) {
if (netconf.isNetTagged(net, tag)) {
externalNetworks.push(net.uuid);
}
});
}
});

Expand Down
4 changes: 3 additions & 1 deletion lib/plugin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

/*
* Copyright 2020 Joyent, Inc.
* Copyright 2021 Joyent, Inc.
* Copyright 2021 The University of Queensland
*/

/*
Expand Down Expand Up @@ -82,6 +83,7 @@ function init(app) {
self.api = {
log: app.log,
datacenterName: app.config.datacenter_name,
extraExternalTags: app.config.extra_external_tags,
service: 'cloudapi',
NotAuthorizedError: require('restify').NotAuthorizedError,
getNapiNetworksForAccount: function getNapiShim(obj, cb) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"sdc-clients": "git+https://github.com/joyent/node-sdc-clients.git#01b9136799e4c76e26c59dd266cd5435cccde534",
"semver": "5.4.1",
"triton-metrics": "1.0.3",
"triton-netconfig": "1.3.0",
"triton-netconfig": "1.5.0",
"ufds": "1.7.0",
"uuid": "^8.3.0",
"uuid-by-string": "0.6.0",
Expand Down
11 changes: 9 additions & 2 deletions plugins/filter_owner_networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/

/*
* Copyright (c) 2019, Joyent, Inc.
* Copyright 2021 Joyent, Inc.
* Copyright 2021 The University of Queensland
*/

/*
Expand Down Expand Up @@ -131,7 +132,13 @@ function findOwnerExternalNetwork(api, cfg) {
});

var external = owned.filter(function filterExternal(network) {
return (netconf.isNetExternal(network));
var ext = netconf.isNetExternal(network);
api.extraExternalTags.forEach(function (tag) {
if (netconf.isNetTagged(network, tag)) {
ext = true;
}
});
return ext;
});

if (external.length === 0) {
Expand Down
7 changes: 7 additions & 0 deletions sapi_manifests/cloudapi/template
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@
}
},

{{#CLOUDAPI_EXTERNAL_TAGS}}
"extra_external_tags": {{{CLOUDAPI_EXTERNAL_TAGS}}},
{{/CLOUDAPI_EXTERNAL_TAGS}}
{{^CLOUDAPI_EXTERNAL_TAGS}}
"extra_external_tags": [],
{{/CLOUDAPI_EXTERNAL_TAGS}}

{{^account_allowed_dcs}}
"account_allowed_dcs": false,
{{/account_allowed_dcs}}
Expand Down

0 comments on commit a227b98

Please sign in to comment.