Esempio n. 1
0
  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
Esempio n. 2
0
  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