def get_machines_update_status(): """ Get machine update status as a dict as key and status string as value. commons status values :"unknown","up-to-date","need_update","update_available", "update_planned" """ # Creating root context ctx = SecurityContext() ctx.userid = 'root' machines_status = {} uuids = [] # get computer list who returned update machines_update = updateDatabase().get_machines() # get uuid for all computer ComputerList = ComputerManager().getComputersList(ctx, {}).keys() uuids = [] for uuid in ComputerList: uuids.append(int(uuid.lower().replace('uuid', ''))) #get status of all machines for uuid in uuids: if uuid in machines_update: if len(updateDatabase().get_neutral_updates_for_host(uuid)) == 0: if len(updateDatabase().get_eligible_updates_for_host(uuid)) == 0: machines_status["UUID" + str(uuid)] = "up-to-date" else: machines_status["UUID" + str(uuid)] = "update_planned" else: machines_status["UUID" + str(uuid)] = "update_available" else: machines_status["UUID" + str(uuid)] = "unknown" return machines_status
def set_update_status_for_group(gid, update_ids, status): """ Set updates status for one define group of machine, for multiples defines update to status param value. This does not affect global status of update """ for update_id in update_ids: updateDatabase().set_update_status_for_group(gid, update_id, status) return True
def get_machines_update_status(not_supported=False): """ Get machine update status as a dict as key and status string as value. commons status values :"not_supported","not_registered", "up-to-date","need_update","update_available","update_planned", "os_update_disabled". The "not_supported" value can be disabled with not_supported param. """ # Creating root context ctx = SecurityContext() ctx.userid = 'root' machines_status = {} uuids = [] # get computer list who returned update machines_update = updateDatabase().get_machines() # get activated os computers: machines_os_enabled = _get_updatable_computers(ctx, activated=True) # get disabled os computers: machines_os_disabled = _get_updatable_computers(ctx, activated=False) # get uuid for all computer ComputerList = ComputerManager().getComputersList(ctx, {}).keys() uuids = [] # convert uuid as string number for uuid in ComputerList: uuids.append(int(uuid.lower().replace('uuid', ''))) machines_os_enabled = [ int(uuid.lower().replace('uuid', '')) for uuid in machines_os_enabled ] machines_os_disabled = [ int(uuid.lower().replace('uuid', '')) for uuid in machines_os_disabled ] # get status of all machines for uuid in uuids: if uuid in machines_os_disabled: machines_status["UUID" + str(uuid)] = "os_update_disabled" elif uuid in machines_os_enabled: if uuid in machines_update: # if no neutral update not installed on this machine if len(updateDatabase().get_neutral_updates_for_host(uuid, 0)) == 0: # if no eligible update if len(updateDatabase().get_eligible_updates_for_host( uuid)) == 0: machines_status["UUID" + str(uuid)] = "up-to-date" else: machines_status["UUID" + str(uuid)] = "update_planned" else: machines_status["UUID" + str(uuid)] = "update_available" else: machines_status["UUID" + str(uuid)] = "not_registered" elif not_supported: machines_status["UUID" + str(uuid)] = "not_supported" return machines_status
def get_machines_update_status(not_supported=False): """ Get machine update status as a dict as key and status string as value. commons status values :"not_supported","not_registered", "up-to-date","need_update","update_available","update_planned", "os_update_disabled". The "not_supported" value can be disabled with not_supported param. """ # Creating root context ctx = SecurityContext() ctx.userid = 'root' machines_status = {} uuids = [] # get computer list who returned update machines_update = updateDatabase().get_machines() # get activated os computers: machines_os_enabled = _get_updatable_computers(ctx, activated=True) # get disabled os computers: machines_os_disabled = _get_updatable_computers(ctx, activated=False) # get uuid for all computer ComputerList = ComputerManager().getComputersList(ctx, {}).keys() uuids = [] # convert uuid as string number for uuid in ComputerList: uuids.append(int(uuid.lower().replace('uuid', ''))) machines_os_enabled = [ int(uuid.lower().replace('uuid', '')) for uuid in machines_os_enabled] machines_os_disabled = [ int(uuid.lower().replace('uuid', '')) for uuid in machines_os_disabled] # get status of all machines for uuid in uuids: if uuid in machines_os_disabled: machines_status["UUID" + str(uuid)] = "os_update_disabled" elif uuid in machines_os_enabled: if uuid in machines_update: # if no neutral update not installed on this machine if len(updateDatabase().get_neutral_updates_for_host(uuid, 0)) == 0: # if no eligible update if len(updateDatabase().get_eligible_updates_for_host(uuid)) == 0: machines_status["UUID" + str(uuid)] = "up-to-date" else: machines_status["UUID" + str(uuid)] = "update_planned" else: machines_status["UUID" + str(uuid)] = "update_available" else: machines_status["UUID" + str(uuid)] = "not_registered" elif not_supported: machines_status["UUID" + str(uuid)] = "not_supported" return machines_status
def create_update_commands(): # TODO: ensure that this method is called by taskmanager # and not directly by XMLRPC # Creating root context ctx = SecurityContext() ctx.userid = 'root' # Get active computer manager computer_manager = ComputerManager().getManagerName() if computer_manager == 'inventory': dyngroup_pattern = '%d==inventory::Hardware/OperatingSystem==%s' elif computer_manager == 'glpi': dyngroup_pattern = '%d==glpi::Operating system==%s' else: logging.getLogger().error( 'Update module: Unsupported computer manager %s' % computer_manager) return False # Get all enabled os_classes os_classes = updateDatabase().get_os_classes({'filters': {'enabled': 1}}) # Create update command for enabled os_classes for os_class in os_classes['data']: patterns = os_class['pattern'].split('||') request = [] equ_bool = [] for i in xrange(len(patterns)): request.append(dyngroup_pattern % (i + 1, patterns[i])) equ_bool.append(str(i + 1)) request = '||'.join(request) equ_bool = 'OR(%s)' % ','.join(equ_bool) targets = ComputerManager().getComputersList(ctx, { 'request': request, 'equ_bool': equ_bool }).keys() # Fetching all targets for uuid in targets: machine_id = int(uuid.lower().replace('uuid', '')) updates = updateDatabase().get_eligible_updates_for_host( machine_id) update_list = [update['uuid'] for update in updates] # Create update command for this host with update_list create_update_command(ctx, [uuid], update_list) return True
def create_update_commands(): # TODO: ensure that this method is called by taskmanager # and not directly by XMLRPC # Creating root context ctx = SecurityContext() ctx.userid = 'root' # Get active computer manager computer_manager = ComputerManager().getManagerName() if computer_manager == 'inventory': dyngroup_pattern = '%d==inventory::Hardware/OperatingSystem==%s' elif computer_manager == 'glpi': dyngroup_pattern = '%d==glpi::Operating system==%s' else: logging.getLogger().error( 'Update module: Unsupported computer manager %s' % computer_manager) return False # Get all enabled os_classes os_classes = updateDatabase().get_os_classes({'filters': {'enabled': 1}}) # Create update command for enabled os_classes for os_class in os_classes['data']: patterns = os_class['pattern'].split('||') request = [] equ_bool = [] for i in xrange(len(patterns)): request.append(dyngroup_pattern % (i + 1, patterns[i])) equ_bool.append(str(i + 1)) request = '||'.join(request) equ_bool = 'OR(%s)' % ','.join(equ_bool) targets = ComputerManager().getComputersList( ctx, { 'request': request, 'equ_bool': equ_bool}).keys() # Fetching all targets for uuid in targets: machine_id = int(uuid.lower().replace('uuid', '')) updates = updateDatabase().get_eligible_updates_for_host( machine_id) update_list = [update['uuid'] for update in updates] # Create update command for this host with update_list create_update_command(ctx, [uuid], update_list) return True
def _get_updatable_computers(ctx, activated=True): # Get active computer manager computer_manager = ComputerManager().getManagerName() if computer_manager == 'inventory': dyngroup_pattern = '%d==inventory::Hardware/OperatingSystem==%s' elif computer_manager == 'glpi': dyngroup_pattern = '%d==glpi::Operating system==%s' else: logging.getLogger().error( 'Update module: Unsupported computer manager %s' % computer_manager) return False # Get all enabled os_classes if activated: os_classes = updateDatabase().get_os_classes( {'filters': { 'enabled': 1 }}) else: os_classes = updateDatabase().get_os_classes( {'filters': { 'enabled': 0 }}) targets = [] # Create update command for enabled os_classes for os_class in os_classes['data']: patterns = os_class['pattern'].split('||') request = [] equ_bool = [] for i in xrange(len(patterns)): request.append(dyngroup_pattern % (i + 1, patterns[i])) equ_bool.append(str(i + 1)) request = '||'.join(request) equ_bool = 'OR(%s)' % ','.join(equ_bool) targets.extend(ComputerManager().getComputersList( ctx, { 'request': request, 'equ_bool': equ_bool }).keys()) return targets
def activate(): config = updateConfig("update") if config.disabled: logger.warning("Plugin UpdateMgr: disabled by configuration.") return False if not updateDatabase().activate(config): logger.error("UpdateMgr database not activated") return False return True
def get_updates(params): """ Get updates standard function, if gid or uuids is defined group view is used else global view is used """ if ('gid' or 'uuids') in params: return _get_updates_for_group(params) else: return updateDatabase().get_updates(params)
def _get_updatable_computers(ctx, activated=True): # Get active computer manager computer_manager = ComputerManager().getManagerName() if computer_manager == 'inventory': dyngroup_pattern = '%d==inventory::Hardware/OperatingSystem==%s' elif computer_manager == 'glpi': dyngroup_pattern = '%d==glpi::Operating system==%s' else: logging.getLogger().error( 'Update module: Unsupported computer manager %s' % computer_manager) return False # Get all enabled os_classes if activated: os_classes = updateDatabase().get_os_classes( {'filters': {'enabled': 1}}) else: os_classes = updateDatabase().get_os_classes( {'filters': {'enabled': 0}}) targets = [] # Create update command for enabled os_classes for os_class in os_classes['data']: patterns = os_class['pattern'].split('||') request = [] equ_bool = [] for i in xrange(len(patterns)): request.append(dyngroup_pattern % (i + 1, patterns[i])) equ_bool.append(str(i + 1)) request = '||'.join(request) equ_bool = 'OR(%s)' % ','.join(equ_bool) targets.extend(ComputerManager().getComputersList( ctx, { 'request': request, 'equ_bool': equ_bool}).keys()) return targets
def activate(): config = updateConfig("update") if config.disabled: logger.warning("Plugin UpdateMgr: disabled by configuration.") return False if not updateDatabase().activate(config): logger.error("UpdateMgr database not activated") return False # Add create update commands in the task manager if config.enable_update_commands: TaskManager().addTask("update.create_update_commands", (create_update_commands,), cron_expression=config.update_commands_cron) return True
def activate(): config = updateConfig("update") if config.disabled: logger.warning("Plugin UpdateMgr: disabled by configuration.") return False if not updateDatabase().activate(config): logger.error("UpdateMgr database not activated") return False DashboardManager().register_panel(Panel('product_updates')) # Add create update commands in the task manager if config.enable_update_commands: TaskManager().addTask("update.create_update_commands", (create_update_commands, ), cron_expression=config.update_commands_cron) return True
def create_update_commands(): # TODO: ensure that this method is called by taskmanager # and not directly by XMLRPC # Creating root context ctx = SecurityContext() ctx.userid = 'root' targets = _get_updatable_computers(ctx) # Fetching all targets for uuid in targets: machine_id = int(uuid.lower().replace('uuid', '')) updates = updateDatabase().get_eligible_updates_for_host(machine_id) update_list = [update['uuid'] for update in updates] # Create update command for this host with update_list create_update_command(ctx, [uuid], update_list) return True
def create_update_commands(): # TODO: ensure that this method is called by taskmanager # and not directly by XMLRPC # Creating root context ctx = SecurityContext() ctx.userid = 'root' targets = _get_updatable_computers(ctx) # Fetching all targets for uuid in targets: machine_id = int(uuid.lower().replace('uuid', '')) updates = updateDatabase().get_eligible_updates_for_host( machine_id) update_list = [update['uuid'] for update in updates] # Create update command for this host with update_list create_update_command(ctx, [uuid], update_list) return True
def _get_updates_for_group(params): """ Get updates from uuids list if params['uuids'] is a correct list of uuid and from group if params['gid'] is a correct group id """ if 'gid' in params: params['uuids'] = [] # Creating root context ctx = SecurityContext() ctx.userid = 'root' # get uuid for all computer of this group ComputerList = ComputerGroupManager().get_group_results( ctx, params['gid'], 0, -1, {}) for uuid in ComputerList: params['uuids'].append(int(uuid.lower().replace('uuid', ''))) # get updates for this group updates = updateDatabase().get_updates_for_group(params) return updates
def activate(): config = updateConfig("update") if config.disabled: logger.warning("Plugin UpdateMgr: disabled by configuration.") return False if not updateDatabase().activate(config): logger.error("UpdateMgr database not activated") return False DashboardManager().register_panel(Panel('product_updates')) DashboardManager().register_panel(Panel('clients_updates')) # Add create update commands in the task manager if config.enable_update_commands: TaskManager().addTask("update.create_update_commands", (create_update_commands,), cron_expression=config.update_commands_cron) if config.enable_update_description: TaskManager().addTask("add_update_description", (add_update_description,), cron_expression=config.add_update_description_cron) return True
def set_update_status(update_id, status): """ Set global status of one update """ return updateDatabase().set_update_status(update_id, status)
def add_update_description(): return updateDatabase().add_update_description()
def get_update_conflicts_for_host(uuid): return updateDatabase().get_update_conflicts_for_host(uuid)
def get_os_classes(params): return updateDatabase().get_os_classes(params)
def calldb(func, *args, **kw): return getattr(updateDatabase(), func).__call__(*args, **kw)
def enable_only_os_classes(os_classes_ids): """ Enable spacified os_classes and disble others """ return updateDatabase().enable_only_os_classes(os_classes_ids)
def get_updates(params): return updateDatabase().get_updates(params)
def set_update_status(update_id, status): return updateDatabase().set_update_status(update_id, status)