/* (non-Javadoc) * @see com.eucalyptus.dns.Zone#findRecords(org.xbill.DNS.Name, int) */ @Override public SetResponse findRecords(Name name, int type) { if (type == Type.AAAA) return (SetResponse.ofType(SetResponse.SUCCESSFUL)); if (StackConfiguration.USE_INSTANCE_DNS && name.toString().matches("euca-.+{3}-.+{3}-.+{3}-.+{3}\\..*")) { try { String[] tryIp = name.toString() .replaceAll("euca-", "") .replaceAll(VmInstances.INSTANCE_SUBDOMAIN + ".*", "") .split("-"); if (tryIp.length < 4) return super.findRecords(name, type); String ipCandidate = new StringBuffer() .append(tryIp[0]) .append(".") .append(tryIp[1]) .append(".") .append(tryIp[2]) .append(".") .append(tryIp[3]) .toString(); try { VmInstances.lookupByPublicIp(ipCandidate); } catch (Exception e) { try { VmInstances.lookupByPrivateIp(ipCandidate); } catch (Exception e1) { return super.findRecords(name, type); } } InetAddress ip = InetAddress.getByName(ipCandidate); SetResponse resp = new SetResponse(SetResponse.SUCCESSFUL); resp.addRRset(new RRset(new ARecord(name, 1, ttl, ip))); return resp; } catch (Exception e) { return super.findRecords(name, type); } } else if (StackConfiguration.USE_INSTANCE_DNS && name.toString().endsWith(".in-addr.arpa.")) { int index = name.toString().indexOf(".in-addr.arpa."); Name target; if (index > 0) { String ipString = name.toString().substring(0, index); String[] parts = ipString.split("\\."); String ipCandidate; if (parts.length == 4) { ipCandidate = new StringBuffer() .append(parts[3]) .append(".") .append(parts[2]) .append(".") .append(parts[1]) .append(".") .append(parts[0]) .toString(); } else { return super.findRecords(name, type); } try { VmInstance instance = VmInstances.lookupByPublicIp(ipCandidate); target = new Name(instance.getPublicDnsName() + "."); } catch (Exception e) { try { VmInstance instance = VmInstances.lookupByPrivateIp(ipCandidate); target = new Name(instance.getPrivateDnsName() + "."); } catch (Exception e1) { return super.findRecords(name, type); } } SetResponse resp = new SetResponse(SetResponse.SUCCESSFUL); resp.addRRset(new RRset(new PTRRecord(name, DClass.IN, ttl, target))); return resp; } else { return super.findRecords(name, type); } } else { return super.findRecords(name, type); } }