Beispiel #1
0
  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
Beispiel #2
0
  def __getPanelsInfo(self, granularity, 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,
                'Status': status,
                'FormerStatus': formerStatus,
                'SiteType': siteType,
                'ServiceType': serviceType,
                'ResourceType': resourceType}

    all_policies = getTypedDictRootedAt("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
Beispiel #3
0
  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
Beispiel #4
0
    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
Beispiel #5
0
    def __getPanelsInfo(self,
                        granularity,
                        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,
            'Status': status,
            'FormerStatus': formerStatus,
            'SiteType': siteType,
            'ServiceType': serviceType,
            'ResourceType': resourceType
        }

        all_policies = getTypedDictRootedAt("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
Beispiel #6
0
    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