Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
add change sg to eni tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Genki Sugawara committed Mar 25, 2012
1 parent f9134f2 commit 15b90db
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ec2ui/content/ec2ui/controller.js
Expand Up @@ -2885,5 +2885,24 @@ var ec2ui_controller = {
if (objResponse.callback) {
objResponse.callback();
}
},

modifyNetworkInterfaceAttributes : function (networkInterfaceId, attributes, callback) {
var params = [];
params.push(["NetworkInterfaceId", networkInterfaceId]);

for (var i = 0; i < attributes.length; i++) {
var name = attributes[i][0];
var value = attributes[i][1];
params.push([name, value]);
}

ec2_httpclient.queryEC2("ModifyNetworkInterfaceAttribute", params, this, true, "onModifyNetworkInterfaceAttributes", callback);
},

onModifyNetworkInterfaceAttributes : function (objResponse) {
if (objResponse.callback) {
objResponse.callback();
}
}
};
65 changes: 65 additions & 0 deletions ec2ui/content/ec2ui/dialog_eni_security_group.js
@@ -0,0 +1,65 @@
var ec2_ENIDialogSecurityGroup = {
securityGroupDialogOnLoad: function() {
var eni = window.arguments[0];
var groups = window.arguments[1];

function isIncludedInGroupList(name) {
var groupList = eni.groupList;

for (var i = 0; i < groupList.length; i++) {
if (name == groupList[i]) {
return true;
}
}

return false;
}

var label = document.getElementById('eni-security-group-dialog-security-group-label');
label.value = eni.networkInterfaceId + ' (' + eni.description + ') Security Group';

var list = document.getElementById('eni-security-group-dialog-security-group-list');
var groupArray = [];

for (var name in groups) {
groupArray.push(name);
}

groupArray.sort();

for (var i = 0; i < groupArray.length; i++) {
var name = groupArray[i];
var label = name;

if (isIncludedInGroupList(name)) {
label = label + ' (*)';
}

list.appendItem(label, name);
}

return true;
},

securityGroupDialogDoOK: function() {
var list = document.getElementById('eni-security-group-dialog-security-group-list');

if (list.selectedItems.length == 0) {
alert('Please choose one or more security groups.');
return false;
}

var newGroups = [];

for (var i = 0; i < list.selectedItems.length; i++) {
var selected = list.selectedItems[i];
newGroups.push(selected.value);
}

var returnValue = window.arguments[2];
returnValue.accepted = true;
returnValue.newGroups = newGroups;

return true;
}
};
18 changes: 18 additions & 0 deletions ec2ui/content/ec2ui/dialog_eni_security_group.xul
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!DOCTYPE window SYSTEM "chrome://iamfox/locale/main.dtd">

<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Security Group"
buttons="accept,cancel"
ondialogaccept="return ec2_ENIDialogSecurityGroup.securityGroupDialogDoOK();"
ondialogcancel="return true;"
onload="ec2_ENIDialogSecurityGroup.securityGroupDialogOnLoad();"
width="300" height="200">

<script type="application/x-javascript" src="chrome://ec2ui/content/dialog_eni_security_group.js" />

<label id="eni-security-group-dialog-security-group-label" control="eni-security-group-dialog-security-group-list" />
<listbox id="eni-security-group-dialog-security-group-list" seltype="multiple" flex="1" />

</dialog>
2 changes: 2 additions & 0 deletions ec2ui/content/ec2ui/eni_tab_overlay.xul
Expand Up @@ -9,6 +9,8 @@
<caption label="Network Interfaces" />
<popupset>
<menupopup id="ec2ui.eni.contextmenu">
<menuitem oncommand="ec2ui_ENITreeView.changeSecurityGroup();"
label="Change Security Group" />
<menuitem oncommand="ec2ui_ENITreeView.changeSourceDestCheck();"
label="Change Source/Dest Check" />
<menuitem oncommand="ec2ui_ENITreeView.changeDescription();"
Expand Down
51 changes: 51 additions & 0 deletions ec2ui/content/ec2ui/eniview.js
Expand Up @@ -109,6 +109,57 @@ var ec2ui_ENITreeView = {
});
},

changeSecurityGroup: function() {
var eni = this.getSelectedNetworkInterface();
if (!eni) { return; }

var returnValue = {accepted:false , result:null};
var groups = ec2ui_model.getSecurityGroupNameIds(eni.vpcId);

openDialog('chrome://ec2ui/content/dialog_eni_security_group.xul',
null,
'chrome,centerscreen,modal',
eni,
groups,
returnValue);

if (!returnValue.accepted) {
return;
}

var oldGroups = [];

for (var i = 0; i < eni.groupList.length; i++) {
oldGroups.push(eni.groupList[i]);
}

oldGroups.sort();

var newGroups = returnValue.newGroups;
newGroups.sort();

if (oldGroups.join() == newGroups.join()) {
return;
}

var attributes = [];

for (var i = 0; i < newGroups.length; i++) {
var groupId = groups[newGroups[i]];

if (groupId) {
attributes.push(['SecurityGroupId.' + (i + 1), groupId]);
}
}

var me = this;

ec2ui_session.controller.modifyNetworkInterfaceAttributes(eni.networkInterfaceId, attributes, function() {
me.refresh();
me.selectByNetworkInterfaceId(eni.networkInterfaceId);
});
},

changeSourceDestCheck : function() {
var eni = this.getSelectedNetworkInterface();
if (!eni) { return; }
Expand Down

0 comments on commit 15b90db

Please sign in to comment.