diff --git a/src/serverroot/common/computemanager.api.js b/src/serverroot/common/computemanager.api.js
index 7d777ed61..106433c62 100644
--- a/src/serverroot/common/computemanager.api.js
+++ b/src/serverroot/common/computemanager.api.js
@@ -52,8 +52,56 @@ function getVMStatsByProject (projUUID, req, callback)
function getFlavors(req, callback)
{
- computeApi.getFlavors(req, function(err,data){
- callback(err,data);
+ computeApi.getFlavors(req, function(err, data) {
+ callback(err, data);
+ });
+}
+
+function pauseInstance(req, callback)
+{
+ computeApi.pauseInstance(req, function(err, data) {
+ callback(err, data);
+ });
+}
+
+function resumeInstance(req, callback)
+{
+ computeApi.resumeInstance(req, function(err, data) {
+ callback(err, data);
+ });
+}
+
+function suspendInstance(req, callback)
+{
+ computeApi.suspendInstance(req, function(err, data) {
+ callback(err, data);
+ });
+}
+
+function deleteInstance(req, callback)
+{
+ computeApi.deleteInstance(req, function(err, data) {
+ callback(err, data);
+ });
+}
+
+function softRebootInstance(req, callback)
+{
+ computeApi.softRebootInstance(req, function(err, data) {
+ callback(err, data);
+ });
+}
+function hardRebootInstance(req, callback)
+{
+ computeApi.hardRebootInstance(req, function(err, data) {
+ callback(err, data);
+ });
+}
+
+function createImage(req, callback)
+{
+ computeApi.createImage(req, function(err, data) {
+ callback(err, data);
});
}
@@ -63,3 +111,11 @@ exports.launchVNC = launchVNC;
exports.getServiceInstanceVMStatus = getServiceInstanceVMStatus;
exports.getVMStatsByProject = getVMStatsByProject;
exports.getFlavors = getFlavors;
+exports.pauseInstance = pauseInstance;
+exports.resumeInstance = resumeInstance;
+exports.suspendInstance = suspendInstance;
+exports.deleteInstance = deleteInstance;
+exports.softRebootInstance = softRebootInstance;
+exports.hardRebootInstance = hardRebootInstance;
+exports.createImage = createImage;
+
diff --git a/src/serverroot/orchestration/plugins/openstack/nova.api.js b/src/serverroot/orchestration/plugins/openstack/nova.api.js
index 6102d897d..e32fad5b4 100644
--- a/src/serverroot/orchestration/plugins/openstack/nova.api.js
+++ b/src/serverroot/orchestration/plugins/openstack/nova.api.js
@@ -180,6 +180,40 @@ function launchVNCV11 (error, data, callback)
callback(null, data);
}
}
+/* Wrapper function to Nova-Server to DELETE a VM Instance */
+novaApi.delete = function(reqUrl, req, callback, stopRetry) {
+ var headers = {};
+ var forceAuth = stopRetry;
+ var tenantId = getTenantIdByReqCookie(req);
+ if (null == tenantId) {
+ /* Just return as we will be redirected to login page */
+ return;
+ }
+
+ headers['User-Agent'] = 'Contrail-WebClient';
+ doNovaOpCb(reqUrl, tenantId, req, novaApi.get, stopRetry,
+ function(err, tokenObj) {
+ if ((err) || (null == tokenObj) || (null == tokenObj.id)) {
+ callback(err, null);
+ } else {
+ headers['X-Auth-Token'] = tokenObj.id;
+ novaAPIServer.api.delete(reqUrl, function(err, data) {
+ if (err) {
+ /* Just retry in case of if it fails, it may happen that failure is
+ * due to token change, so give one more change
+ */
+ if (stopRetry) {
+ callback(err, data);
+ } else {
+ novaApi.get(reqUrl, req, callback, true);
+ }
+ } else {
+ callback(err, data);
+ }
+ }, headers);
+ }
+ });
+}
function getNovaData (novaCallObj, callback)
{
@@ -429,9 +463,104 @@ function getFlavors (req, callback)
});
}
+function instanceActions(req, callback, action)
+{
+ var tenantStr = getTenantIdByReqCookie(req);
+ if(null == tenantStr) {
+ /* Just return as we will be redirected to login page */
+ return;
+ }
+ authApi.getTokenObj(req, tenantStr, true, function(err, data){
+ if(err) {
+ logutils.logger.error("Error in getting token object for tenant: " + tenantStr);
+ callback(err, null);
+ return;
+ }
+ var tenantId = data['tenant']['id'];
+ var serverId = req.param('serverId');
+ var reqUrl = '/v1.1/' + tenantId + '/servers/' + serverId;
+ var postData = '';
+ if(action === 'delete') {
+ novaApi.delete(reqUrl, req, function(err, data){
+ callback(err, data);
+ });
+ }
+ else {
+ reqUrl = reqUrl + '/action';
+ switch(action) {
+ case 'pause':
+ postData = {"pause":null};
+ break;
+ case 'resume':
+ postData = {"os-resetState": {"state": "active"}};
+ break;
+ case 'suspend':
+ postData = {"suspend":null};
+ break;
+ case 'soft-reboot':
+ postData = {"reboot": {"type": "SOFT"}};
+ break;
+ case 'hard-reboot':
+ postData = {"reboot": {"type": "HARD"}};
+ break;
+ case 'create-image':
+ var imgName = req.body['imageName'];
+ console.log("IMG-NAME:" + imgName);
+ postData = {"createImage": {"name": imgName, "metadata": {}}};
+ break;
+ }
+ }
+ novaApi.post(reqUrl, postData, req, function(err, data){
+ callback(err, data);
+ });
+ });
+}
+
+
+function pauseInstance(req, callback)
+{
+ instanceActions(req, callback, 'pause');
+}
+
+function resumeInstance(req, callback)
+{
+ instanceActions(req, callback, 'resume');
+}
+
+function suspendInstance(req, callback)
+{
+ instanceActions(req, callback, 'suspend');
+}
+
+function deleteInstance(req, callback)
+{
+ instanceActions(req, callback, 'delete');
+}
+
+function softRebootInstance(req, callback)
+{
+ instanceActions(req, callback, 'soft-reboot');
+}
+
+function hardRebootInstance(req, callback)
+{
+ instanceActions(req, callback, 'hard-reboot');
+}
+
+function createImage(req, callback)
+{
+ instanceActions(req, callback, 'create-image');
+}
exports.launchVNC = launchVNC;
exports.getServiceInstanceVMStatus = getServiceInstanceVMStatus;
exports.getVMStatsByProject = getVMStatsByProject;
exports.getFlavors = getFlavors;
+exports.pauseInstance = pauseInstance;
+exports.resumeInstance = resumeInstance;
+exports.suspendInstance = suspendInstance;
+exports.deleteInstance = deleteInstance;
+exports.softRebootInstance = softRebootInstance;
+exports.hardRebootInstance = hardRebootInstance;
+exports.createImage = createImage;
diff --git a/src/serverroot/web/api/network.mon.api.js b/src/serverroot/web/api/network.mon.api.js
index 984acd4d7..8441f8f33 100644
--- a/src/serverroot/web/api/network.mon.api.js
+++ b/src/serverroot/web/api/network.mon.api.js
@@ -16,8 +16,8 @@ var cacheApi = require('../core/cache.api'),
infra = require('./infraoverview.api'),
logutils = require('../../utils/log.utils'),
nwMonUtils = require('../../common/nwMon.utils'),
- appErrors = require('../../errors/app.errors');
-
+ appErrors = require('../../errors/app.errors'),
+ computeApi = require('../../common/computemanager.api');
nwMonApi = module.exports;
opServer = rest.getAPIServer({apiName: global.label.OPS_API_SERVER,
server: config.analytics.server_ip,
@@ -2484,6 +2484,55 @@ function getInstanceDetails (req, res, appData)
});
}
+function pauseInstance(req, res, appData)
+{
+ computeApi.pauseInstance(req, function(err, data){
+ commonUtils.handleJSONResponse(err, res, data);
+ });
+}
+
+function resumeInstance(req, res, appData)
+{
+ computeApi.resumeInstance(req, function(err, data){
+ commonUtils.handleJSONResponse(err, res, data);
+ });
+}
+
+function suspendInstance(req, res, appData)
+{
+ computeApi.suspendInstance(req, function(err, data){
+ commonUtils.handleJSONResponse(err, res, data);
+ });
+}
+
+function deleteInstance(req, res, appData)
+{
+ computeApi.deleteInstance(req, function(err, data){
+ commonUtils.handleJSONResponse(err, res, data);
+ });
+}
+
+function softRebootInstance(req, res, appData)
+{
+ computeApi.softRebootInstance(req, function(err, data){
+ commonUtils.handleJSONResponse(err, res, data);
+ });
+}
+
+function hardRebootInstance(req, res, appData)
+{
+ computeApi.hardRebootInstance(req, function(err, data){
+ commonUtils.handleJSONResponse(err, res, data);
+ });
+}
+
+function createImage(req, res, appData)
+{
+ computeApi.createImage(req, function(err, data){
+ commonUtils.handleJSONResponse(err, res, data);
+ });
+}
+
/* List all public functions */
exports.getTopNetworkDetailsByDomain = getTopNetworkDetailsByDomain;
exports.getTopNetworkDetailsByProject = getTopNetworkDetailsByProject;
@@ -2515,4 +2564,10 @@ exports.isAllowedVN = isAllowedVN;
exports.getVNListByProject = getVNListByProject;
exports.getOpServerPagedResponseByLastKey = getOpServerPagedResponseByLastKey;
exports.sortUVEList = sortUVEList;
-
+exports.pauseInstance = pauseInstance;
+exports.resumeInstance = resumeInstance;
+exports.suspendInstance = suspendInstance;
+exports.deleteInstance = deleteInstance;
+exports.softRebootInstance = softRebootInstance;
+exports.hardRebootInstance = hardRebootInstance;
+exports.createImage = createImage;
diff --git a/src/xml/parseURL.xml b/src/xml/parseURL.xml
index ef468afc4..5890092aa 100644
--- a/src/xml/parseURL.xml
+++ b/src/xml/parseURL.xml
@@ -1244,6 +1244,48 @@
monitoring
nwMonApi.getTopNetworkDetailsByDomain
+ -
+ /api/tenant/networking/pause-instance
+ get
+ monitoring
+ nwMonApi.pauseInstance
+
+ -
+ /api/tenant/networking/resume-instance
+ get
+ monitoring
+ nwMonApi.resumeInstance
+
+ -
+ /api/tenant/networking/suspend-instance
+ get
+ monitoring
+ nwMonApi.suspendInstance
+
+ -
+ /api/tenant/networking/delete-instance
+ get
+ monitoring
+ nwMonApi.deleteInstance
+
+ -
+ /api/tenant/networking/soft-reboot-instance
+ get
+ monitoring
+ nwMonApi.softRebootInstance
+
+ -
+ /api/tenant/networking/hard-reboot-instance
+ get
+ monitoring
+ nwMonApi.hardRebootInstance
+
+ -
+ /api/tenant/networking/create-image
+ post
+ monitoring
+ nwMonApi.createImage
+
-
/api/tenant/networking/project/stats/top
get