~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/network/ldapdns.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#    under the License.
14
14
 
15
15
import ldap
16
 
import os
17
 
import shutil
18
 
import tempfile
19
16
import time
20
17
 
21
18
from nova.auth import fakeldap
22
19
from nova import exception
23
20
from nova import flags
24
21
from nova import log as logging
 
22
from nova.openstack.common import cfg
25
23
from nova import utils
26
 
from nova.openstack.common import cfg
27
24
 
28
25
 
29
26
LOG = logging.getLogger(__name__)
95
92
    @classmethod
96
93
    def _get_tuple_for_domain(cls, lobj, domain):
97
94
        entry = lobj.search_s(flags.FLAGS.ldap_dns_base_dn, ldap.SCOPE_SUBTREE,
98
 
                              "(associatedDomain=%s)" % utils.utf8(domain))
 
95
                              '(associatedDomain=%s)' % utils.utf8(domain))
99
96
        if not entry:
100
97
            return None
101
98
        if len(entry) > 1:
106
103
    @classmethod
107
104
    def _get_all_domains(cls, lobj):
108
105
        entries = lobj.search_s(flags.FLAGS.ldap_dns_base_dn,
109
 
                                ldap.SCOPE_SUBTREE, "(sOARecord=*)")
 
106
                                ldap.SCOPE_SUBTREE, '(sOARecord=*)')
110
107
        domains = []
111
108
        for entry in entries:
112
109
            domain = entry[1].get('associatedDomain')
118
115
        self.ldap_tuple = tuple
119
116
 
120
117
    def _qualify(self, name):
121
 
        return "%s.%s" % (name, self.qualified_domain)
 
118
        return '%s.%s' % (name, self.qualified_domain)
122
119
 
123
120
    def _dequalify(self, name):
124
121
        z = ".%s" % self.qualified_domain
125
122
        if name.endswith(z):
126
123
            dequalified = name[0:name.rfind(z)]
127
124
        else:
128
 
            LOG.warn("Unable to dequalify.  %s is not in %s.\n" % (name,
129
 
                                                        self.qualified_domain))
 
125
            LOG.warn("Unable to dequalify.  %s is not in %s.\n" %
 
126
                     (name, self.qualified_domain))
130
127
            dequalified = None
131
128
 
132
129
        return dequalified
144
141
 
145
142
    @classmethod
146
143
    def _soa(cls):
147
 
        date = time.strftime("%Y%m%d%H%M%S")
148
 
        soa = "%s %s %s %s %s %s %s" % (
 
144
        date = time.strftime('%Y%m%d%H%M%S')
 
145
        soa = '%s %s %s %s %s %s %s' % (
149
146
                 flags.FLAGS.ldap_dns_servers[0],
150
147
                 flags.FLAGS.ldap_dns_soa_hostmaster,
151
148
                 date,
160
157
        """Create a new domain entry, and return an object that wraps it."""
161
158
        entry = cls._get_tuple_for_domain(lobj, domain)
162
159
        if entry:
163
 
            raise exception.FloatingIpDNSExists(name=domain, domain="")
 
160
            raise exception.FloatingIpDNSExists(name=domain, domain='')
164
161
 
165
 
        newdn = "dc=%s,%s" % (domain, flags.FLAGS.ldap_dns_base_dn)
 
162
        newdn = 'dc=%s,%s' % (domain, flags.FLAGS.ldap_dns_base_dn)
166
163
        attrs = {'objectClass': ['domainrelatedobject', 'dnsdomain',
167
164
                                 'domain', 'dcobject', 'top'],
168
165
                 'sOARecord': [cls._soa()],
196
193
 
197
194
    def subentry_with_name(self, name):
198
195
        entry = self.lobj.search_s(self.dn, ldap.SCOPE_SUBTREE,
199
 
                                   "(associatedDomain=%s.%s)" %
200
 
                                     (utils.utf8(name),
201
 
                                      utils.utf8(self.qualified_domain)))
 
196
                                   '(associatedDomain=%s.%s)' %
 
197
                                   (utils.utf8(name),
 
198
                                    utils.utf8(self.qualified_domain)))
202
199
        if entry:
203
200
            return HostEntry(self, entry[0])
204
201
        else:
206
203
 
207
204
    def subentries_with_ip(self, ip):
208
205
        entries = self.lobj.search_s(self.dn, ldap.SCOPE_SUBTREE,
209
 
                                   "(aRecord=%s)" % utils.utf8(ip))
 
206
                                     '(aRecord=%s)' % utils.utf8(ip))
210
207
        objs = []
211
208
        for entry in entries:
212
209
            if 'associatedDomain' in entry[1]:
231
228
            return self.subentry_with_name(name)
232
229
        else:
233
230
            # We need to create an entirely new entry.
234
 
            newdn = "dc=%s,%s" % (name, self.dn)
 
231
            newdn = 'dc=%s,%s' % (name, self.dn)
235
232
            attrs = {'objectClass': ['domainrelatedobject', 'dnsdomain',
236
233
                                     'domain', 'dcobject', 'top'],
237
234
                     'aRecord': [address],
268
265
            if (self.rdn[1] == name):
269
266
                # We just removed the rdn, so we need to move this entry.
270
267
                names.remove(self._qualify(name))
271
 
                newrdn = "dc=%s" % self._dequalify(names[0])
 
268
                newrdn = 'dc=%s' % self._dequalify(names[0])
272
269
                self.lobj.modrdn_s(self.dn, [newrdn])
273
270
        else:
274
271
            # We should delete the entire record.