Commit 6852c1d9 authored by Thomas Lechauve's avatar Thomas Lechauve

Upgrade fake server, store in sessionStorage

Large upgrade of the fake server. You can now create instance and it
will be store in sessionStorage.
parent 5745da92
...@@ -129,28 +129,17 @@ $.vifib.mobile = { ...@@ -129,28 +129,17 @@ $.vifib.mobile = {
$.vifib.changepage($(page)); $.vifib.changepage($(page));
$("#instancerequest").submit(function () { $("#instancerequest").submit(function () {
var data = { var data = {
"status": "started", "status": "start_requested",
"slave": false, "slave": false,
"software_release": "http://example.com/example.cfg",
"software_type": "type_provided_by_the_software", "software_type": "type_provided_by_the_software",
"parameter": { };
"Custom1": "one string",
"Custom2": "one float",
"Custom3": [
"abc",
"def"
]
},
"sla": {
"computer_id": "COMP-0"
}
};
$.extend(data, $(this).serializeObject()); $.extend(data, $(this).serializeObject());
$(this).slapos('instanceRequest', { $(this).slapos('instanceRequest', {
data: data, data: data,
success: function (response) { success: function (response) {
$.url.redirect('/dashboard/instance/list'); $.url.redirect('/dashboard/instance/list');
} },
statusCode: $.extend(false, $.vifib.statuscode, {})
}); });
return false; return false;
}); });
......
...@@ -162,7 +162,7 @@ $.vifib.panel = { ...@@ -162,7 +162,7 @@ $.vifib.panel = {
'</ul>' + '</ul>' +
'</article>', '</article>',
rowinstance: rowinstance:
'<a href="{{ insturl }}">{{ instance_id }}</a>', '<a href="{{ insturl }}">{{ title }}</a>',
computer: computer:
'<article>' + '<article>' +
'<h2>{{ computer_id }}</h2>' + '<h2>{{ computer_id }}</h2>' +
......
var comp = { /* Tools to store js object in sessionStorage */
computer_id: "COMP-0", var storejs = {
software: [{software_release: "http://example.com/example.cfg",status: "install"}], add: function (key, js) {
partition: [ window.sessionStorage.setItem(key, JSON.stringify(js));
{title: "slapart1", },
instance_id: "foo", get: function (key) {
status: "start", return JSON.parse(window.sessionStorage.getItem(key));
software_release: "http://example.com/example.cfg"}, },
{title: "slapart2", extend: function (key, object) {
instance_id: "bar", var data = storejs.get(key);
status: "stop", $.extend(data, object);
software_release: "http://example.com/example.cfg"} storejs.add(key, data);
] }
}; }
var inst ={ /*************
title: "INST-1", * RESOURCES
status: "stop_requested", *************/
software_release: "http://example.com/example.cfg", // INSTANCE
software_type: "type_provided_by_the_software", storejs.add('instances', {
slave: "False", Kvm: {
connection: [{ status: "start_requested",
key: "foo", connection: {},
key: "bar"}],
parameter: {
Custom1: "one string",
Custom2: "one float",
Custom3: ["abc", "def"]},
sla: {computer_id: "COMP-0"},
children_id_list: ["subinstance1", "subinstance2"],
partition: { partition: {
public_ip: ["::1", "91.121.63.94"], public_ip: [],
private_ip: ["127.0.0.1"], tap_interface: "",
tap_interface: "tap2"} private_ip: []
}; },
slave: false,
var soft = { children_list: [],
title: "Kvm",
software_type: "Virtual machine",
parameter: {
Custom1: "one string",
Custom2: "one float",
Custom3: "[u'abc', u'def']"
},
software_release: "http://example.com/example.cfg",
sla: {
computer_id: "COMP-0"
}
}
});
// SOFTWARE
storejs.add('softwares', {
Kvm: {
name: 'Kvm', name: 'Kvm',
image_url: 'http://www.linux-kvm.org/wiki/skins/kvm/kvmbanner-logo2.png', image_url: 'http://www.linux-kvm.org/wiki/skins/kvm/kvmbanner-logo2.png',
thumb_url: 'http://www.system-linux.eu/public/images/kvm-logo.png', thumb_url: 'http://www.system-linux.eu/public/images/kvm-logo.png',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.', description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.',
price: '1', price: '1',
}; },
Html5as : {
var html5 = { name: 'Html5as',
name: 'Html5 AS',
image_url: 'http://7.mshcdn.com/wp-content/uploads/2011/01/html5-logo-1.jpg', image_url: 'http://7.mshcdn.com/wp-content/uploads/2011/01/html5-logo-1.jpg',
thumb_url: 'http://www.w3.org/html/logo/downloads/HTML5_Badge_512.png', thumb_url: 'http://www.w3.org/html/logo/downloads/HTML5_Badge_512.png',
description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.', description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vitae metus a est convallis pretium. Pellentesque habitant morbi tristique senectus.',
price: '1337', price: '1337'
}; }
});
var software_list = { // Resources lists
storejs.add('software_list', {
list: [ list: [
'/fake/software_info/kvm', '/fake/software_info/Kvm',
'/fake/software_info/html5', '/fake/software_info/Html5as',
] ]
}; });
var instance_list = {
list: [
'/fake/instance_info/kvm',
'/fake/instance_info/kvm',
]
};
var computer_list = {
list: [
'/fake/computer_info/comp'
]
};
var fakeserver = sinon.fakeServer.create(); var fakeserver = sinon.fakeServer.create();
// Get instances list /*********************
fakeserver.respondWith('GET', '/fake/instance', [ * RESPONSE
200, {'Content-Type': 'application/json'}, JSON.stringify(instance_list) *********************/
]);
// ******* INSTANCE
var instance_list = function () {
var response = {list: []};
$.each(storejs.get('instances'), function (i, e) {
response.list.push('/fake/instance_info/' + e.title)
});
return response;
};
// list
fakeserver.respondWith('GET', '/fake/instance', function (xhr) {
var response = {list: []};
$.each(storejs.get('instances'), function (i, e) {
response.list.push('/fake/instance_info/' + e.title)
});
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(response))
});
// Get instance info // Get instance info
fakeserver.respondWith("GET", '/fake/instance_info/kvm', [ fakeserver.respondWith("GET", /\/fake\/instance_info\/(.*)/, function (xhr, instid) {
200, {"Content-Type":"application/json; charset=utf-8"}, JSON.stringify(inst) var instances = storejs.get('instances');
]); if (instances.hasOwnProperty(instid)) {
xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(instances[instid]));
} else {
xhr.respond(404, { 'Content-Type': 'application/json'}, 'Not found');
}
});
// Request instance
fakeserver.respondWith("POST", '/fake/instance', function (xhr) {
var instances = storejs.get('instances'),
inst = JSON.parse(xhr.requestBody),
iadd = {},
ilist = instance_list();
if (instances.hasOwnProperty(inst.title) === false) {
iadd[inst.title] = inst;
storejs.extend('instances', iadd);
}
xhr.respond(201, {'Content-Type': 'application/json'}, JSON.stringify({
title: inst.title,
status: inst.status
}));
});
//********** SOFTWARE
// Get softwares list // Get softwares list
fakeserver.respondWith('GET', '/fake/software', [ fakeserver.respondWith('GET', '/fake/software', [
200, {'Content-Type': 'application/json'}, JSON.stringify(software_list) 200, {'Content-Type': 'application/json'}, JSON.stringify(storejs.get('software_list'))
]); ]);
// Get software info // Get software info
fakeserver.respondWith('GET', '/fake/software_info/kvm', [ fakeserver.respondWith("GET", /\/fake\/software_info\/(.*)/, function (xhr, softid) {
200, {'Content-Type': 'application/json'}, JSON.stringify(soft) var softwares = storejs.get('softwares');
]); if (softwares.hasOwnProperty(softid)) {
fakeserver.respondWith('GET', '/fake/software_info/html5', [ xhr.respond(200, {'Content-Type': 'application/json'}, JSON.stringify(softwares[softid]));
200, {'Content-Type': 'application/json'}, JSON.stringify(html5) } else {
]); xhr.respond(404, { 'Content-Type': 'application/json'}, 'Not found');
fakeserver.respondWith('GET', '/fake/software_info/nas', [ }
404, {'Content-Type': 'application/json'}, '' });
]);
// Get computers list
fakeserver.respondWith('GET', '/fake/computer', [
200, {'Content-Type': 'application/json'}, JSON.stringify(computer_list)
]);
// Get computer info
fakeserver.respondWith('GET', '/fake/computer_info/comp', [
200, {'Content-Type': 'application/json'}, JSON.stringify(comp)
]);
var tmp = $.ajax; var tmp = $.ajax;
$.ajax = function(url, options){ $.ajax = function(url, options){
......
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