Revive the hostgroup_container and include add/remove hosts in hostgroups plugin

This commit is contained in:
Rob Crittenden 2008-11-04 14:03:43 -05:00
parent 4967002359
commit e825bc7ccb
2 changed files with 27 additions and 2 deletions

View File

@ -69,6 +69,7 @@ DEFAULT_CONFIG = (
('container_group', 'cn=groups,cn=accounts'),
('container_service', 'cn=services,cn=accounts'),
('container_host', 'cn=computers,cn=accounts'),
('container_hostgroup', 'cn=hostgroups,cn=accounts'),
# Ports, hosts, and URIs:
('lite_xmlrpc_port', 8888),

View File

@ -222,7 +222,8 @@ class hostgroup_add_member(frontend.Command):
Param('group', primary_key=True),
)
takes_options = (
Param('groups?', doc='comma-separated list of groups to add'),
Param('groups?', doc='comma-separated list of host groups to add'),
Param('hosts?', doc='comma-separated list of hosts to add'),
)
def execute(self, cn, **kw):
"""
@ -231,7 +232,8 @@ class hostgroup_add_member(frontend.Command):
Returns the updated group entry
:param cn: The group name to add new members to.
:param kw: groups is a comma-separated list of groups to add
:param kw: groups is a comma-separated list of host groups to add
:param kw: hosts is a comma-separated list of hosts to add
"""
ldap = self.api.Backend.ldap
dn = ldap.find_entry_dn("cn", cn, hostgroup_filter)
@ -249,6 +251,16 @@ class hostgroup_add_member(frontend.Command):
add_failed.append(m)
continue
members = kw.get('hosts', '').split(',')
for m in members:
if not m: continue
try:
member_dn = ldap.find_entry_dn("cn", m, "ipaHost")
to_add.append(member_dn)
except errors.NotFound:
add_failed.append(m)
continue
for member_dn in to_add:
try:
ldap.add_member_to_group(member_dn, dn)
@ -278,6 +290,7 @@ class hostgroup_remove_member(frontend.Command):
Param('group', primary_key=True),
)
takes_options = (
Param('hosts?', doc='comma-separated list of hosts to add'),
Param('groups?', doc='comma-separated list of groups to remove'),
)
def execute(self, cn, **kw):
@ -288,6 +301,7 @@ class hostgroup_remove_member(frontend.Command):
:param cn: The group name to add new members to.
:param kw: groups is a comma-separated list of groups to remove
:param kw: hosts is a comma-separated list of hosts to add
"""
ldap = self.api.Backend.ldap
dn = ldap.find_entry_dn("cn", cn, hostgroup_filter)
@ -305,6 +319,16 @@ class hostgroup_remove_member(frontend.Command):
remove_failed.append(m)
continue
members = kw.get('hosts', '').split(',')
for m in members:
if not m: continue
try:
member_dn = ldap.find_entry_dn("cn", m, "ipaHost")
to_remove.append(member_dn)
except errors.NotFound:
remove_failed.append(m)
continue
for member_dn in to_remove:
try:
ldap.remove_member_from_group(member_dn, dn)