def test_is_valid_ip(self): self.assertTrue(netutils.is_valid_ip('127.0.0.1')) self.assertTrue(netutils.is_valid_ip('2001:db8::ff00:42:8329')) self.assertFalse(netutils.is_valid_ip('256.0.0.0')) self.assertFalse(netutils.is_valid_ip('::1.2.3.')) self.assertFalse(netutils.is_valid_ip(''))
def show(self, req, domain_id, id): """Return the DNS entry that corresponds to domain_id and id.""" context = req.environ['nova.context'] authorize(context) domain = _unquote_domain(domain_id) floating_ip = None # Check whether id is a valid ipv4/ipv6 address. if netutils.is_valid_ip(id): floating_ip = id try: if floating_ip: entries = self.network_api.get_dns_entries_by_address( context, floating_ip, domain) else: entries = self.network_api.get_dns_entries_by_name( context, id, domain) except NotImplementedError: msg = _("Unable to get dns entry") raise webob.exc.HTTPNotImplemented(explanation=msg) if not entries: explanation = _("DNS entries not found.") raise webob.exc.HTTPNotFound(explanation=explanation) if floating_ip: entrylist = [_create_dns_entry(floating_ip, entry, domain) for entry in entries] dns_entries = _translate_dns_entries_view(entrylist) return wsgi.ResponseObject(dns_entries) entry = _create_dns_entry(entries[0], id, domain) return _translate_dns_entry_view(entry)