Commit 30f429cc authored by Markos Gogoulos's avatar Markos Gogoulos
Browse files

implement server actions on gui for api/v1.1redux

 * implement server reboot/shutdown/start/destroy actions
 * fix ordering on imports (servers.py, actions.py)
 * actions.py: change type to reboot_type (reserverd word)
 * change vm.start_action to backend.start_action where needed
(there is no vm.start_action any more)
 * create server action function in synnefo.js

Refs #311
parent 0cb51bef
......@@ -2,12 +2,13 @@
# Copyright (c) 2010 Greek Research and Technology Network
#
from synnefo.api.errors import *
from synnefo.util.rapi import GanetiRapiClient
from django.conf import settings
from django.http import HttpResponse
from synnefo.api.errors import *
from synnefo.util.rapi import GanetiRapiClient
from synnefo.logic import backend, utils
server_actions = {}
rapi = GanetiRapiClient(*settings.GANETI_CLUSTER_INFO)
......@@ -51,12 +52,12 @@ def reboot(server, args):
# buildInProgress (409),
# overLimit (413)
type = args.get('type', '')
if type not in ('SOFT', 'HARD'):
reboot_type = args.get('type', '')
if reboot_type not in ('SOFT', 'HARD'):
raise BadRequest()
server.start_action('REBOOT')
rapi.RebootInstance(server.backend_id, type.lower())
backend.start_action(server, 'REBOOT')
rapi.RebootInstance(server.backend_id, reboot_type.lower())
return HttpResponse(status=202)
@server_action('start')
......@@ -64,7 +65,7 @@ def start(server, args):
# Normal Response Code: 202
# Error Response Codes: serviceUnavailable (503), itemNotFound (404)
server.start_action('START')
backend.start_action(server, 'START')
rapi.StartupInstance(server.backend_id)
return HttpResponse(status=202)
......@@ -73,7 +74,7 @@ def shutdown(server, args):
# Normal Response Code: 202
# Error Response Codes: serviceUnavailable (503), itemNotFound (404)
server.start_action('STOP')
backend.start_action(server, 'STOP')
rapi.ShutdownInstance(server.backend_id)
return HttpResponse(status=202)
......
......@@ -2,11 +2,7 @@
# Copyright (c) 2010 Greek Research and Technology Network
#
from synnefo.api.actions import server_actions
from synnefo.api.errors import *
from synnefo.api.util import *
from synnefo.db.models import *
from synnefo.util.rapi import GanetiRapiClient
from logging import getLogger
from django.conf import settings
from django.conf.urls.defaults import *
......@@ -14,9 +10,12 @@ from django.http import HttpResponse
from django.template.loader import render_to_string
from django.utils import simplejson as json
from logging import getLogger
from logic import utils
from synnefo.api.actions import server_actions
from synnefo.api.errors import *
from synnefo.api.util import *
from synnefo.db.models import *
from synnefo.util.rapi import GanetiRapiClient
from synnefo.logic import backend, utils
log = getLogger('synnefo.api.servers')
rapi = GanetiRapiClient(*settings.GANETI_CLUSTER_INFO)
......@@ -232,7 +231,7 @@ def delete_server(request, server_id):
except VirtualMachine.DoesNotExist:
raise ItemNotFound
server.start_action('DESTROY')
backend.start_action(server, 'DESTROY')
rapi.DeleteInstance(server.backend_id)
return HttpResponse(status=204)
......
var flavors = [], images = [], servers = [], disks = [], cpus = [], ram = [];
var changes_since = 0, deferred = 0, update_request = false, load_request = false, pending_actions = [];
var API_URL = "/api/v1.1redux";
function ISODateString(d){
//return a date in an ISO 8601 format using UTC.
......@@ -416,6 +417,39 @@ function updateActions() {
}
}
//create server action
function create_vm(machineName, imageRef, flavorRef){
var payload = {
"server": {
"name": machineName,
"imageRef": imageRef,
"flavorRef" : flavorRef,
"metadata" : {
"My Server Name" : machineName
},
}
};
$.ajax({
url: "/api/v1.0/servers",
type: "POST",
dataType: "json",
data: JSON.stringify(payload),
timeout: TIMEOUT,
error: function(jqXHR, textStatus, errorThrown) {
ajax_error(jqXHR.status);
},
success: function(data, textStatus, jqXHR) {
if ( jqXHR.status == '202') {
ajax_success("CREATE_VM_SUCCESS", data.server.adminPass);
} else {
ajax_error(jqXHR.status);
}
}
});
}
// reboot action
function reboot(serverIDs){
if (!serverIDs.length){
......@@ -429,7 +463,7 @@ function reboot(serverIDs){
var serverID = serverIDs.pop();
$.ajax({
url: '/api/v1.0/servers/' + serverID + '/action',
url: API_URL + '/servers/' + serverID + '/action',
type: "POST",
dataType: "json",
data: JSON.stringify(payload),
......@@ -468,7 +502,7 @@ function shutdown(serverIDs) {
var serverID = serverIDs.pop()
$.ajax({
url: '/api/v1.0/servers/' + serverID + '/action',
url: API_URL + '/servers/' + serverID + '/action',
type: "POST",
dataType: "json",
data: JSON.stringify(payload),
......@@ -505,7 +539,7 @@ function destroy(serverIDs) {
serverID = serverIDs.pop()
$.ajax({
url: '/api/v1.0/servers/' + serverID,
url: API_URL + '/servers/' + serverID,
type: "DELETE",
dataType: "json",
data: JSON.stringify(payload),
......@@ -544,7 +578,7 @@ function start(serverIDs){
var serverID = serverIDs.pop()
$.ajax({
url: '/api/v1.0/servers/' + serverID + '/action',
url: API_URL + '/servers/' + serverID + '/action',
type: "POST",
dataType: "json",
data: JSON.stringify(payload),
......
......@@ -423,35 +423,10 @@ $("#start").click(function(){
var imageRef = $('input[type=radio][name=image-id]:checked')[0].id.replace('img-radio-','');
var flavorRef = identify_flavor($("#cpu-indicator")[0].value, $("#storage-indicator")[0].value, $("#ram-indicator")[0].value);
var machineName = $('input[name=machine_name]')[0].value;
var payload = {
"server": {
"name": machineName,
"imageRef": imageRef,
"flavorRef" : flavorRef,
"metadata" : {
"My Server Name" : machineName
},
}
};
create_vm(machineName, imageRef, flavorRef);
$('a#create').data('overlay').close();
$.ajax({
url: "/api/v1.0/servers",
type: "POST",
dataType: "json",
data: JSON.stringify(payload),
timeout: TIMEOUT,
error: function(jqXHR, textStatus, errorThrown) {
ajax_error(jqXHR.status);
},
success: function(data, textStatus, jqXHR) {
if ( jqXHR.status == '202') {
ajax_success("CREATE_VM_SUCCESS", data.server.adminPass);
} else {
ajax_error(jqXHR.status);
}
}
});
$("#emptymachineslist").hide();
try{console.warn('creating ' + $("input[name=machine_name]")[0].value)} catch(err){}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment