Skip to content
This repository has been archived by the owner on Sep 23, 2020. It is now read-only.

Commit

Permalink
Added translation of IPs for EC2 protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
labisso committed Jul 15, 2010
1 parent 4b8f522 commit dcbf243
Showing 1 changed file with 38 additions and 12 deletions.
Expand Up @@ -452,8 +452,15 @@ protected void handleNetworking(VM vm,
vm.getID() + " is missing hostname");
}

final String ipAddress = nics[0].getIpAddress();
if (ipAddress == null) {
throw new CannotTranslateException("NIC in vm id-" +
vm.getID() + " is missing IP address");
}

final String netName2;
final String hostname2;
final String ipAddress2;
if (nics.length == 2) {
netName2 = nics[1].getNetworkName();
if (netName2 == null) {
Expand All @@ -466,46 +473,63 @@ protected void handleNetworking(VM vm,
throw new CannotTranslateException("NIC in vm id-" +
vm.getID() + " is missing hostname");
}

ipAddress2 = nics[1].getIpAddress();
if (ipAddress2 == null) {
throw new CannotTranslateException("NIC in vm id-" +
vm.getID() + " is missing IP address");
}
} else {
netName2 = null;
hostname2 = null;
ipAddress2 = null;
}

String privateAssigned = null;
String publicAssigned = null;
String privateAssignedHostname = null;
String publicAssignedHostname = null;
String privateAssignedIp = null;
String publicAssignedIp = null;

if (this.networks.isPrivateNetwork(netName)) {
riit.setPrivateDnsName(hostname);
privateAssigned = hostname;
riit.setPrivateIpAddress(ipAddress);
privateAssignedHostname = hostname;
privateAssignedIp = ipAddress;
} else if (this.networks.isPublicNetwork(netName)) {
riit.setDnsName(hostname);
publicAssigned = hostname;
riit.setIpAddress(ipAddress);
publicAssignedHostname = hostname;
publicAssignedIp = ipAddress;
} else {
throw new CannotTranslateException("Unknown network was " +
"assigned: '" + netName + "'");
}

if (nics.length == 2) {
if (this.networks.isPrivateNetwork(netName2)) {
if (privateAssigned != null) {
if (privateAssignedHostname != null) {
// if public and private are set to be the same, that means
// request ONE nic and make it appear to be two in remote
// interface
throw new CannotTranslateException("Won't support " +
"real NICs from duplicate networks yet");
}
riit.setPrivateDnsName(hostname2);
privateAssigned = hostname2;
riit.setPrivateIpAddress(ipAddress2);
privateAssignedHostname = hostname2;
privateAssignedIp = ipAddress2;
} else if (this.networks.isPublicNetwork(netName2)) {
if (publicAssigned != null) {
if (publicAssignedHostname != null) {
// if public and private are set to be the same, that means
// request ONE nic and make it appear to be two in remote
// interface
throw new CannotTranslateException("Won't support " +
"real NICs from duplicate networks yet");
}
riit.setDnsName(hostname2);
publicAssigned = hostname2;
riit.setIpAddress(ipAddress2);
publicAssignedHostname = hostname2;
publicAssignedIp = ipAddress2;
} else {
throw new CannotTranslateException("Unknown network was " +
"assigned: '" + netName2 + "'");
Expand All @@ -515,18 +539,20 @@ protected void handleNetworking(VM vm,
if (this.networks.getManagerPublicNetworkName().equals(
this.networks.getManagerPrivateNetworkName())) {

if (publicAssigned != null && privateAssigned != null) {
if (publicAssignedHostname != null && privateAssignedHostname != null) {
// if public and private are set to be the same, that means
// request ONE nic and make it appear to be two in remote
// interface
throw new CannotTranslateException("Won't support " +
"real NICs from duplicate networks yet");
}

if (publicAssigned != null) {
riit.setPrivateDnsName(publicAssigned);
if (publicAssignedHostname != null) {
riit.setPrivateDnsName(publicAssignedHostname);
riit.setPrivateIpAddress(publicAssignedIp);
} else {
riit.setDnsName(privateAssigned);
riit.setDnsName(privateAssignedHostname);
riit.setIpAddress(privateAssignedIp);
}
}
}
Expand Down

0 comments on commit dcbf243

Please sign in to comment.