joyent-portal/portal-api/lib/handlers.js

83 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2017-04-28 00:59:03 +03:00
'use strict';
// Deployments
exports.deploymentCreate = function (request, reply) {
const deploymentRoute = request.server.lookup('deploymentGet');
this.createDeployment(request.payload).then((deployment) => {
reply(deployment).created(deploymentRoute.path.replace('{deployment}', deployment.id));
}).catch((error) => {
reply(error);
});
};
exports.deploymentGet = function (request, reply) {
2017-05-02 23:31:05 +03:00
reply(this.getDeployment(request.params.deploymentId));
2017-04-28 00:59:03 +03:00
};
exports.deploymentUpdate = function (request, reply) {
const payload = request.payload;
2017-05-02 01:28:03 +03:00
payload.id = request.params.deploymentId;
2017-04-28 00:59:03 +03:00
reply(this.updateDeployment(payload));
};
exports.deploymentDelete = function (request, reply) {
2017-05-02 23:31:05 +03:00
reply(this.deleteDeployment(request.params.deploymentId));
2017-04-28 00:59:03 +03:00
};
exports.deploymentsGet = function (request, reply) {
reply(this.getDeployments());
};
// Datacenters
exports.datacentersGet = function (request, reply) {
reply(this.getDatacenters());
};
// Manifests
exports.manifestCreate = function (request, reply) {
const manifestRoute = request.server.lookup('manifestGet');
const deploymentId = request.params.deploymentId;
this.createManifest(deploymentId, request.payload).then((manifest) => {
2017-05-02 23:31:05 +03:00
reply(manifest).created(manifestRoute.path.replace('{deployment}', deploymentId).replace('{manifestId}', manifest.id));
2017-04-28 00:59:03 +03:00
}).catch((error) => {
reply(error);
});
};
exports.manifestGet = function (request, reply) {
2017-05-02 23:31:05 +03:00
reply(this.getManifest(request.params.manifestId));
2017-04-28 00:59:03 +03:00
};
// Activities and Metrics
exports.activitiesGet = function (request, reply) {
reply(this.getActivities(request.params.deploymentId));
};
exports.metricsGet = function (request, reply) {
reply(this.getMetrics(request.params.deploymentId));
};
// Services
exports.servicesGet = function (request, reply) {
reply(this.getServices(request.params.deploymentId));
};
exports.serviceUpdate = function (request, reply) {
const service = request.payload;
service.name = request.params.name;
reply(this.updateService(request.params.deploymentId, service));
};