Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ markdown2extras: tables, code-friendly
-->

<!--
Copyright (c) 2018, Joyent, Inc.
Copyright (c) 2019, Joyent, Inc.
-->

<!--
Expand Down Expand Up @@ -1457,6 +1457,22 @@ install and server will download and install package.
| 500 | Error | Could not process request |


## ServerRefreshAgents (POST /servers/:server_uuid/refresh-agents)

Makes cn-agent refresh the values for the agents setup on the server and
post them back to CNAPI

### Inputs

None.

### Responses

| Code | Type | Description |
| ---- | ----- | ----------------------------------- |
| 200 | Ok | Install task initiated successfully |
| 500 | Error | Could not process request |


# Virtual Machine API

Expand Down
94 changes: 68 additions & 26 deletions lib/endpoints/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

/*
* Copyright (c) 2018, Joyent, Inc.
* Copyright (c) 2019, Joyent, Inc.
*/

/*
Expand All @@ -15,17 +15,13 @@
*/

var async = require('async');
var fs = require('fs');
var qs = require('qs');
var restify = require('restify');
var semver = require('semver');
var sprintf = require('sprintf').sprintf;
var util = require('util');
var vasync = require('vasync');
var VError = require('verror');

var common = require('../common');
var datasetEndpoints = require('./zfs');
var Designation = require('../designation');
var ModelPlatform = require('../models/platform');
var ModelServer = require('../models/server');
Expand Down Expand Up @@ -58,8 +54,10 @@ function Server() {}
* @param {Boolean} reserved Return only reserved servers
* @param {Boolean} reservoir Return only reservoir servers
* @param {String} hostname Return machine with given hostname
* @param {String} extras Comma seperated values: agents, vms, memory, disk, sysinfo, capacity, all
* @param {Integer} limit Maximum number of results to return. It must be between 1-1000, inclusive. Defaults to 1000 (the maxmimum allowed value).
* @param {String} extras Comma seperated values: agents, vms, memory, disk,
* sysinfo, capacity, all
* @param {Integer} limit Maximum number of results to return. It must be
* between 1-1000, inclusive. Defaults to 1000 (the maxmimum allowed value).
* @param {Integer} offset Offset the subset of results returned
*
* @example GET /servers
Expand All @@ -82,7 +80,7 @@ Server.list = function handlerSeverList(req, res, next) {
],
'extras': [
['optional', undefined],
/*JSSTYLED*/
/* JSSTYLED */
['regex', RegExp(/^[a-zA-Z_]+(,[a-zA-Z_]+)*$/i)]
],
'reserved': [
Expand All @@ -105,7 +103,7 @@ Server.list = function handlerSeverList(req, res, next) {
'offset': ['optional', 'isInt'],
'uuids': [
['optional', undefined],
/*JSSTYLED*/
/* JSSTYLED */
['regex', RegExp(/^[-a-z0-9A-Z]+(,[-a-z0-9A-Z]+)*$/i)]
]
};
Expand Down Expand Up @@ -319,11 +317,15 @@ Server.get = function handlerServerGet(req, res, next) {
* @param {Boolean} reserved Server is available for provisioning
* @param {Boolean} reservoir Server should be considered last for provisioning
* @param {Nmber} reservation_ratio The reservation ratio
* @param {Object} overprovision_ratios The overprovisioning ratios. Must be an object with Number value keys and keys must be one of 'cpu', 'ram', 'disk', 'io', 'net'.
* @param {Object} overprovision_ratios The overprovisioning ratios. Must be
* an object with Number value keys and keys must be one of
* 'cpu', 'ram', 'disk', 'io', 'net'.
* @param {String} serial Serial device
* @param {Boolean} setup True if server has been set up
* @param {Boolean} setting_up True if server is in the process of setting up
* @param {String} transitional_status The fallback status if not 'running'. For example, if the server has to reboot, this value may be set to 'rebooting'.
* @param {String} transitional_status The fallback status if not 'running'.
* For example, if the server has to reboot, this value may be set to
* 'rebooting'.
* @param {Object} traits Server traits
*
* @example POST /servers/12494d5e-3960-4d65-a61a
Expand Down Expand Up @@ -379,8 +381,8 @@ Server.update = function handlerServerUpdate(req, res, next) {
}
});

req.params.overprovision_ratios
= qs.stringify(req.params.overprovision_ratios);
req.params.overprovision_ratios =
qs.stringify(req.params.overprovision_ratios);
}

// Check that if next_reboot is set, it is an ISO date string.
Expand Down Expand Up @@ -423,15 +425,15 @@ Server.update = function handlerServerUpdate(req, res, next) {
return;
}

