You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bf...@apache.org on 2012/11/06 01:07:28 UTC
[5/9] git commit: Add network-level egress UI
Add network-level egress UI
Adds new tab to network section details to add/remove/list
network-level egress rules. This tab only appears for isolated source
NAT networks. It is based on the same format as the firewall rule
edit.
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/c3f1a694
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/c3f1a694
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/c3f1a694
Branch: refs/heads/master
Commit: c3f1a694aec1d7e8deb6f881d9d339f2a015d054
Parents: 58de3c3
Author: Brian Federle <br...@citrix.com>
Authored: Mon Nov 5 15:24:30 2012 -0800
Committer: Brian Federle <br...@citrix.com>
Committed: Mon Nov 5 15:42:11 2012 -0800
----------------------------------------------------------------------
ui/scripts/network.js | 290 +++++++++++++++++++++++---------------------
1 files changed, 151 insertions(+), 139 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c3f1a694/ui/scripts/network.js
----------------------------------------------------------------------
diff --git a/ui/scripts/network.js b/ui/scripts/network.js
index dae4dfb..a7482f8 100644
--- a/ui/scripts/network.js
+++ b/ui/scripts/network.js
@@ -3416,172 +3416,184 @@
},
egressRules: {
title: 'label.egress.rule',
- custom: cloudStack.uiCustom.securityRules({
- noSelect: true,
- noHeaderActionsColumn: true,
- fields: {
- 'protocol': {
- label: 'label.protocol',
- select: function(args) {
- args.$select.change(function() {
- var $inputs = args.$form.find('th, td');
- var $icmpFields = $inputs.filter(function() {
- var name = $(this).attr('rel');
+ custom: function(args) {
+ var context = args.context;
- return $.inArray(name, [
- 'icmptype',
- 'icmpcode'
- ]) > -1;
- });
- var $otherFields = $inputs.filter(function() {
- var name = $(this).attr('rel');
+ return $('<div>').multiEdit({
+ context: context,
+ noSelect: true,
+ noHeaderActionsColumn: true,
+ fields: {
+ 'cidrlist': { edit: true, label: 'label.cidr' },
+ 'protocol': {
+ label: 'label.protocol',
+ select: function(args) {
+ args.$select.change(function() {
+ var $inputs = args.$form.find('th, td');
+ var $icmpFields = $inputs.filter(function() {
+ var name = $(this).attr('rel');
- return name != 'icmptype' &&
- name != 'icmpcode' &&
- name != 'protocol' &&
- name != 'add-rule' &&
- name != 'cidr' &&
- name != 'accountname' &&
- name != 'securitygroup';
- });
+ return $.inArray(name, [
+ 'icmptype',
+ 'icmpcode'
+ ]) > -1;
+ });
+ var $otherFields = $inputs.filter(function() {
+ var name = $(this).attr('rel');
- if ($(this).val() == 'icmp') {
- $icmpFields.show();
- $otherFields.hide();
- } else {
- $icmpFields.hide();
- $otherFields.show();
- }
- });
+ return name != 'cidrlist' &&
+ name != 'icmptype' &&
+ name != 'icmpcode' &&
+ name != 'protocol' &&
+ name != 'add-rule';
+ });
- args.response.success({
- data: [
- { name: 'tcp', description: 'TCP' },
- { name: 'udp', description: 'UDP' },
- { name: 'icmp', description: 'ICMP' }
- ]
- });
+ if ($(this).val() == 'icmp') {
+ $icmpFields.show();
+ $otherFields.hide();
+ } else {
+ $icmpFields.hide();
+ $otherFields.show();
+ }
+ });
+
+ args.response.success({
+ data: [
+ { name: 'tcp', description: 'TCP' },
+ { name: 'udp', description: 'UDP' },
+ { name: 'icmp', description: 'ICMP' }
+ ]
+ });
+ }
+ },
+ 'startport': { edit: true, label: 'label.start.port' },
+ 'endport': { edit: true, label: 'label.end.port' },
+ 'icmptype': { edit: true, label: 'ICMP.type', isHidden: true },
+ 'icmpcode': { edit: true, label: 'ICMP.code', isHidden: true },
+ 'add-rule': {
+ label: 'label.add',
+ addButton: true
}
},
- 'startport': { edit: true, label: 'label.start.port' },
- 'endport': { edit: true, label: 'label.end.port' },
- 'icmptype': { edit: true, label: 'ICMP.type', isHidden: true },
- 'icmpcode': { edit: true, label: 'ICMP.code', isHidden: true },
- 'cidr': { edit: true, label: 'label.cidr', isHidden: true },
- 'accountname': {
- edit: true,
- label: 'label.account.and.security.group',
- isHidden: true,
- range: ['accountname', 'securitygroup']
- },
- 'add-rule': {
+ add: {
label: 'label.add',
- addButton: true
- }
- },
- add: {
- label: 'label.add',
- action: function(args) {
- var data = {
- securitygroupid: args.context.securityGroups[0].id,
- protocol: args.data.protocol,
- domainid: args.context.securityGroups[0].domainid,
- account: args.context.securityGroups[0].account
- };
-
- // TCP / ICMP
- if (args.data.icmptype && args.data.icmpcode) { // ICMP
- $.extend(data, {
- icmptype: args.data.icmptype,
- icmpcode: args.data.icmpcode
- });
- } else { // TCP
- $.extend(data, {
- startport: args.data.startport,
- endport: args.data.endport
- });
- }
-
- // CIDR / account
- if (args.data.cidr) {
- data.cidrlist = args.data.cidr;
- } else {
- data['usersecuritygrouplist[0].account'] = args.data.accountname;
- data['usersecuritygrouplist[0].group'] = args.data.securitygroup;
- }
-
- $.ajax({
- url: createURL('authorizeSecurityGroupEgress'),
- data: data,
- dataType: 'json',
- async: true,
- success: function(data) {
- var jobId = data.authorizesecuritygroupegressresponse.jobid;
+ action: function(args) {
+ var data = {
+ protocol: args.data.protocol,
+ cidrlist: args.data.cidrlist,
+ trafficType: 'Egress'
+ };
- args.response.success({
- _custom: {
- jobId: jobId
- },
- notification: {
- label: 'label.add.egress.rule',
- poll: pollAsyncJobResult
- }
+ if (args.data.icmptype && args.data.icmpcode) { // ICMP
+ $.extend(data, {
+ icmptype: args.data.icmptype,
+ icmpcode: args.data.icmpcode
+ });
+ } else { // TCP/UDP
+ $.extend(data, {
+ startport: args.data.startport,
+ endport: args.data.endport
});
}
- });
- }
- },
- actions: {
- destroy: {
- label: 'label.remove.rule',
- action: function(args) {
+
+ // Get Source NAT IP
+ var sourceNATIP;
+
$.ajax({
- url: createURL('revokeSecurityGroupEgress'),
+ url: createURL('listPublicIpAddresses'),
data: {
- domainid: args.context.securityGroups[0].domainid,
- account: args.context.securityGroups[0].account,
- id: args.context.multiRule[0].id
+ listAll: true,
+ associatednetworkid: args.context.networks[0].id
},
+ async: false,
+ success: function(json) {
+ var ipAddresses = json.listpublicipaddressesresponse.publicipaddress;
+
+ sourceNATIP = $.grep(ipAddresses, function(ipAddress) {
+ return ipAddress.issourcenat;
+ })[0];
+ }
+ });
+
+ data.ipaddressid = sourceNATIP.id;
+
+ $.ajax({
+ url: createURL('createFirewallRule'),
+ data: data,
dataType: 'json',
async: true,
- success: function(data) {
- var jobID = data.revokesecuritygroupegress.jobid;
+ success: function(json) {
+ var jobId = json.createfirewallruleresponse.jobid;
args.response.success({
_custom: {
- jobId: jobID
+ jobId: jobId
},
notification: {
- label: 'label.remove.egress.rule',
+ label: 'label.add.egress.rule',
poll: pollAsyncJobResult
}
});
+ },
+ error: function(json) {
+ args.response.error(parseXMLHttpResponse(json));
}
});
}
- }
- },
- ignoreEmptyFields: true,
- dataProvider: function(args) {
- $.ajax({
- url: createURL('listSecurityGroups'),
- data: {
- id: args.context.securityGroups[0].id
- },
- dataType: 'json',
- async: true,
- success: function(data) {
- args.response.success({
- data: $.map(
- data.listsecuritygroupsresponse.securitygroup[0].egressrule ?
- data.listsecuritygroupsresponse.securitygroup[0].egressrule : [],
- ingressEgressDataMap
- )
- });
+ },
+ actions: {
+ destroy: {
+ label: 'label.remove.rule',
+ action: function(args) {
+ $.ajax({
+ url: createURL('deleteFirewallRule'),
+ data: {
+ id: args.context.multiRule[0].id
+ },
+ dataType: 'json',
+ async: true,
+ success: function(data) {
+ var jobID = data.deletefirewallruleresponse.jobid;
+
+ args.response.success({
+ _custom: {
+ jobId: jobID
+ },
+ notification: {
+ label: 'label.remove.egress.rule',
+ poll: pollAsyncJobResult
+ }
+ });
+ },
+ error: function(json) {
+ args.response.error(parseXMLHttpResponse(json));
+ }
+ });
+ }
}
- });
- }
- })
+ },
+ ignoreEmptyFields: true,
+ dataProvider: function(args) {
+ $.ajax({
+ url: createURL('listFirewallRules'),
+ data: {
+ listAll: true,
+ networkid: args.context.networks[0].id,
+ trafficType: 'Egress'
+ },
+ dataType: 'json',
+ async: true,
+ success: function(json) {
+ var response = json.listfirewallrulesresponse.firewallrule;
+
+ args.response.success({
+ data: response
+ });
+ }
+ });
+ }
+ });
+ }
}
},