Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/pynslcd/host.py
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2012-01-29 16:13:25 +0100
committerArthur de Jong <arthur@arthurdejong.org>2012-01-29 16:13:25 +0100
commit4c31632a1cf1a89fc685931986653581b2623f02 (patch)
treecdb2f5ad651760eaa89c5ed10e05e2787c21cde1 /pynslcd/host.py
parent0ddbc4563992e3e27a8e2fd1a343a855af6af151 (diff)
implement a naive offline cache
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1615 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'pynslcd/host.py')
-rw-r--r--pynslcd/host.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/pynslcd/host.py b/pynslcd/host.py
index 23ab521..49de45b 100644
--- a/pynslcd/host.py
+++ b/pynslcd/host.py
@@ -18,6 +18,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA
+import cache
import common
import constants
@@ -32,6 +33,31 @@ class Search(common.Search):
required = ('cn', )
+class HostQuery(cache.CnAliasedQuery):
+
+ sql = '''
+ SELECT `host_cache`.`cn` AS `cn`,
+ `host_1_cache`.`cn` AS `alias`,
+ `host_2_cache`.`ipHostNumber` AS `ipHostNumber`
+ FROM `host_cache`
+ LEFT JOIN `host_1_cache`
+ ON `host_1_cache`.`host` = `host_cache`.`cn`
+ LEFT JOIN `host_2_cache`
+ ON `host_2_cache`.`host` = `host_cache`.`cn`
+ '''
+
+ def __init__(self, parameters):
+ super(HostQuery, self).__init__('host', parameters)
+
+
+class Cache(cache.Cache):
+
+ def retrieve(self, parameters):
+ query = HostQuery(parameters)
+ for row in cache.RowGrouper(query.execute(self.con), ('cn', ), ('alias', 'ipHostNumber', )):
+ yield row['cn'], row['alias'], row['ipHostNumber']
+
+
class HostRequest(common.Request):
def write(self, hostname, aliases, addresses):