Commit 81426833 authored by Dimitris Moraitis's avatar Dimitris Moraitis
Browse files

api 1.1 compatibility improvements - Refs #311

parent 4bb72703
......@@ -103,7 +103,7 @@ def get_request_dict(request):
"""Returns data sent by the client as a python dict."""
data = request.raw_post_data
if request.META.get('CONTENT_TYPE') == 'application/json':
if request.META.get('CONTENT_TYPE').startswith('application/json'):
try:
return json.loads(data)
except ValueError:
......
......@@ -248,7 +248,7 @@ function update_vms(interval) {
if (jqXHR.status == 200 || jqXHR.status == 203) {
try {
servers = data.servers;
servers = data.servers.values;
} catch(err) { ajax_error('400', undefined, 'Update VMs', jqXHR.responseText);}
update_machines_view(data);
} else if (jqXHR.status != 304){
......@@ -470,11 +470,12 @@ function create_vm(machineName, imageRef, flavorRef){
}
}
};
var uri = API_URL + '/servers';
$.ajax({
url: API_URL + '/servers',
url: uri,
type: "POST",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(payload),
timeout: TIMEOUT,
......@@ -505,7 +506,8 @@ function reboot(serverIDs){
$.ajax({
url: API_URL + '/servers/' + serverID + '/action',
type: "POST",
type: "POST",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(payload),
timeout: TIMEOUT,
......@@ -545,6 +547,7 @@ function shutdown(serverIDs) {
$.ajax({
url: API_URL + '/servers/' + serverID + '/action',
type: "POST",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(payload),
timeout: TIMEOUT,
......@@ -582,6 +585,7 @@ function destroy(serverIDs) {
$.ajax({
url: API_URL + '/servers/' + serverID,
type: "DELETE",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(payload),
timeout: TIMEOUT,
......@@ -621,6 +625,7 @@ function start(serverIDs){
$.ajax({
url: API_URL + '/servers/' + serverID + '/action',
type: "POST",
contentType: "application/json",
dataType: "json",
data: JSON.stringify(payload),
timeout: TIMEOUT,
......
......@@ -174,7 +174,7 @@ function update_machines_view(data){
new ones to the list
*/
tableData = vmTable.fnGetData();
$.each(data.servers, function(i,server){
$.each(data.servers.values, function(i,server){
current = -1;
// check server status to select the appropriate OS icon
osTag = image_tags[server.imageRef]
......@@ -211,7 +211,7 @@ function update_machines_view(data){
imgStr = "<img class=list-logo src=" + imgSrc + " title=" + osTag + " height=16 width=16 />";
tableData[current][1] = "<span class=imagetag>" + osTag + "</span>" + imgStr;
tableData[current][2] = "<a class=name><span class=name>" + server.name + "</span></a>";
tableData[current][3] = "<a class=ip><span class=public>"+ server.addresses.public.ip.addr + "</span></a>";
tableData[current][3] = "<a class=ip><span class=public>"+ server.addresses.values[0].values[0].addr + "</span></a>";
//tableData[current][4] = "group"; //TODO
tableData[current][5] = "<span class=status>" + STATUS_MESSAGES[server.status] + "</span>";
vmTable.fnUpdate(tableData[current],current);
......@@ -232,7 +232,7 @@ function update_machines_view(data){
"<span class=imagetag>" + osTag + "</span><img class=list-logo src=static/os_logos/" + osIcon +
" title=" + osTag + " height=16 width=16>",
"<a class=name><span class=name>" + server.name + "</span></a>",
"<a class=ip><span class=public>"+ server.addresses.public.ip.addr + "</span></a>",
"<a class=ip><span class=public>"+ server.addresses.values[0].values[0].addr + "</span></a>",
"group",
"<span class=status>" + STATUS_MESSAGES[server.status] + "</span>"
]);
......
......@@ -162,8 +162,7 @@ function update_machines_view(data){
Go through the servers in the input data. Update existing entries, add
new ones to the list
*/
$.each(data.servers, function(i,server){
$.each(data.servers.values, function(i,server){
existing = $('#' + server.id);
// if multiple machines exist in the DOM, delete all but one
......@@ -210,14 +209,14 @@ function update_machines_view(data){
}
existing.find("a.name span.name").text(server.name);
existing.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));
existing.find("a.ip span.public").text(String(server.addresses.values[0].values[0].addr).replace(',',' '));
} else if (server.status != 'DELETED') {
// If it does not exist and it's not deleted, we should create it
var machine = $("#machine-template").clone().attr("id", server.id).fadeIn("slow");
machine.find("a.name span.name").text(server.name);
machine.find("img.logo").attr("src","static/machines/"+image_tags[server.imageRef]+'.png');
machine.find("span.imagetag").text(image_tags[server.imageRef]);
machine.find("a.ip span.public").text(String(server.addresses.public.ip.addr).replace(',',' '));
machine.find("a.ip span.public").text(String(server.addresses.values[0].values[0].addr).replace(',',' '));
machine.find(".status").text(STATUS_MESSAGES[server.status]);
if (['BUILD', 'ACTIVE', 'REBOOT'].indexOf(server.status) >= 0){
machine.appendTo(".running");
......
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