def __getPolTypes(self, granularity, status=None, formerStatus=None, newStatus=None, siteType=None, serviceType=None, resourceType=None): """Get Policy Types from config that match the given keyword arguments""" # This dict is constructed to be used with function dictMatch that # helps selecting policies. **kwargs are not used due to the fact # that it's too dangerous here. argsdict = {'Granularity': granularity, 'Status': status, 'FormerStatus': formerStatus, 'NewStatus': newStatus, 'SiteType': siteType, 'ServiceType': serviceType, 'ResourceType': resourceType} pTconfig = getTypedDictRootedAt("PolicyTypes") pTypes = [] for pt in pTconfig: if Utils.dictMatch(argsdict, pTconfig[pt]): pTypes.append(pt) for pt_name in pTypes: if 'Alarm_PolType' in pt_name: pTypes.remove(pt_name) pTypes.append('Alarm_PolType') return pTypes
def __getPanelsInfo( self, granularity, statusType = None, status = None, formerStatus = None, siteType = None, serviceType = None, resourceType = None, panel_name = None, useNewRes = False ): info = [] # First, select only policies we want. argsdict = {'Granularity' : granularity, 'StatusType' : statusType, 'Status' : status, 'FormerStatus' : formerStatus, 'SiteType' : siteType, 'ServiceType' : serviceType, 'ResourceType' : resourceType} all_policies = getTypedDictRootedAtOperations("Policies") selected_policies = [] for p in all_policies: if Utils.dictMatch(argsdict, all_policies[p]): selected_policies.append(p) for p in selected_policies: # For selected policies if panel_name in self.C_Policies[p].keys(): # For selected panel_name (arguments) toAppend = copy.deepcopy(self.C_Policies[p][panel_name]) # type(toAppend) = list # Put CommandIn and args to correct values according to useNewRes if useNewRes: for panel in toAppend: for info_type in panel.keys(): if type(panel[info_type]) == dict: try: panel[info_type]['CommandIn'] = panel[info_type]['CommandInNewRes'] del panel[info_type]['CommandInNewRes'] except KeyError: pass try: panel[info_type]['args'] = panel[info_type]['argsNewRes'] del panel[info_type]['argsNewRes'] except KeyError: pass else: for panel in toAppend: for info_type in panel.keys(): try: del panel[info_type]['CommandInNewRes'] except KeyError: pass try: del panel[info_type]['argsNewRes'] except KeyError: pass info.append({p:toAppend}) return info
def _getUsersToNotify(self): groups = CS.getTypedDictRootedAtOperations("AssigneeGroups/" + CS.getSetup()).values() concerned_groups = [ g for g in groups if Utils.dictMatch(self.kw["Params"], g) ] return [{ 'Users': g['Users'], 'Notifications': g['Notifications'] } for g in concerned_groups]
def __getPolToEval(self, granularity, status=None, formerStatus=None, siteType=None, serviceType=None, resourceType=None, useNewRes=False): # This dict is constructed to be used with function dictMatch that # helps selecting policies. **kwargs are not used due to the fact # that it's too dangerous here. argsdict = {'Granularity': granularity, 'Status': status, 'FormerStatus': formerStatus, 'SiteType': siteType, 'ServiceType': serviceType, 'ResourceType': resourceType} pConfig = getTypedDictRootedAt("Policies") pol_to_eval = [] for p in pConfig: if Utils.dictMatch(argsdict, pConfig[p]): pol_to_eval.append(p) polToEval_Args = [] for p in pol_to_eval: try: moduleName = self.C_Policies[p]['module'] except KeyError: moduleName = None try: ConfirmationPolicy = self.C_Policies[p]['ConfirmationPolicy'] except KeyError: ConfirmationPolicy = None if useNewRes: try: commandIn = self.C_Policies[p]['commandInNewRes'] except KeyError: commandIn = self.C_Policies[p]['commandIn'] try: args = self.C_Policies[p]['argsNewRes'] except KeyError: args = self.C_Policies[p]['args'] else: commandIn = self.C_Policies[p]['commandIn'] args = self.C_Policies[p]['args'] polToEval_Args.append({'Name' : p, 'Module' : moduleName, 'args' : args, 'ConfirmationPolicy' : ConfirmationPolicy, 'commandIn' : commandIn}) return polToEval_Args
def __getPolToEval( self, granularity, statusType = None, status=None, formerStatus=None, siteType=None, serviceType=None, resourceType=None, useNewRes=False ): """Returns a possibly empty list of dicts, each dict containing enough information to evaluate a given policy""" # This dict is constructed to be used with function dictMatch that # helps selecting policies. **kwargs are not used due to the fact # that it's too dangerous here. argsdict = { 'Granularity' : granularity, 'StatusType' : statusType, 'Status' : status, 'FormerStatus' : formerStatus, 'SiteType' : siteType, 'ServiceType' : serviceType, 'ResourceType' : resourceType } pConfig = getTypedDictRootedAtOperations("Policies") pol_to_eval = (p for p in pConfig if Utils.dictMatch(argsdict, pConfig[p])) polToEval_Args = [] for p in pol_to_eval: try: moduleName = self.C_Policies[p]['module'] except KeyError: moduleName = None try: ConfirmationPolicy = self.C_Policies[p]['ConfirmationPolicy'] except KeyError: ConfirmationPolicy = None if useNewRes: try: commandIn = self.C_Policies[p]['commandInNewRes'] except KeyError: commandIn = self.C_Policies[p]['commandIn'] try: args = self.C_Policies[p]['argsNewRes'] except KeyError: args = self.C_Policies[p]['args'] else: commandIn = self.C_Policies[p]['commandIn'] args = self.C_Policies[p]['args'] polToEval_Args.append({'Name' : p, 'Module' : moduleName, 'args' : args, 'ConfirmationPolicy' : ConfirmationPolicy, 'commandIn' : commandIn}) return polToEval_Args
def getUsersToNotify(setup, kwargs): """Get a list of users to notify (helper function for AlarmPolTypeActions) Optional keyword arguments: - Granularity - SiteType - ServiceType - ResourceType """ notifications = [] groups = CS.getTypedDictRootedAt("AssigneeGroups/" + setup) for k in groups: if Utils.dictMatch(kwargs, groups[k]): notifications.append({ 'Users': groups[k]['Users'], 'Notifications': groups[k]['Notifications'] }) return notifications
def __getPolTypes( self, granularity, statusType=None, status=None, formerStatus=None, newStatus=None, siteType=None, serviceType=None, resourceType=None ): """Get Policy Types from config that match the given keyword arguments. Always returns a generator object, possibly empty.""" # This dict is constructed to be used with function dictMatch that # helps selecting policies. **kwargs are not used due to the fact # that it's too dangerous here. argsdict = {'Granularity' : granularity, 'StatusType' : statusType, 'Status' : status, 'FormerStatus' : formerStatus, 'NewStatus' : newStatus, 'SiteType' : siteType, 'ServiceType' : serviceType, 'ResourceType' : resourceType } pTconfig = RssConfiguration.getValidPolicyTypes() return (pt for pt in pTconfig if Utils.dictMatch(argsdict, pTconfig[pt]))
def __getPolTypes(self, granularity, status=None, formerStatus=None, newStatus=None, siteType=None, serviceType=None, resourceType=None): """Get Policy Types from config that match the given keyword arguments""" # This dict is constructed to be used with function dictMatch that # helps selecting policies. **kwargs are not used due to the fact # that it's too dangerous here. argsdict = { 'Granularity': granularity, 'Status': status, 'FormerStatus': formerStatus, 'NewStatus': newStatus, 'SiteType': siteType, 'ServiceType': serviceType, 'ResourceType': resourceType } pTconfig = getTypedDictRootedAt("PolicyTypes") pTypes = [] for pt in pTconfig: if Utils.dictMatch(argsdict, pTconfig[pt]): pTypes.append(pt) for pt_name in pTypes: if 'Alarm_PolType' in pt_name: pTypes.remove(pt_name) pTypes.append('Alarm_PolType') return pTypes
def _getUsersToNotify(self): groups = CS.getTypedDictRootedAtOperations("AssigneeGroups/" + CS.getSetup()).values() concerned_groups = [g for g in groups if Utils.dictMatch(self.kw["Params"], g)] return [{'Users':g['Users'], 'Notifications':g['Notifications']} for g in concerned_groups]