def replyToQuery(ctx, query, bool = None, min = 0, max = 10, justId = False, toH = False, filt = None): if query == None: return [] if __onlyIn(query, ComputerManager().main): ComputerManager().main filt = __addCtxFilters(ctx, filt) filt['query'] = query return xmlrpcCleanup(ComputerManager().getRestrictedComputersList(ctx, min, max, filt, False, justId, toH)) else: return xmlrpcCleanup(QueryManager().replyToQuery(ctx, query, bool, min, max))
def replyToQueryLen(ctx, query, bool = None, filt = None): if query == None: return 0 if __onlyIn(query, ComputerManager().main): ComputerManager().main filt = __addCtxFilters(ctx, filt) filt['query'] = query return xmlrpcCleanup(ComputerManager().getRestrictedComputersListLen(ctx, filt)) else: return xmlrpcCleanup(QueryManager().replyToQueryLen(ctx, query, bool))
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 getMachinesBy(self, table, field, value): ctx = self.currentContext return xmlrpcCleanup( map( lambda m: ComputerLocationManager(). doesUserHaveAccessToMachine(ctx.userid, m[0]), Inventory().getMachinesBy(ctx, table, field, value)))
def setbool_group(self, id, bool, type=0, parent_id=None): if type == 2 and parent_id is not None: # convergence group, get parent group's user context _group_user = DyngroupDatabase()._get_group_user(parent_id) ctx = self.getContext(user=_group_user) else: ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().setbool_group(ctx, id, bool))
def delmembers_to_group(self, id, uuids): ctx = self.currentContext ret = DyngroupDatabase().delmembers_to_group(ctx, id, uuids) # WIP : call ComputerProfileManager to add machines if len(uuids) != 0 and self.isprofile(id): ComputerProfileManager().delComputersFromProfile(uuids, id) return xmlrpcCleanup(ret)
def create_group(self, name, visibility, type=0, parent_id=None): if type == 2 and parent_id is not None: # convergence group, get parent group's user context _group_user = DyngroupDatabase()._get_group_user(parent_id) ctx = self.getContext(user=_group_user) else: ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().create_group(ctx, name, visibility, type, parent_id))
def addmembers_to_group(self, id, uuids): ctx = self.currentContext # remove all the computers that cant be added to a profile from the list didnt_work = [] are_some_to_remove = False if self.isprofile(id): computers = [] uuid2key = {} for c in uuids: computers.append(uuids[c]['uuid']) uuid2key[uuids[c]['uuid']] = c didnt_work = ComputerProfileManager().areForbiddebComputers(computers) if len(didnt_work) > 0: logging.getLogger().debug("Can't add the following computers in that profile %s : %s"%(str(id), str(didnt_work))) for i in didnt_work: if uuid2key[i] in uuids: are_some_to_remove = True uuids.pop(uuid2key[i]) if len(uuids) != 0: if self.isprofile(id): ComputerProfileManager().addComputersToProfile(ctx, uuids, id) else: ret = DyngroupDatabase().addmembers_to_group(ctx, id, uuids) return [ret] return xmlrpcCleanup([not are_some_to_remove, didnt_work])
def get_pull_targets(self): """ Returns list of Pull target UUIDs @return: list """ return xmlrpcCleanup(MscDatabase().getPullTargets())
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_profile_imaging_server(self, gid): if gid == '': return False if not self.isprofile(gid): return False ret = DyngroupDatabase().getProfileImagingServer(gid) return xmlrpcCleanup(ret)
def inventoryExists(self, uuid): ctx = self.currentContext if uuid == '': return False # if not ComputerLocationManager().doesUserHaveAccessToMachine(ctx.userid, uuid): # return False return xmlrpcCleanup(Inventory().inventoryExists(ctx, uuid))
def reload_group(self, id): ctx = self.currentContext ret = DyngroupDatabase().reload_group(ctx, id, queryManager) # WIP : call ComputerProfileManager to add machines # if self.isprofile(id): # ComputerProfileManager().addComputersToProfile(ctx, [1, 2], id) # fake! return xmlrpcCleanup(ret)
def get_profile_entity(self, gid): if gid == '': return False if not self.isprofile(gid): return False ret = DyngroupDatabase().getProfileEntity(gid) return xmlrpcCleanup(ret)
def establish_vnc_proxy(self, scheduler, uuid, requestor_ip): ctx = self.currentContext computer = ComputerManager().getComputer(ctx, {'uuid': uuid}) try: # FIXME: dirty bugfix, should be factorized upstream computer[1]['fullname'] except KeyError: computer[1]['fullname'] = computer[1]['cn'][0] return xmlrpcCleanup(mmc.plugins.msc.client.scheduler.tcp_sproxy(scheduler, computer, requestor_ip, MscConfig().web_vnc_port))
def get_all_commandsonhost_by_currentstate(self, current_state, min=0, max=10, filt=''): ctx = self.currentContext return xmlrpcCleanup(MscDatabase().getAllCommandsonhostByCurrentstate( ctx, current_state, min, max, filt))
def getLastMachineInventoryPart(uuid, part, minbound=0, maxbound=-1, filt=None, options={}): return xmlrpcCleanup(Glpi().getLastMachineInventoryPart( uuid, part, minbound, maxbound, filt, options))
def establish_vnc_proxy(self, scheduler, uuid, requestor_ip): ctx = self.currentContext computer = ComputerManager().getComputer(ctx, {'uuid': uuid}, True) try: # FIXME: dirty bugfix, should be factorized upstream computer[1]['fullname'] except KeyError: computer[1]['fullname'] = computer[1]['cn'][0] return xmlrpcCleanup(mmc.plugins.msc.client.scheduler.tcp_sproxy(scheduler, computer, requestor_ip, MscConfig().web_vnc_port))
def create_group(self, name, visibility, type=0, parent_id=None): if type == 2 and parent_id is not None: # convergence group, get parent group's user context _group_user = DyngroupDatabase()._get_group_user(parent_id) ctx = self.getContext(user=_group_user) else: ctx = self.currentContext return xmlrpcCleanup(DyngroupDatabase().create_group( ctx, name, visibility, type, parent_id))
def getMachinesByDict(self, table, params): ctx = self.currentContext return xmlrpcCleanup( map( lambda m: ComputerLocationManager().doesUserHaveAccessToMachine(ctx.userid, m[0]), Inventory().getMachinesByDict(ctx, table, params), ) )
def replyToQuery(ctx, query, bool=None, min=0, max=10, justId=False, toH=False, filt=None): if query == None: return [] if __onlyIn(query, ComputerManager().main): ComputerManager().main filt = __addCtxFilters(ctx, filt) filt['query'] = query return xmlrpcCleanup(ComputerManager().getRestrictedComputersList( ctx, min, max, filt, False, justId, toH)) else: return xmlrpcCleanup(QueryManager().replyToQuery( ctx, query, bool, min, max))
def add_convergence_datas(self, parent_group_id, deploy_group_id, done_group_id, pid, p_api, command_id, active, params): ret = DyngroupDatabase().add_convergence_datas(parent_group_id, deploy_group_id, done_group_id, pid, p_api, command_id, active, params) return xmlrpcCleanup(ret)
def is_pull_target(self, uuid): """ Returns True if the machine is a known pull client @param uuid: computer UUID @type uuid: str @return: bool """ return xmlrpcCleanup(MscDatabase().isPullTarget(uuid))
def getPossiblesValuesForCriterionInModuleFuzzyWhere(self, moduleName, criterion, value1, value2 = ''): # not used anymore ? ctx = self.currentContext if not isDynamicEnable(): return False result = queryManager.getPossiblesValuesForCriterionInModule(ctx, moduleName, criterion, unescape(value1), unescape(value2)) ret = result[1] # Only returns the 100 first results # FIXME: maybe the range limitation could be done on the queryManager ? ret = ret[:100] return xmlrpcCleanup(ret)
def update_target_ip(self, uuid, ip): """ Updates IP address of all records according to UUID. @param uuid: UUID of machine @type uuid: str @param ip: actualized IP address of machine @type ip: str """ return xmlrpcCleanup(MscDatabase().updateTargetIP(uuid, ip))
def remove_pull_targets(self, uuids): """ remove pull targets @param uuids: a list of uuids to remove @type uuids: list or str @return: True or False :-) """ if isinstance(uuids, basestring): uuids = [uuids] return xmlrpcCleanup(MscDatabase().removePullTargets(uuids))
def getAllMachinesInventoryColumn(self, part, column, pattern={}): ret = self.getLastMachineInventoryPart(part, pattern) # TODO : m.uuid doesn't exists and should do that in just one call retour = [] for machine in ret: name = machine[0] invents = [] for invent in machine[1]: invents.append(invent[column]) retour.append([name, invents]) return xmlrpcCleanup(retour)
def checkLightPullCommands(self, uuid): """ Returns all coh ids te re-execute. @param uuid: uuid of checked computer @type uuid: str @return: coh ids to start @rtype: list """ return xmlrpcCleanup(MscDatabase().checkLightPullCommands(uuid))
def getAllMachinesInventoryColumn(self, part, column, pattern = {}): ret = self.getLastMachineInventoryPart(part, pattern) # TODO : m.uuid doesn't exists and should do that in just one call retour = [] for machine in ret: name = machine[0] invents = [] for invent in machine[1]: invents.append(invent[column]) retour.append([name, invents]) return xmlrpcCleanup(retour)
def getReport(uuid,lang): xsl= XLSGenerator("/var/tmp/report-"+uuid+".xls",lang) xsl.get_summary_sheet(getLastMachineInventoryPart(uuid, "Summary")) xsl.get_hardware_sheet(getLastMachineInventoryPart(uuid, "Processors"), getLastMachineInventoryPart(uuid, "Controllers"), getLastMachineInventoryPart(uuid, 'GraphicCards'), getLastMachineInventoryPart(uuid, 'SoundCards')) xsl.get_network_sheet(getLastMachineInventoryPart(uuid,'Network')) xsl.get_storage_sheet(getLastMachineInventoryPart(uuid, 'Storage')) xsl.get_software_sheet(getLastMachineInventoryPart(uuid, 'Softwares',0,-1,None,{"hide_win_updates":True})) xsl.save() return xmlrpcCleanup(xsl.path)
def getLastMachineInventoryPart(uuid, part, minbound=0, maxbound=-1, filt=None, options={}): return xmlrpcCleanup(Glpi().getLastMachineInventoryPart(uuid, part, minbound, maxbound, filt, options))
def getReport(self,uuid,lang): xsl= XLSGenerator("/var/tmp/report-"+uuid+".xls",lang) xsl.get_summary_sheet(self.getLastMachineInventoryPart2('Summary', {"uuid":uuid})) xsl.get_hardware_sheet(self.getLastMachineInventoryPart2("Processors", {"uuid":uuid}), self.getLastMachineInventoryPart2('Controllers', {"uuid":uuid}), self.getLastMachineInventoryPart2('GraphicCards', {"uuid":uuid}), self.getLastMachineInventoryPart2('SoundCards', {"uuid":uuid})) xsl.get_network_sheet(self.getLastMachineInventoryPart2('Network', {"uuid":uuid})) xsl.get_storage_sheet(self.getLastMachineInventoryPart2('Storage', {"uuid":uuid})) # TODO : adapt Inventory().getLastMachineInventoryPart2 to Software part #xsl.get_software_sheet(self.getLastMachineInventoryPart2('Software', {"uuid":uuid, "hide_win_updates":True})) xsl.save() return xmlrpcCleanup(xsl.path)
def get_all_commands_for_consult(self, min=0, max=10, filt='', expired=True): ctx = self.currentContext size, ret1 = MscDatabase().getAllCommandsConsult( ctx, min, max, filt, expired) ret = [] logger = logging.getLogger() cache = {} for c in ret1: if c['gid']: if cache.has_key("G%s" % (c['gid'])): #if "G%s"%(c['gid']) in cache: c['target'] = cache["G%s" % (c['gid'])] else: group = DyngroupDatabase().get_group(ctx, c['gid'], True) if type( group ) == bool: # we dont have the permission to view the group c['target'] = 'UNVISIBLEGROUP' # TODO! elif group == None: c['target'] = 'this group has been deleted' elif hasattr(group, 'ro') and group.ro: logger.debug("user %s access to group %s in RO mode" % (ctx.userid, group.name)) c['target'] = group.name else: c['target'] = group.name cache["G%s" % (c['gid'])] = c['target'] else: if cache.has_key("M%s" % (c['uuid'])): #if "M%s"%(c['uuid']) in cache: c['target'] = cache["M%s" % (c['uuid'])] else: if not ComputerLocationManager( ).doesUserHaveAccessToMachine(ctx, c['uuid']): c['target'] = "UNVISIBLEMACHINE" elif not ComputerManager().getComputer( ctx, {'uuid': c['uuid']}): c['target'] = "UNVISIBLEMACHINE" cache["M%s" % (c['uuid'])] = c['target'] # treat c['title'] to remove the date when possible # "Bundle (1) - 2009/12/14 10:22:24" => "Bundle (1)" date_re = re.compile(" - \d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d") c['title'] = date_re.sub('', c['title']) ret.append(c) return xmlrpcCleanup((size, ret))
def update_target_ip(self, uuid, ip, netmask): """ Updates IP address of all records according to UUID. @param uuid: UUID of machine @type uuid: str @param ip: actualized IP address of machine @type ip: str @param netmask: actualized netmask of machine @type netmask: str """ self.ip_table[uuid] = ip return xmlrpcCleanup(MscDatabase().updateTargetIP(uuid, ip, netmask))
def _get_convergence_soon_ended_commands(all=False): """ @param all: If True, get all convergence active commands @type all: Bool @return: list of soon ended convergence commands @rtype: list """ ret = [] cmd_ids = all and [] or MscDatabase()._get_convergence_soon_ended_commands() if cmd_ids or all: # Get active commands only if there is any cmd_ids # or if we want all active commands ret = DyngroupDatabase()._get_convergence_active_commands_ids(cmd_ids=cmd_ids) return xmlrpcCleanup(ret)
def getAllMachinesInventoryColumn(self, part, column, pattern = {}): ctx = self.currentContext ret = self.getLastMachineInventoryPart(part, pattern) # TODO : m.uuid doesn't exists and should do that in just one call retour = [] for machine in ret: name = machine[0] uuid = machine[2] # if not ComputerLocationManager().doesUserHaveAccessToMachine(ctx.userid, uuid): # continue invents = [] for invent in machine[1]: invents.append(invent[column]) retour.append([name, invents]) return xmlrpcCleanup(retour)
def pull_target_awake(self, hostname, macs): """ Gets the requested machine for UUID. @param hostname: hostname of computer @type hostname: str @param macs: MAC addresses of computer @type macs: list @return: UUID @rtype: str """ ctx = self.currentContext return xmlrpcCleanup(ComputerManager().getComputerByHostnameAndMacs( ctx, hostname, macs))
def getPossiblesValuesForCriterionInModuleFuzzyWhere(self, moduleName, criterion, value1, value2 = ''): """ Used in "double" type. It's used where you search on 2 fields of a table. Example: On table Software, you can search on ProductName and ProductVersion This function is related to field 2 """ ctx = self.currentContext if not isDynamicEnable(): return False result = queryManager.getPossiblesValuesForCriterionInModule(ctx, moduleName, criterion, unescape(value1), unescape(value2)) ret = result[1] # Only returns the 100 first results # FIXME: maybe the range limitation could be done on the queryManager ? ret = ret[:100] return xmlrpcCleanup(ret)
def getReport(self, uuid, lang): xsl = XLSGenerator("/var/tmp/report-" + uuid + ".xls", lang) xsl.get_summary_sheet( self.getLastMachineInventoryPart2('Summary', {"uuid": uuid})) xsl.get_hardware_sheet( self.getLastMachineInventoryPart2("Processors", {"uuid": uuid}), self.getLastMachineInventoryPart2('Controllers', {"uuid": uuid}), self.getLastMachineInventoryPart2('GraphicCards', {"uuid": uuid}), self.getLastMachineInventoryPart2('SoundCards', {"uuid": uuid})) xsl.get_network_sheet( self.getLastMachineInventoryPart2('Network', {"uuid": uuid})) xsl.get_storage_sheet( self.getLastMachineInventoryPart2('Storage', {"uuid": uuid})) # TODO : adapt Inventory().getLastMachineInventoryPart2 to Software part #xsl.get_software_sheet(self.getLastMachineInventoryPart2('Software', {"uuid":uuid, "hide_win_updates":True})) xsl.save() return xmlrpcCleanup(xsl.path)
def pull_target_awake(self, hostname, macs): """ Gets the requested machine for UUID. @param hostname: hostname of computer @type hostname: str @param macs: MAC addresses of computer @type macs: list @return: UUID @rtype: str """ ctx = self.currentContext return xmlrpcCleanup(ComputerManager().getComputerByHostnameAndMacs(ctx, hostname, macs))
def _get_convergence_soon_ended_commands(all=False): """ @param all: If True, get all convergence active commands @type all: Bool @return: list of soon ended convergence commands @rtype: list """ ret = [] active_convergence_cmd_ids = DyngroupDatabase()._get_convergence_active_commands_ids() if all: # Return all active_convergence_cmd_ids return active_convergence_cmd_ids elif active_convergence_cmd_ids: # Get active_convergence_cmd_ids who are soon expired ret = MscDatabase()._get_convergence_soon_ended_commands(cmd_ids=active_convergence_cmd_ids) return xmlrpcCleanup(ret)
def getPossiblesValuesForCriterionInModuleFuzzyWhere( self, moduleName, criterion, value1, value2=''): """ Used in "double" type. It's used where you search on 2 fields of a table. Example: On table Software, you can search on ProductName and ProductVersion This function is related to field 2 """ ctx = self.currentContext if not isDynamicEnable(): return False result = queryManager.getPossiblesValuesForCriterionInModule( ctx, moduleName, criterion, unescape(value1), unescape(value2)) ret = result[1] # Only returns the 100 first results # FIXME: maybe the range limitation could be done on the queryManager ? ret = ret[:100] return xmlrpcCleanup(ret)
def getLicensesCount(vendor, software, version): ctx = SecurityContext() ctx.userid = "root" def replace_splat(param): if '*' in param: return param.replace('*', '%') return param def check_param(param): if param == '' or param == '*' or param == '%': return None return replace_splat(param) software = check_param(software) vendor = check_param(vendor) version = check_param(version) if software is None: software = '%' return xmlrpcCleanup(Inventory().getAllSoftwaresImproved(ctx, software, vendor=vendor, version=version, count=1))
def getMachineNumberByState(self): ctx = self.currentContext return xmlrpcCleanup(Inventory().getMachineNumberByState(ctx))
def getMachines(self, pattern=None): ctx = self.currentContext return xmlrpcCleanup(Inventory().getMachines(ctx, pattern))
def getMachineInventoryDiff(self, params): ctx = self.currentContext # Use xmlrpcCleanup to clean all None values return xmlrpcCleanup(Inventory().getComputerInventoryDiff(ctx, params))
def getInventoryHistory(days, only_new, pattern, max, min): # Use xmlrpcCleanup to clean the date values return xmlrpcCleanup(Inventory().getInventoryHistory( days, only_new, pattern, max, min))
def getLastMachineInventoryPart2(self, part, params): ctx = self.currentContext # uuid = name # TODO : get uuid from name, or something like that... # ComputerLocationManager().doesUserHaveAccessToMachine(ctx.userid, uuid) return xmlrpcCleanup(Inventory().getLastMachineInventoryPart2( ctx, part, params))
def getMachineByHostnameAndMacs(self, hostname, macs): ctx = self.currentContext return xmlrpcCleanup(Inventory().getMachineByHostnameAndMacs( ctx, hostname, macs))
def getMachineInventoryHistory(self, params): ctx = self.currentContext return xmlrpcCleanup(Inventory().getComputerInventoryHistory( ctx, params))
def getMachineByOwner(self, user): ctx = self.currentContext return xmlrpcCleanup(Inventory().getMachineByOwner(ctx, user))
def getLastMachineInventoryFull(self, params): ctx = self.currentContext # if not ComputerLocationManager().doesUserHaveAccessToMachine(ctx.userid, uuid): # return False return xmlrpcCleanup(Inventory().getLastMachineInventoryFull( ctx, params))
def getMachineListByState(self, groupName): ctx = self.currentContext return xmlrpcCleanup(Inventory().getMachineListByState(ctx, groupName))