Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add private ip func

  • Loading branch information...
commit 8f663498aa7edc01d0c324b4a619b1e39ddd9c1e 1 parent 84a725c
@winebarrel winebarrel authored
View
2  ec2ui/content/ec2ui/client.js
@@ -13,7 +13,7 @@ var ec2_httpclient = {
USER_AGENT : "Elasticfox/1.7-000116",
- API_VERSION : "2012-03-01",
+ API_VERSION : "2012-07-20",
ELB_API_VERSION : "2011-11-15",
VPN_CONFIG_PATH : "http://ec2-downloads.s3.amazonaws.com/",
View
71 ec2ui/content/ec2ui/controller.js
@@ -2991,6 +2991,39 @@ var ec2ui_controller = {
}
},
+ describePrivateIpAddresses : function (eni_id, callback) {
+ var params = [
+ ['Filter.1.Name', 'network-interface-id'],
+ ['Filter.1.Value', eni_id]
+ ];
+
+ ec2_httpclient.queryEC2("DescribeNetworkInterfaces", params, this, true, "onCompleteDescribePrivateIpAddresses", callback);
+ },
+
+ onCompleteDescribePrivateIpAddresses : function (objResponse) {
+ var xmlDoc = objResponse.xmlDoc;
+
+ var items = xmlDoc.evaluate("/ec2:DescribeNetworkInterfacesResponse/ec2:networkInterfaceSet/ec2:item/ec2:privateIpAddressesSet/ec2:item",
+ xmlDoc,
+ this.getNsResolver(),
+ XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
+ null);
+
+ var list = new Array();
+
+ for(var i = 0 ; i < items.snapshotLength; i++) {
+ var item = items.snapshotItem(i);
+
+ var privateIpAddress = getNodeValueByName(item, "privateIpAddress");
+ var primary = getNodeValueByName(item, "primary");
+ list.push([privateIpAddress, primary]);
+ }
+
+ if (objResponse.callback) {
+ objResponse.callback(list);
+ }
+ },
+
createNetworkInterface : function (vpcId, subnetId, privateIpAddress, description, groupNames, callback) {
var params = [['SubnetId', subnetId]];
@@ -3162,4 +3195,42 @@ var ec2ui_controller = {
}
},
+ assignPrivateIpAddresses : function(eni_id, ip_addrs, reassign, callback) {
+ var params = [["NetworkInterfaceId", eni_id]];
+
+ for (var i = 0; i < ip_addrs.length; i++) {
+ var ip_addr = ip_addrs[i];
+ params.push(["PrivateIpAddress." + (i + 1), ip_addr]);
+ }
+
+ if (reassign) {
+ params.push(["AllowReassignment", "true"])
+ }
+
+ ec2_httpclient.queryEC2("AssignPrivateIpAddresses", params, this, true, "onCompleteAssignPrivateIpAddresses", callback);
+ },
+
+ onCompleteAssignPrivateIpAddresses : function (objResponse) {
+ if (objResponse.callback) {
+ objResponse.callback();
+ }
+ },
+
+ unassignPrivateIpAddresses : function(eni_id, ip_addrs, callback) {
+ var params = [["NetworkInterfaceId", eni_id]];
+
+ for (var i = 0; i < ip_addrs.length; i++) {
+ var ip_addr = ip_addrs[i];
+ params.push(["PrivateIpAddress." + (i + 1), ip_addr]);
+ }
+
+ ec2_httpclient.queryEC2("UnassignPrivateIpAddresses", params, this, true, "onCompleteUnassignPrivateIpAddresses", callback);
+ },
+
+ onCompleteUnassignPrivateIpAddresses : function (objResponse) {
+ if (objResponse.callback) {
+ objResponse.callback();
+ }
+ },
+
};
View
36 ec2ui/content/ec2ui/dialog_private_ip_address.xul
@@ -0,0 +1,36 @@
+<?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="Secondly Private IP Address"
+ buttons="accept,cancel"
+ ondialogaccept="return privateIpAddressDialogDoOK();"
+ ondialogcancel="return true;"
+ onload="privateIpAddressDialogOnLoad();">
+
+ <label id="private-ip-address-dialog-private-ip-address-label" control="private-ip-address-dialog-private-ip-address" value="Private IP Address (ex: IP Address, IP Address...) " />
+ <textbox id="private-ip-address-dialog-private-ip-address" multiline="true" flex="1" wrap="false" />
+ <checkbox id="private-ip-address-dialog-allow-reassignment" label="Allow Reassignment" checked="false" />
+
+ <script><![CDATA[
+ function privateIpAddressDialogOnLoad() {
+ var currentPrivateIpAddress = window.arguments[0];
+
+ if (currentPrivateIpAddress) {
+ var privateIpAddress = document.getElementById('private-ip-address-dialog-private-ip-address');
+ privateIpAddress.value = currentPrivateIpAddress.join(",\n");
+ }
+ }
+
+ function privateIpAddressDialogDoOK() {
+ var returnValue = window.arguments[1];
+ var privateIpAddress = document.getElementById('private-ip-address-dialog-private-ip-address');
+ var allowReassignment = document.getElementById('private-ip-address-dialog-allow-reassignment');
+ returnValue.accepted = true;
+ returnValue.addrs = (privateIpAddress.value || '');
+ returnValue.reassign = allowReassignment.checked;
+ return true;
+ }
+ ]]></script>
+</dialog>
View
2  ec2ui/content/ec2ui/eni_tab_overlay.xul
@@ -19,6 +19,8 @@
label="Change Source/Dest Check" />
<menuitem oncommand="ec2ui_ENITreeView.changeDescription();"
label="Change Description" />
+ <menuitem oncommand="ec2ui_ENITreeView.changePrivateIpAddresses();"
+ label="Change Secondly Private IP Address" />
<menuseparator />
<menuitem oncommand="ec2ui_ENITreeView.copyToClipBoard('networkInterfaceId');"
label="Copy Network Interface ID" />
View
70 ec2ui/content/ec2ui/eniview.js
@@ -253,6 +253,76 @@ var ec2ui_ENITreeView = {
});
},
+ changePrivateIpAddresses: function() {
+ var eni = this.getSelectedNetworkInterface();
+ if (!eni) { return; }
+
+ var me = this;
+
+ ec2ui_session.controller.describePrivateIpAddresses(eni.networkInterfaceId, function(list) {
+ var returnValue = {accepted:false , addrs:null, reassign:null};
+
+ var current_ip_addrs = new Array();
+
+ for (var i = 0; i < list.length; i++) {
+ if (list[i][1] != 'true') {
+ current_ip_addrs.push(list[i][0]);
+ }
+ }
+
+ openDialog('chrome://ec2ui/content/dialog_private_ip_address.xul',
+ null,
+ 'chrome,centerscreen,modal,width=400,height=250',
+ current_ip_addrs,
+ returnValue);
+
+ if (returnValue.accepted) {
+ var new_ip_addrs = (returnValue.addrs || '');
+ me.updatePrivateIpAddresses(eni.networkInterfaceId, current_ip_addrs.join(","), new_ip_addrs, returnValue.reassign);
+ }
+ });
+ },
+
+ updatePrivateIpAddresses: function(eni_id, current_ip_addrs, new_ip_addrs, reassign) {
+ function normalize(addrs) {
+ var hash = new Object();
+ addrs = (addrs || '').trim().split(',');
+
+ for (var i = 0; i < addrs.length; i++) {
+ var ip_addr = (addrs[i] || '').trim();
+ if (ip_addr) { hash[ip_addr] = 1; }
+ }
+
+ return hash;
+ }
+
+ current_ip_addrs = normalize(current_ip_addrs);
+ new_ip_addrs = normalize(new_ip_addrs);
+
+ var assigns = new Array();
+ var unassigns = new Array();
+
+ for (var ip_addr in new_ip_addrs) {
+ if (!current_ip_addrs[ip_addr]) {
+ assigns.push(ip_addr);
+ }
+ }
+
+ for (var ip_addr in current_ip_addrs) {
+ if (!new_ip_addrs[ip_addr]) {
+ unassigns.push(ip_addr);
+ }
+ }
+
+ if (unassigns.length > 0) {
+ ec2ui_session.controller.unassignPrivateIpAddresses(eni_id, unassigns);
+ }
+
+ if (assigns.length > 0) {
+ ec2ui_session.controller.assignPrivateIpAddresses(eni_id, assigns, reassign);
+ }
+ },
+
register: function() {
if (!this.registered) {
this.registered = true;
Please sign in to comment.
Something went wrong with that request. Please try again.