diff options
Diffstat (limited to 'pynslcd/host.py')
-rw-r--r-- | pynslcd/host.py | 26 |
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): |