summaryrefslogtreecommitdiff
path: root/nova/network/ldapdns.py
diff options
context:
space:
mode:
authorPádraig Brady <pbrady@redhat.com>2012-02-10 13:19:40 +0000
committerPádraig Brady <pbrady@redhat.com>2012-02-13 09:38:30 +0000
commit0e541e27a987f04cab2248b852ab897a23801047 (patch)
treee0c00449aaa17b3df623fa07fb08fa333f853196 /nova/network/ldapdns.py
parentd8f8bad0f26b4438986ab1a469d89d03b22551db (diff)
downloadnova-0e541e27a987f04cab2248b852ab897a23801047.tar.gz
remove a private duplicate function
* nova/network/ldapdns.py (utf-8): This function is already available in nova.utils. Note this duplicate was catching impossible to trigger exceptions, and was referencing an undefined variable 'val' Change-Id: I0e47f8b976a3326c99927990f91be473c0a85f78
Diffstat (limited to 'nova/network/ldapdns.py')
-rw-r--r--nova/network/ldapdns.py29
1 files changed, 10 insertions, 19 deletions
diff --git a/nova/network/ldapdns.py b/nova/network/ldapdns.py
index 275587d502..7608d807e6 100644
--- a/nova/network/ldapdns.py
+++ b/nova/network/ldapdns.py
@@ -22,6 +22,7 @@ from nova.auth import fakeldap
from nova import exception
from nova import flags
from nova import log as logging
+from nova import utils
from nova.openstack.common import cfg
@@ -67,17 +68,6 @@ ldap_dns_opts = [
flags.FLAGS.register_opts(ldap_dns_opts)
-def utf8(instring):
- if type(instring) == unicode:
- try:
- return instring.encode('utf8')
- except UnicodeError, AttributeError:
- LOG.warn(_('Unable to encode %s as utf8. Discarding.') % val)
- return None
- else:
- return instring
-
-
# Importing ldap.modlist breaks the tests for some reason,
# so this is an abbreviated version of a function from
# there.
@@ -86,7 +76,7 @@ def create_modlist(newattrs):
for attrtype in newattrs.keys():
utf8_vals = []
for val in newattrs[attrtype]:
- utf8_vals.append(utf8(val))
+ utf8_vals.append(utils.utf8(val))
newattrs[attrtype] = utf8_vals
modlist.append((attrtype, newattrs[attrtype]))
return modlist
@@ -105,7 +95,7 @@ class DNSEntry(object):
@classmethod
def _get_tuple_for_domain(cls, lobj, domain):
entry = lobj.search_s(flags.FLAGS.ldap_dns_base_dn, ldap.SCOPE_SUBTREE,
- "(associatedDomain=%s)" % utf8(domain))
+ "(associatedDomain=%s)" % utils.utf8(domain))
if not entry:
return None
if len(entry) > 1:
@@ -163,7 +153,7 @@ class DomainEntry(DNSEntry):
flags.FLAGS.ldap_dns_soa_retry,
flags.FLAGS.ldap_dns_soa_expiry,
flags.FLAGS.ldap_dns_soa_minimum)
- return utf8(soa)
+ return utils.utf8(soa)
@classmethod
def create_domain(cls, lobj, domain):
@@ -207,7 +197,8 @@ class DomainEntry(DNSEntry):
def subentry_with_name(self, name):
entry = self.lobj.search_s(self.dn, ldap.SCOPE_SUBTREE,
"(associatedDomain=%s.%s)" %
- (utf8(name), utf8(self.qualified_domain)))
+ (utils.utf8(name),
+ utils.utf8(self.qualified_domain)))
if entry:
return HostEntry(self, entry[0])
else:
@@ -215,7 +206,7 @@ class DomainEntry(DNSEntry):
def subentries_with_ip(self, ip):
entries = self.lobj.search_s(self.dn, ldap.SCOPE_SUBTREE,
- "(aRecord=%s)" % utf8(ip))
+ "(aRecord=%s)" % utils.utf8(ip))
objs = []
for entry in entries:
if 'associatedDomain' in entry[1]:
@@ -235,7 +226,7 @@ class DomainEntry(DNSEntry):
existingdn = entries[0].dn
self.lobj.modify_s(existingdn, [(ldap.MOD_ADD,
'associatedDomain',
- utf8(self._qualify(name)))])
+ utils.utf8(self._qualify(name)))])
return self.subentry_with_name(name)
else:
@@ -273,7 +264,7 @@ class HostEntry(DNSEntry):
if len(names) > 1:
# We just have to remove the requested domain.
self.lobj.modify_s(self.dn, [(ldap.MOD_DELETE, 'associatedDomain',
- self._qualify(utf8(name)))])
+ self._qualify(utils.utf8(name)))])
if (self.rdn[1] == name):
# We just removed the rdn, so we need to move this entry.
names.remove(self._qualify(name))
@@ -289,7 +280,7 @@ class HostEntry(DNSEntry):
raise exception.NotFound()
if len(names) == 1:
self.lobj.modify_s(self.dn, [(ldap.MOD_REPLACE, 'aRecord',
- [utf8(address)])])
+ [utils.utf8(address)])])
else:
self.remove_name(name)
parent.add_entry(name, address)