summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--ipalib/plugins/host.py36
-rw-r--r--tests/test_xmlrpc/test_host_plugin.py2
2 files changed, 38 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):
diff --git a/tests/test_xmlrpc/test_host_plugin.py b/tests/test_xmlrpc/test_host_plugin.py
index 18f813d5b..ff87bc248 100644
--- a/tests/test_xmlrpc/test_host_plugin.py
+++ b/tests/test_xmlrpc/test_host_plugin.py
@@ -152,6 +152,7 @@ class test_host(Declarative):
serverhostname=[u'testhost1'],
objectclass=objectclasses.host,
managedby_host=[fqdn1],
+ managing_host=[fqdn1],
ipauniqueid=[fuzzy_uuid],
has_keytab=False
),
@@ -203,6 +204,7 @@ class test_host(Declarative):
objectclass=objectclasses.host,
ipauniqueid=[fuzzy_uuid],
managedby_host=[u'%s' % fqdn1],
+ managing_host=[u'%s' % fqdn1],
),
],
),