def delete_group(self, id): ctx = self.currentContext if self.isprofile(id): grp = DyngroupDatabase().get_group(ctx, id, True) profile_UUID = grp.getUUID() ComputerProfileManager().delProfile(profile_UUID) return xmlrpcCleanup(DyngroupDatabase().delete_group(ctx, id))
def get_group(self, id, ro=False, root_context=False): grp = DyngroupDatabase().get_group(self.getContext(), id) if grp.type == 2: _group_user = DyngroupDatabase()._get_group_user(grp.parent_id) ctx = self.getContext(user=_group_user) else: ctx = root_context and self.getContext() or self.currentContext grp = DyngroupDatabase().get_group(ctx, id, ro) if grp: return xmlrpcCleanup(grp.toH()) return xmlrpcCleanup(False)
def checkPool(): ret = True try : pool = DyngroupDatabase().db.pool if pool._max_overflow > -1 and pool._overflow >= pool._max_overflow : logging.getLogger().error('dyngroup plugin: CHECK: NOK: timeout then overflow (%d vs. %d) detected in SQL pool : check your network connectivity !' % (pool._overflow, pool._max_overflow)) pool.dispose() pool = pool.recreate() ret = False except Exception, e: logging.getLogger().warn('dyngroup plugin: CHECK: NOK: got the following error : %s' % (e)) ret = False
def update_machine_cache(self): ctx = self.currentContext dyndatabase = DyngroupDatabase() cache = dyndatabase.getAllMachinesUuid() machines = ComputerManager().getRestrictedComputersList(ctx, 0, -1, {'uuids':cache.keys()}, False, False, True) need_update = {} for m in machines: if m['hostname'] != cache[m['uuid']]: need_update[m['uuid']] = m['hostname'] dyndatabase.updateNewNames(need_update) return len(need_update)
class DyngroupComputers(ComputerI): # don't know how to do something else than delComputer. def __init__(self, conffile = None): self.logger = logging.getLogger() self.dyngroup = DyngroupDatabase() def getComputer(self, ctx, filt = None): return {} def getMachineMac(self, ctx, filt): # TODO : need to sort! return None def getMachineIp(self, ctx, filt): # TODO : need to sort! return None def getComputersNetwork(self, ctx, filt): return None def getComputersList(self, ctx, filt = None): return [] def getRestrictedComputersListLen(self, ctx, filt = {}): #Mutable dict filt used as default argument to a method or function return 0 def getRestrictedComputersList(self, ctx, min = 0, max = -1, filt = {}, advanced = True, justId = False, toH = False): #Mutable dict filt used as default argument to a method or function return [] def getComputerCount(self, ctx, filt = None): return 0 def canAddComputer(self): return False def canAssociateComputer2Location(self): return False def addComputer(self, ctx, params): return -1 def neededParamsAddComputer(self): return [] def canDelComputer(self): return True def delComputer(self, ctx, uuid, backup): return self.dyngroup.delMachine(uuid) def getComputersListHeaders(self, ctx): return []
def share_with(self, id): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().share_with(ctx, id))
def del_share(self, id, shares): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().del_share(ctx, id, shares))
def set_profile_imaging_server(self, gid, imaging_uuid): if not self.isprofile(gid): return False dyndatabase = DyngroupDatabase() ret = dyndatabase.setProfileImagingServer(gid, imaging_uuid) return xmlrpcCleanup(ret)
def countallprofiles(self, params): #NEW ctx = self.currentContext count = DyngroupDatabase().countallgroups(ctx, params, 1) return count
def _get_convergence_deploy_group_id_and_user(cmd_id): return DyngroupDatabase()._get_convergence_deploy_group_id_and_user(cmd_id)
def group_name_exists(self, name, gid=None): #TODO possible risks of collision betwen share/group/profiles... ctx = self.currentContext return DyngroupDatabase().groupNameExists(ctx, name, gid)
def setbool_group(self, id, bool): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().setbool_group(ctx, id, bool))
def set_profile_entity(self, gid, entity_uuid): if not self.isprofile(gid): return False dyndatabase = DyngroupDatabase() ret = dyndatabase.setProfileEntity(gid, entity_uuid) return xmlrpcCleanup(ret)
def setvisibility_group(self, id, visibility): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().setvisibility_group( ctx, id, visibility))
def setrequest_group(self, id, request): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().setrequest_group( ctx, id, request))
def setname_group(self, id, name): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().setname_group(ctx, id, name))
def create_profile(self, name, visibility): #NEW ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().create_group( ctx, name, visibility, 1))
def get_group(self, id, ro=False): ctx = self.currentContext grp = DyngroupDatabase().get_group(ctx, id, ro) if grp: return xmlrpcCleanup(grp.toH()) return xmlrpcCleanup(False)
def can_edit(self, id): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().can_edit(ctx, id))
def getallgroups(self, params): ctx = self.currentContext groups = DyngroupDatabase().getallgroups(ctx, params) return xmlrpcCleanup(map(lambda g: g.toH(), groups))
def getmachineprofile(self, id): #NEW ctx = self.currentContext profile = DyngroupDatabase().getMachineProfile(ctx, id) return xmlrpcCleanup(profile)
def _get_convergence_phases(cmd_id, deploy_group_id): return DyngroupDatabase()._get_convergence_phases(cmd_id, deploy_group_id)
def countallgroups(self, params): ctx = self.currentContext count = DyngroupDatabase().countallgroups(ctx, params) return count
def requestresult_group(self, id, start, end, filter): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().requestresult_group( ctx, id, start, end, filter, queryManager))
def profile_name_exists(self, name, gid=None): ctx = self.currentContext return DyngroupDatabase().groupNameExists(ctx, name, gid, True)
def __init__(self, conffile = None): self.logger = logging.getLogger() self.dyngroup = DyngroupDatabase()
def countresult_group(self, id, filter): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().countresult_group( ctx, id, filter))
def get_group(self, id, ro=False, root_context=False): ctx = root_context and self.getContext() or self.currentContext grp = DyngroupDatabase().get_group(ctx, id, ro) if grp: return xmlrpcCleanup(grp.toH()) return xmlrpcCleanup(False)
def todyn_group(self, id): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().todyn_group(ctx, id))
def isrequest_group(self, id): ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().isrequest_group(ctx, id))
def isprofile(self, id): #NEW ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().isprofile(ctx, id))
def arePartOfAProfile(self, uuids): ctx = self.currentContext return DyngroupDatabase().arePartOfAProfile(ctx, uuids)