def restart_service(self,groupname,servicename):
		"""
		Restart service taking new rescent changes in use.
		"""
		res = self.l.search(conf.get('LDAPSERVER','basedn'),\
			ldap.SCOPE_SUBTREE,'(& (cn=%s)(objectclass=skoleSysServiceGroup))'%groupname,['dn','memberuid','servicelist'])
	
		sres = self.l.result(res,0)
		if sres[1]==[]:
			return -1 # Group does not exist
	
		dn = sres[1][0][0]
		servicelist = []
		if sres[1][0][1].has_key('serviceList'):
			servicelist = sres[1][0][1]['serviceList']
		
		if not servicelist.count(servicename):
			return -4 # Group is not attached to the service
		
		import skolesys.services as s
		if not s.groupservices().count(servicename):
			return -2 # the service does not exist
		service_inst = s.create_groupserviceinterface(servicename,groupname)
		if not service_inst:
			return -3 # the service failed to load
		
		return service_inst.restart()
	def attach_service(self,groupname,servicename):
		"""
		Attach the groupservice servicename to the group groupname
		1. LDAP insertion + run the service's hook_attachservice func 
		"""
		res = self.l.search(conf.get('LDAPSERVER','basedn'),\
			ldap.SCOPE_SUBTREE,'(& (cn=%s)(objectclass=skoleSysServiceGroup))'%groupname,['dn','memberuid','servicelist'])
		
		sres = self.l.result(res,0)
		if sres[1]==[]:
			return -1 # Group does not exist
		
		memberlist = []
		if sres[1][0][1].has_key('memberUid'):
			memberlist = sres[1][0][1]['memberUid']
		
		dn = sres[1][0][0]
		servicelist = []
		if sres[1][0][1].has_key('serviceList'):
			servicelist = sres[1][0][1]['serviceList']
		if servicelist.count(servicename):
			return -4 # service is already enabled
		
		import skolesys.services as s
		if not s.groupservices().count(servicename):
			return -2 # the service does not exist
		service_inst = s.create_groupserviceinterface(servicename,groupname)
		if not service_inst:
			return -3 # the service failed to load
		
		print "Attach service %s\non group %s\naffecting users: %s" % (servicename,groupname,','.join(memberlist))
		res = service_inst.hook_attachservice(memberlist)
		if not res==0:
			# Service hook failed
			print "The service attachment did not succeed"
			return res
		
		servicelist += [servicename]
		self.bind(conf.get('LDAPSERVER','admin'),conf.get('LDAPSERVER','passwd'))
		self.touch_by_dict({dn:{'serviceList': servicelist}})
		return 0
	def list_service_options_available(self,servicename,groupname=None):
		"""
		Fetch a dictionary describing the options available for a certain group service.
		It can only be used in combination with a groupname since it is legal to have options_available
		change dynamically i.e. as a function of the options already set. F.inst. if an option is "use_pop3"
		the options_available might change by adding options like "use_ssl" and "pop3_server".
		SkoleSYS UI is implemented with this in mind.
		"""
		if groupname:
			res = self.l.search(conf.get('LDAPSERVER','basedn'),\
				ldap.SCOPE_SUBTREE,'(& (cn=%s)(objectclass=skoleSysServiceGroup))'%groupname,['dn','memberuid','servicelist'])
		
			sres = self.l.result(res,0)
			if sres[1]==[]:
				return -1 # Group does not exist
		
			dn = sres[1][0][0]
			servicelist = []
			if sres[1][0][1].has_key('serviceList'):
				servicelist = sres[1][0][1]['serviceList']
			
			if not servicelist.count(servicename):
				return -4 # Group is not attached to the service
		else:
			groupname = "dummy"
			print "WARNING: No groupname to the list_service_options_available(). There is no garantee " + \
				"That this will work, som services build there options dynamically from options already set"
		
		import skolesys.services as s
		if not s.groupservices().count(servicename):
			return -2 # the service does not exist
		service_inst = s.create_groupserviceinterface(servicename,groupname)
		if not service_inst:
			return -3 # the service failed to load
		opts_avail = copy.deepcopy((service_inst.get_options_available()))
		cur_options = service_inst.get_options()
		if cur_options:
			for var,val in cur_options.items():
				if opts_avail.has_key(var):
					opts_avail[var]['value'] = val	
		return opts_avail
	def detach_service(self,groupname,servicename):
		"""
		Detach the groupservice servicename from the group groupname
		"""
		res = self.l.search(conf.get('LDAPSERVER','basedn'),\
			ldap.SCOPE_SUBTREE,'(& (cn=%s)(objectclass=skoleSysServiceGroup))'%groupname,['dn','memberuid','servicelist'])
		
		sres = self.l.result(res,0)
		if sres[1]==[]:
			return -1 # Group does not exist
		
		memberlist = []
		if sres[1][0][1].has_key('memberUid'):
			memberlist = sres[1][0][1]['memberUid']
		
		dn = sres[1][0][0]
		servicelist = []
		if sres[1][0][1].has_key('serviceList'):
			servicelist = sres[1][0][1]['serviceList']
		if not servicelist.count(servicename):
			return -4 # service is not enabled
			
		import skolesys.services as s
		if not s.groupservices().count(servicename):
			return -2 # the service does not exist
		
		service_inst = s.create_groupserviceinterface(servicename,groupname)
		if not service_inst:
			return -3 # the service failed to load
		
		print "Detach service %s\non group %s\naffecting users: %s" % (servicename,groupname,','.join(memberlist))
		service_inst.hook_detachservice(memberlist)
		servicelist.remove(servicename)
		self.bind(conf.get('LDAPSERVER','admin'),conf.get('LDAPSERVER','passwd'))
		self.touch_by_dict({dn:{'serviceList': servicelist}})
		return 0