Skip to content

Commit 0eb73e9

Browse files
committed
Update VPC tier dashboard
- Remove 'Port forwarders' -- Getting IPs by PF is not supported by API - Split Public + Internal LB into separate items - Use API response 'count' for count number, instead of array '.length' to fix issues with larger results
1 parent ea440f2 commit 0eb73e9

2 files changed

Lines changed: 126 additions & 118 deletions

File tree

‎ui/modules/vpc/vpc.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
$total.find('span').html(dashboardItem.totalMultiLine);
169169
$total.addClass('multiline');
170170
} else {
171-
$total.find('span').html(dashboardItem.total);
171+
$total.find('span').html(dashboardItem.total ? dashboardItem.total : 0);
172172
}
173173

174174
$dashboardItem.append($total, $name);
@@ -183,7 +183,7 @@
183183
var $section = $('<div>');
184184

185185
if ($.isFunction(section)) {
186-
section = cloudStack.vpc.sections[id]()
186+
section = cloudStack.vpc.sections[id]();
187187
}
188188

189189
if (section.listView) {

‎ui/scripts/vpc.js‎

Lines changed: 124 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@
341341
},
342342

343343
tierStaticNATs: function() {
344-
return cloudStack.vpc.ipAddresses.listView();
344+
return cloudStack.vpc.staticNatIpAddresses.listView();
345345
},
346346

