}
final NIC[] nics = vm.getNics();
if (nics == null || nics.length == 0) {
// zero NICs not supported by this interface
throw new CannotTranslateException("NICs are missing");
}
if (nics.length != 1 && nics.length != 2) {
throw new CannotTranslateException("Can only handle one or two " +
"assigned NICs, but were given " + nics.length +
" for vm id-" + vm.getID());
}
if (nics.length == 1 && nics[0] == null) {
throw new CannotTranslateException("NIC[] value is missing");
}
if (nics.length == 2 && nics[1] == null) {
throw new CannotTranslateException("NIC[] value is missing");
}
final String netName = nics[0].getNetworkName();
if (netName == null) {
throw new CannotTranslateException("NIC in vm id-" +
vm.getID() + " is missing network name");
}
final String hostname = nics[0].getHostname();
if (hostname == null) {
throw new CannotTranslateException("NIC in vm id-" +
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) {
throw new CannotTranslateException("NIC in vm id-" +
vm.getID() + " is missing network name");
}
hostname2 = nics[1].getHostname();
if (hostname2 == null) {
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 privateAssignedHostname = null;
String publicAssignedHostname = null;
String privateAssignedIp = null;
String publicAssignedIp = null;
if (netName2 != null) {
logger.info("Using networks " + netName + " and " + netName2);
} else {
logger.info("Using network " + netName);
}
if (this.networks.isPrivateNetwork(netName)) {
riit.setPrivateDnsName(hostname);
riit.setPrivateIpAddress(ipAddress);
privateAssignedHostname = hostname;
privateAssignedIp = ipAddress;
} else if (this.networks.isPublicNetwork(netName)) {
riit.setDnsName(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 (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);
riit.setPrivateIpAddress(ipAddress2);
privateAssignedHostname = hostname2;
privateAssignedIp = ipAddress2;
} else if (this.networks.isPublicNetwork(netName2)) {
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);
riit.setIpAddress(ipAddress2);
publicAssignedHostname = hostname2;
publicAssignedIp = ipAddress2;
} else {
throw new CannotTranslateException("Unknown network was " +
"assigned: '" + netName2 + "'");
}
}
if (this.networks.getManagerPublicNetworkName().equals(
this.networks.getManagerPrivateNetworkName())) {
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 (publicAssignedHostname != null) {
riit.setPrivateDnsName(publicAssignedHostname);