summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins/hostgroup.py
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2009-08-27 15:52:05 +0200
committerRob Crittenden <rcritten@redhat.com>2009-10-05 16:02:02 -0400
commit26b05cd364f76a9e07a9653fdc143dd94b660aae (patch)
treef044153dd6837e47c890ce202c8be95f04e6f89f /ipalib/plugins/hostgroup.py
parent9b77455cbbb7f91551c92133caf288c7136b4da4 (diff)
downloadfreeipa-26b05cd364f76a9e07a9653fdc143dd94b660aae.tar.gz
freeipa-26b05cd364f76a9e07a9653fdc143dd94b660aae.tar.xz
freeipa-26b05cd364f76a9e07a9653fdc143dd94b660aae.zip
Make the hostgroup plugin use baseldap classes.
Diffstat (limited to 'ipalib/plugins/hostgroup.py')
-rw-r--r--ipalib/plugins/hostgroup.py218
1 files changed, 45 insertions, 173 deletions
diff --git a/ipalib/plugins/hostgroup.py b/ipalib/plugins/hostgroup.py
index ec69e6058..8e5cf5fa6 100644
--- a/ipalib/plugins/hostgroup.py
+++ b/ipalib/plugins/hostgroup.py
@@ -1,5 +1,6 @@
# Authors:
# Rob Crittenden <rcritten@redhat.com>
+# Pavel Zuna <pzuna@redhat.com>
#
# Copyright (C) 2009 Red Hat
# see file 'COPYING' for use and warranty information
@@ -16,233 +17,104 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
"""
Groups of hosts.
"""
from ipalib import api
-from ipalib.plugins.basegroup import *
-
-_container_dn = api.env.container_hostgroup
-_default_attributes = ['cn', 'description', 'member', 'memberof']
-_default_class = 'ipahostgroup'
+from ipalib import Int
+from ipalib.plugins.baseldap import *
-class hostgroup(basegroup):
+class hostgroup(LDAPObject):
"""
Hostgroup object.
"""
- container = _container_dn
+ container_dn = api.env.container_hostgroup
+ object_name = 'hostgroup'
+ object_name_plurals = 'hostgroups'
+ object_class = ['ipaobject', 'ipahostgroup']
+ default_attributes = ['cn', 'description', 'member', 'memberof']
+ uuid_attribute = 'ipauniqueid'
+ attribute_names = {
+ 'cn': 'names',
+ 'member host': 'member hosts',
+ 'member hostgroup': 'member hostgroups',
+ 'memberof hostgroup': 'member of hostgroup',
+ }
+ attribute_members = {
+ 'member': ['host', 'hostgroup'],
+ 'memberof': ['hostgroup'],
+ }
+
+ takes_params = (
+ Str('cn',
+ cli_name='name',
+ doc='group name',
+ primary_key=True,
+ normalizer=lambda value: value.lower(),
+ ),
+ Str('description',
+ cli_name='desc',
+ doc='A description of this group',
+ ),
+ )
api.register(hostgroup)
-class hostgroup_add(basegroup_add):
+class hostgroup_add(LDAPCreate):
"""
- Create a new hostgroup.
+ Create new hostgroup.
"""
- base_classes = basegroup_add.base_classes + (_default_class, )
-
- def execute(self, cn, **kw):
- return super(hostgroup_add, self).execute(cn, **kw)
api.register(hostgroup_add)
-class hostgroup_del(basegroup_del):
+class hostgroup_del(LDAPDelete):
"""
- Delete an existing hostgroup.
+ Delete hostgroup.
"""
- container = _container_dn
-
- def execute(self, cn, **kw):
- return super(hostgroup_del, self).execute(cn, **kw)
api.register(hostgroup_del)
-class hostgroup_mod(basegroup_mod):
+class hostgroup_mod(LDAPUpdate):
"""
- Edit an existing hostgroup.
+ Modify hostgroup.
"""
- container = _container_dn
-
- def execute(self, cn, **kw):
- return super(hostgroup_mod, self).execute(cn, **kw)
api.register(hostgroup_mod)
-class hostgroup_find(basegroup_find):
+class hostgroup_find(LDAPSearch):
"""
- Search the groups.
+ Search for hostgroups.
"""
- container = _container_dn
-
- def execute(self, term, **kw):
- return super(hostgroup_find, self).execute(term, **kw)
api.register(hostgroup_find)
-class hostgroup_show(basegroup_show):
+class hostgroup_show(LDAPRetrieve):
"""
- Examine an existing hostgroup.
+ Display hostgroup.
"""
- container = _container_dn
-
- def execute(self, cn, **kw):
- return super(hostgroup_show, self).execute(cn, **kw)
api.register(hostgroup_show)
-class hostgroup_add_member(basegroup_add_member):
+class hostgroup_add_member(LDAPAddMember):
"""
Add members to hostgroup.
"""
- container = _container_dn
-
- takes_options = (
- List('groups?',
- cli_name='groups',
- doc='comma-separated list of user groups to add'
- ),
- List('hosts?',
- cli_name='hosts',
- doc='comma-separated list of hosts to add'
- ),
- List('hostgroups?',
- cli_name='hostgroups',
- doc='comma-separated list of hostgroups to add'
- ),
- )
-
- def execute(self, cn, **kw):
- """
- Execute the group-add-member operation.
-
- Returns a tuple containing the number of members added
- and the updated entry.
-
- :param cn: The group name to add new members to.
- :param kw: groups is a comma-separated list of groups to add
- :parem kw: users is a comma-separated list of users to add
- """
- assert self.container
- ldap = self.api.Backend.ldap2
- (dn, entry_attrs) = ldap.find_entry_by_attr(
- 'cn', cn, self.filter_class, [''], self.container
- )
- to_add = []
- add_failed = {}
- completed = 0
-
- members = kw.get('groups', [])
- (to_add, add_failed) = find_members(
- ldap, add_failed, members, 'cn', 'ipausergroup',
- self.api.env.container_group
- )
- (completed, add_failed) = add_members(
- ldap, completed, to_add, add_failed, dn, 'member'
- )
-
- members = kw.get('hosts', [])
- (to_add, add_failed) = find_members(
- ldap, add_failed, members, 'cn', 'ipahost',
- self.api.env.container_host
- )
- (completed, add_failed) = add_members(
- ldap, completed, to_add, add_failed, dn, 'member'
- )
-
- members = kw.get('hostgroups', [])
- (to_add, add_failed) = find_members(
- ldap, add_failed, members, 'cn', 'ipahostgroup',
- self.api.env.container_hostgroup
- )
- (completed, add_failed) = add_members(
- ldap, completed, to_add, add_failed, dn, 'member'
- )
-
- return (
- completed, add_failed, ldap.get_entry(dn, self.default_attributes)
- )
api.register(hostgroup_add_member)
-class hostgroup_remove_member(basegroup_remove_member):
+class hostgroup_remove_member(LDAPRemoveMember):
"""
Remove members from hostgroup.
"""
- container = _container_dn
-
- takes_options = (
- List('groups?',
- cli_name='groups',
- doc='comma-separated list of user groups to add'
- ),
- List('hosts?',
- cli_name='hosts',
- doc='comma-separated list of hosts to add'
- ),
- List('hostgroups?',
- cli_name='hostgroups',
- doc='comma-separated list of hostgroups to add'
- ),
- )
-
- def execute(self, cn, **kw):
- """
- Execute the group-remove-member operation.
-
- Returns a tuple containing the number of members removed
- and the updated entry.
-
- :param cn: The group name to remove new members from.
- :parem kw: users is a comma-separated list of users to remove
- """
- assert self.container
- ldap = self.api.Backend.ldap2
- (dn, entry_attrs) = ldap.find_entry_by_attr(
- 'cn', cn, self.filter_class, [''], self.container
- )
- to_remove = []
- rem_failed = {}
- completed = 0
-
- members = kw.get('groups', [])
- (to_remove, rem_failed) = find_members(
- ldap, rem_failed, members, 'cn', 'ipausergroup',
- self.api.env.container_group
- )
- (completed, rem_failed) = del_members(
- ldap, completed, to_remove, rem_failed, dn, 'member'
- )
-
- members = kw.get('hosts', [])
- (to_remove, rem_failed) = find_members(
- ldap, rem_failed, members, 'cn', 'ipahost',
- self.api.env.container_host
- )
- (completed, rem_failed) = del_members(
- ldap, completed, to_remove, rem_failed, dn, 'member'
- )
-
- members = kw.get('hostgroups', [])
- (to_remove, rem_failed) = find_members(
- ldap, rem_failed, members, 'cn', 'ipahostgroup',
- self.api.env.container_hostgroup
- )
- (completed, rem_failed) = del_members(
- ldap, completed, to_remove, rem_failed, dn, 'member'
- )
-
- return (
- completed, rem_failed, ldap.get_entry(dn, _default_attributes)
- )
api.register(hostgroup_remove_member)