summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2011-06-13 16:23:09 +0200
committerMartin Kosek <mkosek@redhat.com>2011-06-15 12:47:57 +0200
commit613804083d40f6d3b64eeaa8da8a4f5b94cb839d (patch)
treef171cffe554cd746ed3e2ea06e4d0bff71d05f73 /ipalib/plugins
parentf21508978511d40a60fbdaaa786bcc96f99578d5 (diff)
downloadfreeipa-613804083d40f6d3b64eeaa8da8a4f5b94cb839d.tar.gz
freeipa-613804083d40f6d3b64eeaa8da8a4f5b94cb839d.tar.xz
freeipa-613804083d40f6d3b64eeaa8da8a4f5b94cb839d.zip
Add a list of managed hosts
Enhance Host plugin to provide not only "Managed By" list but also a list of managed hosts. The new list is generated only when --all option is passed. https://fedorahosted.org/freeipa/ticket/993
Diffstat (limited to 'ipalib/plugins')
-rw-r--r--ipalib/plugins/host.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/ipalib/plugins/host.py b/ipalib/plugins/host.py
index a602df4d1..29f659f9c 100644
--- a/ipalib/plugins/host.py
+++ b/ipalib/plugins/host.py
@@ -158,6 +158,9 @@ host_output_params = (
Str('managedby_host',
label='Managed by',
),
+ Str('managing_host',
+ label='Managing',
+ ),
Str('subject',
label=_('Subject'),
),
@@ -216,6 +219,7 @@ class host(LDAPObject):
'enrolledby': ['user'],
'memberof': ['hostgroup', 'netgroup', 'role', 'hbacrule', 'sudorule'],
'managedby': ['host'],
+ 'managing': ['host'],
'memberofindirect': ['hostgroup', 'netgroup', 'role', 'hbacrule',
'sudorule'],
}
@@ -224,6 +228,7 @@ class host(LDAPObject):
'memberof': ('Member Of', 'in_', 'not_in_'),
'enrolledby': ('Enrolled by', 'enroll_by_', 'not_enroll_by_'),
'managedby': ('Managed by', 'man_by_', 'not_man_by_'),
+ 'managing': ('Managing', 'man_', 'not_man_'),
}
label = _('Hosts')
@@ -302,6 +307,23 @@ class host(LDAPObject):
pass
return dn
+ def get_managed_hosts(self, dn):
+ host_filter = 'managedBy=%s' % dn
+ host_attrs = ['fqdn']
+ ldap = self.api.Backend.ldap2
+ managed_hosts = []
+
+ try:
+ (hosts, truncated) = ldap.find_entries(base_dn=self.container_dn,
+ filter=host_filter, attrs_list=host_attrs)
+
+ for host in hosts:
+ managed_hosts.append(host[0])
+ except errors.NotFound:
+ return []
+
+ return managed_hosts
+
api.register(host)
@@ -416,6 +438,10 @@ class host_add(LDAPCreate):
reason=_('The host was added but the DNS update failed with: %(exc)s') % dict(exc=exc)
)
set_certificate_attrs(entry_attrs)
+
+ if options.get('all', False):
+ entry_attrs['managing'] = self.obj.get_managed_hosts(dn)
+
return dn
api.register(host_add)
@@ -611,6 +637,10 @@ class host_mod(LDAPUpdate):
if options.get('random', False):
entry_attrs['randompassword'] = unicode(getattr(context, 'randompassword'))
set_certificate_attrs(entry_attrs)
+
+ if options.get('all', False):
+ entry_attrs['managing'] = self.obj.get_managed_hosts(dn)
+
return dn
api.register(host_mod)
@@ -638,6 +668,9 @@ class host_find(LDAPSearch):
entry_attrs = entry[1]
set_certificate_attrs(entry_attrs)
+ if options.get('all', False):
+ entry_attrs['managing'] = self.obj.get_managed_hosts(entry[0])
+
api.register(host_find)
@@ -664,6 +697,9 @@ class host_show(LDAPRetrieve):
set_certificate_attrs(entry_attrs)
+ if options.get('all', False):
+ entry_attrs['managing'] = self.obj.get_managed_hosts(dn)
+
return dn
def forward(self, *keys, **options):