Skip to content

Commit e046364

Browse files
committed
LB/PF/NAT UI: Support secondary IP selection
During selection of a VM for LB/PF/Static NAT, show dropdown to select which secondary IP will apply for the rule being created.
1 parent ed7ebf5 commit e046364

2 files changed

Lines changed: 97 additions & 2 deletions

File tree

‎ui/scripts/network.js‎

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,36 @@
3434

3535
return elemData;
3636
};
37+
38+
var instanceSecondaryIPSubselect = function(args) {
39+
var instance = args.context.instances[0];
40+
var network = args.context.networks[0];
41+
var nic = $.grep(instance.nic, function(nic) {
42+
return nic.networkid = network.id;
43+
})[0]
44+
45+
// Get NIC IPs
46+
$.ajax({
47+
url: createURL('listNics'),
48+
data: {
49+
virtualmachineid: instance.id,
50+
nicId: nic.id
51+
},
52+
success: function(json) {
53+
var nic = json.listnics.nic[0];
54+
var ips = nic.secondaryip ? nic.secondaryip : [];
55+
56+
args.response.success({
57+
data: $(ips).map(function(index, ip) {
58+
return {
59+
id: ip.ipaddress,
60+
description: ip.ipaddress
61+
} ;
62+
})
63+
});
64+
}
65+
})
66+
};
3767

3868
var ipChangeNotice = function() {
3969
cloudStack.dialog.confirm({
@@ -1095,7 +1125,7 @@
10951125
addRow: 'true',
10961126
messages: {
10971127
confirm: function(args) {
1098-
'message.acquire.new.ip';
1128+
return 'message.acquire.new.ip';
10991129
},
11001130
notification: function(args) {
11011131
return 'label.acquire.new.ip';
@@ -1138,7 +1168,7 @@
11381168
virtualmachineid: args.context.instances[0].id
11391169
},
11401170
success: function(json) {
1141-
var ips = json.listnics.nic[0].secondaryip
1171+
var ips = json.listnics.nic ? json.listnics.nic[0].secondaryip : [];
11421172

11431173
args.response.success({
11441174
data: $(ips).map(function(index, ip) {
@@ -1632,6 +1662,7 @@
16321662
listView: $.extend(true, {}, cloudStack.sections.instances, {
16331663
listView: {
16341664
filters: false,
1665+
subselect: instanceSecondaryIPSubselect,
16351666
dataProvider: function(args) {
16361667
var data = {
16371668
page: args.page,
@@ -2374,7 +2405,22 @@
23742405
loadBalancing: {
23752406
listView: $.extend(true, {}, cloudStack.sections.instances, {
23762407
listView: {
2408+
fields: {
2409+
name: { label: 'label.name' },
2410+
displayname: { label: 'label.display.name' },
2411+
zonename: { label: 'label.zone.name' },
2412+
state: {
2413+
label: 'label.state',
2414+
indicator: {
2415+
'Running': 'on',
2416+
'Stopped': 'off',
2417+
'Destroyed': 'off',
2418+
'Error': 'off'
2419+
}
2420+
}
2421+
},
23772422
filters: false,
2423+
subselect: instanceSecondaryIPSubselect,
23782424
dataProvider: function(args) {
23792425
var itemData = $.isArray(args.context.multiRule) && args.context.multiRule[0]['_itemData'] ?
23802426
args.context.multiRule[0]['_itemData'] : [];
@@ -2957,6 +3003,7 @@
29573003
listView: $.extend(true, {}, cloudStack.sections.instances, {
29583004
listView: {
29593005
filters: false,
3006+
subselect: instanceSecondaryIPSubselect,
29603007
dataProvider: function(args) {
29613008
var networkid;
29623009
if('vpc' in args.context)

‎ui/scripts/ui/widgets/multiEdit.js‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,54 @@
468468
// Change action label
469469
$listView.find('th.actions').html(_l('Select'));
470470

471+
// Add sub-select
472+
if (instances.listView.subselect) {
473+
$listView.bind('cloudStack.listView.addRow', function(event, data) {
474+
var $tr = data.$tr;
475+
var $td = $tr.find('td.first');
476+
var $select = $('<div></div>').addClass('subselect').append(
477+
$('<select></select>')
478+
).hide();
479+
var $selectionArea = $tr.find('td:last').find('input');
480+
481+
$td.append($select);
482+
483+
// Show and populate selection
484+
$selectionArea.change(function() {
485+
if ($(this).is(':checked')) {
486+
// Populate data
487+
instances.listView.subselect({
488+
context: $.extend(true, {}, context, {
489+
instances: [$tr.data('json-obj')]
490+
}),
491+
response: {
492+
success: function(args) {
493+
var data = args.data;
494+
495+
if (data.length) {
496+
$(data).map(function(index, item) {
497+
var $option = $('<option>');
498+
499+
$option.attr('value', item.id);
500+
$option.append(item.description);
501+
$option.appendTo($select.find('select'));
502+
});
503+
504+
} else {
505+
$select.hide();
506+
}
507+
}
508+
}
509+
});
510+
$select.show();
511+
} else {
512+
$select.find('option').remove();
513+
$select.hide();
514+
}
515+
});
516+
});
517+
}
518+
471519
var $dataList = $listView.addClass('multi-edit-add-list').dialog({
472520
dialogClass: 'multi-edit-add-list panel',
473521
width: 825,

0 commit comments

Comments
 (0)