347347
// Internal load balancers
@@ -1185,7 +1185,7 @@
11851185
ipAddresses: {
11861186
listView: function() {
11871187
var listView = $.extend(true, {}, cloudStack.sections.network.sections.ipAddresses);
1188-
1188+
11891189
listView.listView.fields = {
11901190
ipaddress: listView.listView.fields.ipaddress,
11911191
zonename: listView.listView.fields.zonename,
@@ -1196,6 +1196,35 @@
11961196
return listView;
11971197
}
11981198
},
1199+
staticNatIpAddresses: {
1200+
listView: function() {
1201+
var listView = $.extend(true, {}, cloudStack.sections.network.sections.ipAddresses);
1202+
1203+
listView.listView.fields = {
1204+
ipaddress: listView.listView.fields.ipaddress,
1205+
zonename: listView.listView.fields.zonename,
1206+
associatednetworkname: { label: 'label.network.name' },
1207+
state: listView.listView.fields.state
1208+
};
1209+
1210+
listView.listView.dataProvider = function(args) {
1211+
$.ajax({
1212+
url: createURL('listPublicIpAddresses'),
1213+
data: { networkid: args.context.networks[0].id, isstaticnat: true },
1214+
success: function(json) {
1215+
args.response.success({
1216+
data: json.listpublicipaddressesresponse.publicipaddress
1217+
});
1218+
},
1219+
error: function(json) {
1220+
args.response.error(parseXMLHttpResponse(json));
1221+
}
1222+
});
1223+
};
1224+
1225+
return listView;
1226+
}
1227+
},
11991228
acl: {
12001229
multiEdit: aclMultiEdit,
12011230

@@ -3171,29 +3200,16 @@
31713200
async: true,
31723201
success: function(json) {
31733202
var networks = json.listnetworksresponse.network;
3174-
var loadBalancers, networkACLLists, publicIpAddresses, privateGateways, vpnGateways, portForwardingRules;
3203+
var networkACLLists, publicIpAddresses, privateGateways, vpnGateways;
31753204
var error = false;
31763205

3177-
// Get load balancers
3178-
$.ajax({
3179-
url: createURL('listLoadBalancers'),
3180-
data: { vpcid: args.context.vpc[0].id },
3181-
success: function(json) {
3182-
loadBalancers = json.listloadbalancerssresponse.loadbalancer ?
3183-
json.listloadbalancerssresponse.loadbalancer : [];
3184-
},
3185-
error: function(json) {
3186-
error = true;
3187-
}
3188-
});
3189-
31903206
// Get network ACL lists
31913207
$.ajax({
31923208
url: createURL('listNetworkACLLists'),
31933209
data: { 'vpc_id': args.context.vpc[0].id },
3210+
async: false,
31943211
success: function(json) {
3195-
networkACLLists = json.listnetworkacllistsresponse.networkacllist ?
3196-
json.listnetworkacllistsresponse.networkacllist : [];
3212+
networkACLLists = json.listnetworkacllistsresponse;
31973213
},
31983214
error: function(json) {
31993215
error = true;
@@ -3203,23 +3219,10 @@
32033219
// Get public IPs
32043220
$.ajax({
32053221
url: createURL('listPublicIpAddresses'),
3222+
async: false,
32063223
data: { 'vpcid': args.context.vpc[0].id },
32073224
success: function(json) {
3208-
publicIpAddresses = json.listpublicipaddressesresponse.publicipaddress ?
3209-
json.listpublicipaddressesresponse.publicipaddress : [];
3210-
},
3211-
error: function(json) {
3212-
error = true;
3213-
}
3214-
});
3215-
3216-
// Get port forwarding rules
3217-
$.ajax({
3218-
url: createURL('listPortForwardingRules'),
3219-
data: { 'vpcid': args.context.vpc[0].id },
3220-
success: function(json) {
3221-
portForwardingRules = json.listportforwardingrulesresponse.portforwardingrule ?
3222-
json.listportforwardingrulesresponse.portforwardingrule : [];
3225+
publicIpAddresses = json.listpublicipaddressesresponse;
32233226
},
32243227
error: function(json) {
32253228
error = true;
@@ -3229,10 +3232,10 @@
32293232
// Get private gateways
32303233
$.ajax({
32313234
url: createURL('listPrivateGateways'),
3235+
async: false,
32323236
data: { 'vpcid': args.context.vpc[0].id },
32333237
success: function(json) {
3234-
privateGateways = json.listprivategatewaysresponse.privategateway ?
3235-
json.listprivategatewaysresponse.privategateway : [];
3238+
privateGateways = json.listprivategatewaysresponse;
32363239
},
32373240
error: function(json) {
32383241
error = true;
@@ -3242,106 +3245,111 @@
32423245
// Get VPN gateways
32433246
$.ajax({
32443247
url: createURL('listVpnGateways'),
3248+
async: false,
32453249
data: { 'vpcid': args.context.vpc[0].id },
32463250
success: function(json) {
3247-
vpnGateways = json.listvpngatewaysresponse.vpngateway ?
3248-
json.listvpngatewaysresponse.vpngateway : [];
3251+
vpnGateways = json.listvpngatewaysresponse;
32493252
},
32503253
error: function(json) {
32513254
error = true;
32523255
}
32533256
});
32543257

3255-
var dataTimer = setInterval(function() {
3256-
var complete = loadBalancers && networkACLLists && publicIpAddresses && privateGateways && vpnGateways;
3257-
3258-
if (complete) {
3259-
clearInterval(dataTimer);
3258+
args.response.success({
3259+
routerDashboard: [
3260+
{
3261+
id: 'privateGateways',
3262+
name: 'Private gateways',
3263+
total: privateGateways.count
3264+
},
3265+
{
3266+
id: 'publicIPs',
3267+
name: 'Public IP addresses',
3268+
total: publicIpAddresses.count
3269+
},
3270+
{
3271+
id: 'siteToSiteVPNs',
3272+
name: 'Site-to-site VPNs',
3273+
total: vpnGateways.count
3274+
},
3275+
{
3276+
id: 'networkACLLists',
3277+
name: 'Network ACL lists',
3278+
total: networkACLLists.count
3279+
}
3280+
],
3281+
tiers: $(networks).map(function(index, tier) {
3282+
var internalLoadBalancers, publicLoadBalancers, virtualMachines, staticNatIps;
32603283

3261-
if(networks != null && networks.length > 0) {
3262-
for(var i = 0; i < networks.length; i++) {
3263-
$.ajax({
3264-
url: createURL("listVirtualMachines"),
3265-
dataType: "json",
3266-
data: {
3267-
networkid: networks[i].id,
3268-
listAll: true
3269-
},
3270-
async: false,
3271-
success: function(json) {
3272-
networks[i].virtualMachines = json.listvirtualmachinesresponse.virtualmachine;
3273-
}
3274-
});
3284+
// Get internal load balancers
3285+
$.ajax({
3286+
url: createURL('listLoadBalancers'),
3287+
async: false,
3288+
data: { networkid: tier.id },
3289+
success: function(json) {
3290+
internalLoadBalancers = json.listloadbalancerssresponse;
3291+
},
3292+
error: function(json) {
3293+
error = true;
32753294
}
3276-
}
3277-
args.response.success({
3278-
routerDashboard: [
3295+
});
3296+
3297+
// Get VMs
3298+
$.ajax({
3299+
url: createURL('listVirtualMachines'),
3300+
async: false,
3301+
data: { networkid: tier.id },
3302+
success: function(json) {
3303+
virtualMachines = json.listvirtualmachinesresponse;
3304+
},
3305+
error: function(json) {
3306+
error = true;
3307+
}
3308+
});
3309+
3310+
// Get static NAT IPs
3311+
$.ajax({
3312+
url: createURL('listPublicIpAddresses'),
3313+
async: false,
3314+
data: { networkid: tier.id, isstaticnat: true },
3315+
success: function(json) {
3316+
staticNatIps = json.listpublicipaddressesresponse;
3317+
},
3318+
error: function(json) {
3319+
error = true;
3320+
}
3321+
});
3322+
3323+
return $.extend(tier, {
3324+
_dashboardItems: [
32793325
{
3280-
id: 'privateGateways',
3281-
name: 'Private gateways',
3282-
total: privateGateways.length
3326+
id: 'tierLoadBalancers',
3327+
name: 'Internal LB',
3328+
total: internalLoadBalancers.count
32833329
},
32843330
{
3285-
id: 'publicIPs',
3286-
name: 'Public IP addresses',
3287-
total: publicIpAddresses.length
3331+
id: 'tierLoadBalancers',
3332+
name: 'Public LB',
3333+
total: 0
32883334
},
32893335
{
3290-
id: 'siteToSiteVPNs',
3291-
name: 'Site-to-site VPNs',
3292-
total: vpnGateways.length
3336+
id: 'tierStaticNATs',
3337+
name: 'Static NATs',
3338+
total: staticNatIps.count
32933339
},
32943340
{
3295-
id: 'networkACLLists',
3296-
name: 'Network ACL lists',
3297-
total: networkACLLists.length
3341+
id: 'tierVMs',
3342+
name: 'Virtual Machines',
3343+
total: virtualMachines.count
32983344
}
3299-
],
3300-
tiers: $(networks).map(function(index, tier) {
3301-
var internalLoadBalancers = $.grep(loadBalancers, function(lb) {
3302-
return lb.networkid == tier.id;
3303-
});
3304-
3305-
return $.extend(tier, {
3306-
_dashboardItems: [
3307-
{
3308-
id: 'tierLoadBalancers',
3309-
name: 'Load balancers',
3310-
totalMultiLine: internalLoadBalancers.length + ' Internal<br/>0 Public'
3311-
},
3312-
{
3313-
id: 'tierPortForwarders',
3314-
name: 'Port forwarders',
3315-
total: $.grep(publicIpAddresses, function(ip) {
3316-
return $.grep(
3317-
portForwardingRules,
3318-
function(pf) {
3319-
return pf.ipaddressid == ip.id;
3320-
}
3321-
).length ? true : false;
3322-
}).length
3323-
},
3324-
{
3325-
id: 'tierStaticNATs',
3326-
name: 'Static NATs',
3327-
total: $.grep(publicIpAddresses, function(ip) {
3328-
return ip.associatednetworkid == tier.id && ip.isstaticnat;
3329-
}).length
3330-
},
3331-
{
3332-
id: 'tierVMs',
3333-
name: 'Virtual Machines',
3334-
total: $.isArray(tier.virtualMachines) ? tier.virtualMachines.length : 0
3335-
}
3336-
]
3337-
});
3338-
})
3345+
]
33393346
});
3340-
} else if (error) {
3341-
clearInterval(dataTimer);
3342-
cloudStack.dialog.notice({ message: 'Error loading dashboard data.' });
3343-
}
3344-
}, 500);
3347+
})
3348+
});
3349+
3350+
if (error) {
3351+
cloudStack.dialog.notice({ message: 'Error loading dashboard data.' });
3352+
}
33453353
}
33463354
});
33473355
}

0 commit comments

Comments
 (0)