if (type == String) {
if (type === String) {
change[param] = val;
} else if (type == Boolean) {
} else if (type === Boolean) {
if (val === true) {
change[param] = true;
} else if (val === false) {
change[param] = false;
}
} else if (type == Number) {
} else if (type === Number) {
change[param] = Number(val);
} else {
change[param] = val;
Expand Down Expand Up @@ -470,7 +472,7 @@ Server.update = function handlerServerUpdate(req, res, next) {
return;
}

req.stash.server.getRaw(function (error, server) {
req.stash.server.getRaw(function (error, _server) {
if (error) {
cb(new VError('failed to fetch vms'));
return;
Expand All @@ -488,15 +490,15 @@ Server.update = function handlerServerUpdate(req, res, next) {
return;
}

req.stash.server.getRaw(function (error, raw) {
req.stash.server.getRaw(function (_error, raw) {
if (!raw.setup) {
cb();
return;
}

var request = {
task: 'server_overprovision_ratio',
cb: function (err, task) {
cb: function (_err, _task) {
},
evcb: function () {},
synccb: function (err, result) {
Expand Down Expand Up @@ -565,7 +567,7 @@ Server.reboot = function handlerServerReboot(req, res, next) {
return;
}

req.stash.server.getRaw(function (error, rawserver) {
req.stash.server.getRaw(function (_error, _rawserver) {
var params = {
origin: req.params.origin,
creator_uuid: req.params.creator_uuid,
Expand Down Expand Up @@ -713,7 +715,7 @@ Server.setup = function handlerServerSetup(req, res, next) {
params.disk_layout = layout;
}

req.stash.server.getRaw(function (error, rawserver) {
req.stash.server.getRaw(function (_error, rawserver) {
if (rawserver.setup) {
res.send(204);
next();
Expand Down Expand Up @@ -953,6 +955,35 @@ Server.taskHistory = function handlerServerTaskHistory(req, res, next) {
});
};

/* BEGIN JSSTYLED */
/**
* Makes cn-agent refresh the values for the agents setup on the server and
* post them back to CNAPI
*
* @name ServerRefreshAgents
* @endpoint POST /servers/:server_uuid/refresh-agents
* @section Server API
*
* @response 200 Ok task initiated successfully
* @response 500 Error Could not process request
*/
/* END JSSTYLED */
Server.refreshAgents = function handlerServerRefreshAgents(req, res, next) {
var self = this;

req.stash.server.sendTaskRequest({
task: 'refresh_agents',
params: req.params,
req: req,
evcb: ModelServer.createComputeNodeAgentHandler(self, req.params.jobid),
cb: function (_error, task) {
res.send({ id: task.id });
next();
return;
}
});
};

/* BEGIN JSSTYLED */
/**
* Makes cn-agent stop accepting new tasks
Expand Down Expand Up @@ -1086,8 +1117,8 @@ Server.ensureImage = function handlerServerEnsureImage(req, res, next) {
var rules = {
'server_uuid': ['isStringType'],
'image_uuid': ['isStringType'],
'zfs_storage_pool_name': ['optional', 'isStringType'],
'imgapiPeers': ['optional', 'isArrayType']
'zfs_storage_pool_name': ['optional', 'isStringType'],
'imgapiPeers': ['optional', 'isArrayType']
};

if (validation.ensureParamsValid(req, res, rules, { strict: true })) {
Expand All @@ -1100,7 +1131,7 @@ Server.ensureImage = function handlerServerEnsureImage(req, res, next) {
params: req.params,
req: req,
evcb: ModelServer.createComputeNodeAgentHandler(self, req.params.jobid),
cb: function (error, task) {
cb: function (_error, task) {
res.send({ id: task.id });
next();
return;
Expand Down Expand Up @@ -1287,7 +1318,7 @@ Server.installAgent = function handlerServerInstallAgent(req, res, next) {
params: req.params,
req: req,
evcb: ModelServer.createComputeNodeAgentHandler(self, req.params.jobid),
cb: function (error, task) {
cb: function (_error, task) {
res.send({ id: task.id });
next();
return;
Expand All @@ -1301,7 +1332,7 @@ Server.nop = function handlerServerNop(req, res, next) {
task: 'nop',
params: req.params,
req: req,
cb: function (error, taskstatus) {
cb: function (_error, taskstatus) {
res.send({ id: taskstatus.id });
next();
}
Expand Down Expand Up @@ -1467,6 +1498,17 @@ function attachTo(http, app) {
}),
Server.taskHistory);

http.post({
path: '/servers/:server_uuid/refresh-agents',
name: 'ServerRefreshAgents'
}, ensure({
connectionTimeoutSeconds: 60 * 60,
app: app,
serverRunning: true,
prepopulate: ['server'],
connected: ['moray']
}), Server.refreshAgents);

// cn-agent pause-resume
http.post({
path: '/servers/:server_uuid/cn-agent/pause',
Expand Down