On Tue, 2014-05-20 at 23:27 +0800, shaohef(a)linux.vnet.ibm.com wrote:
From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
Add a set ticket API in UI.
set a ticket for a VM before connect it.
also set a cookie to store this ticket.
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
Signed-off-by: Zhou Zheng Sheng <zhshzhou(a)linux.vnet.ibm.com>
---
ui/js/src/kimchi.api.js | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)
diff --git a/ui/js/src/kimchi.api.js b/ui/js/src/kimchi.api.js
index 7d85fdf..1a34b3b 100644
--- a/ui/js/src/kimchi.api.js
+++ b/ui/js/src/kimchi.api.js
@@ -311,6 +311,19 @@ var kimchi = {
});
},
+ setTicketVM: function(vm, data, suc, err, sync) {
+ kimchi.requestJSON({
+ url : kimchi.url + 'vms/' + encodeURIComponent(vm) +
'/setticket',
+ type : 'POST',
+ contentType : 'application/json',
+ dataType : 'json',
+ async : !sync,
+ data : JSON.stringify(data || {}),
+ success : suc,
+ error : err
+ });
+ },
+
vncToVM : function(vm) {
kimchi.requestJSON({
url : '/config',
@@ -318,16 +331,25 @@ var kimchi = {
dataType : 'json'
}).done(function(data, textStatus, xhr) {
proxy_port = data['display_proxy_port'];
+ var ticket;
+ kimchi.setTicketVM(vm, function(data) {
+ }, function(){
+ kimchi.message.error.code('KCHAPI6002E');
+ }, true);
kimchi.requestJSON({
url : "/vms/" + encodeURIComponent(vm) +
"/connect",
type : "POST",
dataType : "json"
- }).done(function() {
+ }).done(function(data, textStatus, xhr) {
+ ticket = data['ticket'];
+ alert(ticket)
url = 'https://' + location.hostname + ':' +
proxy_port;
url += "/console.html?url=vnc_auto.html&port=" +
proxy_port;
url += "&path=?token=" + encodeURIComponent(vm);
url += "&kimchi=" + location.port;
url += '&encrypt=1';
+ kimchi.cookie.remove("ticketVM");
+ ticket != null && kimchi.cookie.set("ticketVM",
ticket, 100);
window.open(url);
});
}).error(function() {
@@ -342,17 +364,26 @@ var kimchi = {
dataType : 'json'
}).done(function(data, textStatus, xhr) {
proxy_port = data['display_proxy_port'];
+ var ticket;
+ kimchi.setTicketVM(vm, function(data) {
+ }, function(){
+ kimchi.message.error.code('KCHAPI6002E');
+ }, true);
kimchi.requestJSON({
url : "/vms/" + encodeURIComponent(vm) +
"/connect",
type : "POST",
dataType : "json"
}).done(function(data, textStatus, xhr) {
+ ticket = data['ticket'];
+ alert(ticket)
url = 'https://' + location.hostname + ':' +
proxy_port;
url += "/console.html?url=spice.html&port=" + proxy_port;
url += "&listen=" + location.hostname;
url += "&token=" + encodeURIComponent(vm);
url += "&kimchi=" + location.port;
url += '&encrypt=1';
+ kimchi.cookie.remove("ticketVM");
+ ticket != null && kimchi.cookie.set("ticketVM",
ticket, 100);
I had to change this a bit to get it to work for me:
+ if (ticket != null) kimchi.cookie.set("ticketVM",
ticket, 100);
After that, though, I could easily copy/paste in the password and the
VNC console came up. Very cool!
window.open(url);
});
}).error(function() {
Regards,
- Christy