summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/constants.py1
-rw-r--r--ipalib/plugins/f_hostgroup.py28
2 files changed, 27 insertions, 2 deletions
diff --git a/ipalib/constants.py b/ipalib/constants.py
index 99b0ea719..9bd82a1bf 100644
--- a/ipalib/constants.py
+++ b/ipalib/constants.py
@@ -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),
diff --git a/ipalib/plugins/f_hostgroup.py b/ipalib/plugins/f_hostgroup.py
index 27aea00c6..8e4c37407 100644
--- a/ipalib/plugins/f_hostgroup.py
+++ b/ipalib/plugins/f_hostgroup.py
@@ -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)