Skip to content
Snippets Groups Projects
Commit 40aec768 authored by Wes Felter's avatar Wes Felter
Browse files

UI: Correctly handle switches and ports going away.

Also fixed OVS local port display.
parent be23f35e
No related branches found
No related tags found
No related merge requests found
......@@ -38,7 +38,7 @@ window.HostCollection = Backbone.Collection.extend({
url:hackBase + "/wm/device/",
dataType:"json",
success:function (data) {
console.log("fetched host list: " + data.length);
//console.log("fetched host list: " + data.length);
// console.log(data);
// data is a list of device hashes
var old_ids = self.pluck('id');
......@@ -55,7 +55,7 @@ window.HostCollection = Backbone.Collection.extend({
}
});
// old_ids now holds hosts that no longer exist; remove them
console.log("old_ids" + old_ids);
//console.log("old_ids" + old_ids);
_.each(old_ids, function(h) {
console.log("---removing host " + h);
self.remove({id:h});
......
......@@ -74,9 +74,16 @@ window.Switch = Backbone.Model.extend({
success:function (data) {
//console.log("fetched switch " + self.id + " ports");
//console.log(data[self.id]);
var old_ids = self.ports.pluck('id');
//console.log("old_ids" + old_ids);
// create port models
_.each(data[self.id], function(p) {
// workaround for REST serialization signed/unsigned bug
if(p.portNumber < 0) {p.portNumber = 65536 + p.portNumber};
p.id = self.id+'-'+p.portNumber;
old_ids = _.without(old_ids, p.id);
p.dropped = p.receiveDropped + p.transmitDropped;
p.errors = p.receiveCRCErrors + p.receiveErrors + p.receiveOverrunErrors +
p.receiveFrameErrors + p.transmitErrors;
......@@ -89,6 +96,13 @@ window.Switch = Backbone.Model.extend({
}
//console.log(p);
});
// old_ids now holds ports that no longer exist; remove them
//console.log("old_ids" + old_ids);
_.each(old_ids, function(p) {
console.log("removing port " + p);
self.remove({id:p});
});
}
}),
$.ajax({
......@@ -260,10 +274,21 @@ window.SwitchCollection = Backbone.Collection.extend({
success:function (data) {
//console.log("fetched switch list: " + data.length);
//console.log(data);
_.each(data, function(sw) {self.add({id: sw['dpid'],
inetAddress: sw.inetAddress,
connectedSince: new Date(sw.connectedSince).toLocaleString()})});
}
var old_ids = self.pluck('id');
//console.log("old_ids" + old_ids);
_.each(data, function(sw) {
old_ids = _.without(old_ids, sw['dpid']);
self.add({id: sw['dpid'], inetAddress: sw.inetAddress,
connectedSince: new Date(sw.connectedSince).toLocaleString()})});
// old_ids now holds switches that no longer exist; remove them
//console.log("old_ids" + old_ids);
_.each(old_ids, function(sw) {
console.log("removing switch " + sw);
self.remove({id:sw});
});
},
});
},
......
......@@ -57,6 +57,7 @@ window.SwitchListView = Backbone.View.extend({
initialize:function () {
this.template = _.template(tpl.get('switch-list'));
this.model.bind("change", this.render, this);
this.model.bind("remove", this.render, this);
},
render:function (eventName) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment