configurationengine/source/plugins/common/ConeRulePlugin/ruleplugin/evals/accesspoint_id_counter.py
changeset 3 e7e0ae78773e
parent 0 2e8eeb919028
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
    19 
    19 
    20 import logging
    20 import logging
    21 
    21 
    22 logger = logging.getLogger('cone.ruleplugin.evals.accesspoint_id_counter')
    22 logger = logging.getLogger('cone.ruleplugin.evals.accesspoint_id_counter')
    23 
    23 
    24 def get_apindex_by_apname(aps, dns, apname):
    24 def get_apindex_by_apname(wlan_aps, aps, dns, apname):
    25     """
    25     """
    26     Returns AccessPoint index by given AccessPoint name
    26     Returns AccessPoint index by given AccessPoint name
    27     """
    27     """
    28     cnt = _get_ApDnContainer_(aps, dns)
    28     cnt = _get_ApDnContainer_(wlan_aps, aps, dns)
    29     return cnt.get_apindex_by_apname(apname)
    29     return cnt.get_apindex_by_apname(apname)
    30 
    30 
    31 def get_apid_by_apname(aps, dns, apname, wlan_support=True):
    31 def get_apid_by_apname(wlan_aps, aps, dns, apname):
    32     """
    32     """
    33     Returns AccessPoint id by given AccessPoint name
    33     Returns AccessPoint id by given AccessPoint name
    34     """
    34     """
    35     cnt = _get_ApDnContainer_(aps, dns, wlan_support)
    35     cnt = _get_ApDnContainer_(wlan_aps, aps, dns)
    36     return cnt.get_apid_by_apname(apname)
    36     return cnt.get_apid_by_apname(apname)
    37 
    37 
    38 def get_dnid_by_dnname(aps, dns, dnname, wlan_support=True):
    38 def get_dnid_by_dnname(aps, dns, dnname):
    39     """
    39     """
    40     Return DestinationNetwork id by given DestinationNetworks name
    40     Return DestinationNetwork id by given DestinationNetworks name
    41     """
    41     """
    42     cnt = _get_ApDnContainer_(aps, dns, wlan_support)
    42     cnt = _get_ApDnContainer_(wlan_aps, aps, dns)
    43     return cnt.get_dnid_by_dnname(dnname)
    43     return cnt.get_dnid_by_dnname(dnname)
    44 
    44 
    45 def get_apid_by_dnname_and_apname(aps, dns, dnname, apname, wlan_support=True):
    45 def get_apid_by_dnname_and_apname(wlan_aps, aps, dns, dnname, apname):
    46     """
    46     """
    47     Returns AccessPoint id by given DestinationNetwork name and AccessPoint name.
    47     Returns AccessPoint id by given DestinationNetwork name and AccessPoint name.
    48     """
    48     """
    49     cnt = _get_ApDnContainer_(aps, dns, wlan_support)
    49     cnt = _get_ApDnContainer_(wlan_aps, aps, dns)
    50     return cnt.get_apid_by_dnname_and_apname(dnname, apname)
    50     return cnt.get_apid_by_dnname_and_apname(dnname, apname)
    51 
    51 
    52 def get_all_in_array(aps, dns, wlan_support=True):
    52 def get_all_in_array(wlan_aps, aps, dns):
    53     """
    53     """
    54     Returns array containing all data:
    54     Returns array containing all data:
    55         [DN name],[DN id], [IAPS names], [IAPS ids], [IAPS indexes] 
    55         [DN name],[DN id], [IAPS names], [IAPS ids], [IAPS indexes] 
    56     """
    56     """
    57     cnt = _get_ApDnContainer_(aps, dns, wlan_support)
    57     cnt = _get_ApDnContainer_(wlan_aps, aps, dns)
    58     return cnt.get_all_in_array()
    58     return cnt.get_all_in_array()
    59 
    59 
    60 def _get_ApDnContainer_(aps, dns, wlan_support=True):
    60 def _get_ApDnContainer_(wlan_aps, aps, dns):
    61     """
    61     """
    62     Returns populated ApDnContainer
    62     Returns populated ApDnContainer
    63     """
    63     """
    64     cnt = ApDnContainer()
    64     cnt = ApDnContainer()
    65     
    65     
    66     _read_dns_(dns, cnt)
    66     _read_dns_(dns, cnt)
       
    67     _read_wlan_aps_(wlan_aps, cnt)
    67     _read_aps_(aps, cnt)
    68     _read_aps_(aps, cnt)
    68     
    69     
    69     cnt._calc_dn_ids_()
    70     cnt._calc_dn_ids_()
    70     
    71     cnt._calc_ap_ids_()
    71     if wlan_support:
    72     cnt._calc_ap_indexes_()
    72         cnt._calc_ap_ids_(2)
       
    73     else:
       
    74         cnt._calc_ap_ids_(1)
       
    75     
       
    76     cnt._calc_ap_indexes_(1)
       
    77     
    73     
    78     return cnt
    74     return cnt
    79 
    75 
    80 def _read_dns_(dns, cnt):
    76 def _read_dns_(dns, cnt):
    81     """
    77     """
   125             myiaps[j] = dn_iaps[j][i]
   121             myiaps[j] = dn_iaps[j][i]
   126         mydn.set_iaps(myiaps)
   122         mydn.set_iaps(myiaps)
   127         cnt.add_dn(mydn)
   123         cnt.add_dn(mydn)
   128     return cnt
   124     return cnt
   129 
   125 
       
   126 def _read_all_aps_(wlan_aps, aps, cnt):
       
   127     """
       
   128     Reads WLAN_APs and APs to internal objects to ApDnContainer
       
   129     """
       
   130     
       
   131 
   130 def _read_aps_(aps, cnt):
   132 def _read_aps_(aps, cnt):
   131     """
   133     """
   132     Reads APs to internal objects to ApDnContainer.
   134     Reads APs to internal objects to ApDnContainer.
   133     """
   135     """
   134     ap_names = None
   136     ap_names = None
   157         myap.set_id(ap_ids2[i])
   159         myap.set_id(ap_ids2[i])
   158         myap.set_name(ap_names[i])
   160         myap.set_name(ap_names[i])
   159         cnt.add_ap(myap)
   161         cnt.add_ap(myap)
   160     return cnt
   162     return cnt
   161 
   163 
   162 def _get_next_free_id_(bases, start_index=1):
   164 def _read_wlan_aps_(wlan_aps, cnt):
       
   165     """
       
   166     Reads APs to internal objects to ApDnContainer.
       
   167     """
       
   168     ap_names = None
       
   169     ap_ids1 = None
       
   170     
       
   171     for ap in wlan_aps.WLAN_AP:
       
   172         if ap.ref == 'ConnectionName':
       
   173             ap_names = ap.value
       
   174         if ap.ref == 'ConnectionId':
       
   175             ap_ids1 = ap.value
       
   176     
       
   177     ap_ids2 = [None]*len(ap_names)
       
   178     if ap_ids1 == None:
       
   179         ap_ids1 = []
       
   180     
       
   181     
       
   182     for i in range(len(ap_ids1)):
       
   183         ap_ids2[i] = ap_ids1[i]
       
   184         
       
   185     
       
   186     logger.info('Parsed WLAN_AP names: %s' % ap_names)
       
   187     logger.info('Parsed WLAN_AP ids: %s' % ap_ids2)
       
   188     
       
   189     for i in range(len(ap_names)):
       
   190         myap = Ap()
       
   191         myap.set_id(ap_ids2[i])
       
   192         myap.set_name(ap_names[i])
       
   193         cnt.add_ap(myap)
       
   194     return cnt
       
   195 
       
   196 def _get_next_free_id_(bases, start_index=0):
   163     """
   197     """
   164     Returns next id as a string that is not in use.
   198     Returns next id as a string that is not in use.
   165     """
   199     """
   166     
   200     
   167     biggest_id = int(start_index)
   201     biggest_id = int(start_index)
   204             if dn.get_id() == None or dn.get_id() == '':
   238             if dn.get_id() == None or dn.get_id() == '':
   205                 dn.set_id(_get_next_free_id_(self.dns, 1))
   239                 dn.set_id(_get_next_free_id_(self.dns, 1))
   206 
   240 
   207     def _calc_ap_indexes_(self, ind=1):
   241     def _calc_ap_indexes_(self, ind=1):
   208         index = ind
   242         index = ind
   209         
       
   210         for dn in self.dns:
   243         for dn in self.dns:
   211             for iap in dn.get_iaps():
   244             for iap in dn.get_iaps():
   212                 if iap != None:
   245                 if iap != None:
   213                     for ap in self.aps:
   246                     for ap in self.aps:
   214                         if ap.get_name() == iap and ap.get_index() == '':
   247                         if ap.get_name() == iap and ap.get_index() == '':
   215                             ap.set_index(str(index))
   248                             ap.set_index(str(index))
   216                             index += 1
   249                             index += 1
   217 
   250 
   218     def _calc_ap_ids_(self, start_index=1):
   251     def _calc_ap_ids_(self, start_index=0):
   219         """
   252         """
   220         Calculates unique index for every AccessPoint, if Easy_WLAN is given it always have index 1.
   253         Calculates unique index for every AccessPoint.
   221         """
   254         """
   222         
   255                         
   223         for ap in self.aps:
       
   224             if ap.name == 'Easy WLAN':
       
   225                 ap.set_id('1')
       
   226                 logger.info('Easy_WLAN AP found. Setting 1 to AP id.')
       
   227                 
       
   228         for ap in self.aps:
   256         for ap in self.aps:
   229             if ap.get_id() == None or ap.get_id() == '':
   257             if ap.get_id() == None or ap.get_id() == '':
   230                 ap.set_id(_get_next_free_id_(self.aps, int(start_index)))
   258                 ap.set_id(_get_next_free_id_(self.aps, int(start_index)))
   231     
   259     
   232     def get_apid_by_apname(self, apname):
   260     def get_apid_by_apname(self, apname):
   235         """
   263         """
   236     
   264     
   237         for ap in self.aps:
   265         for ap in self.aps:
   238             if ap.name == apname:
   266             if ap.name == apname:
   239                 return ap.get_id()
   267                 return ap.get_id()
       
   268         logger.warning('ApId not found by ApName: %s' % apname)
   240         return None
   269         return None
   241     
   270     
   242     def get_apindex_by_apname(self, apname):
   271     def get_apindex_by_apname(self, apname):
   243         """
   272         """
   244         Returns Accesspoint index by given AccessPoint name
   273         Returns Accesspoint index by given AccessPoint name
   245         """
   274         """
   246         
   275         
   247         for ap in self.aps:
   276         for ap in self.aps:
   248             if ap.get_name() == apname:
   277             if ap.get_name() == apname:
   249                 return ap.get_index()
   278                 return ap.get_index()
       
   279         logger.warning('ApIndex not found by ApName: %s' % apname)
   250         return None
   280         return None
   251     
   281     
   252     
   282     
   253     def get_dnid_by_dnname(self, dnname):
   283     def get_dnid_by_dnname(self, dnname):
   254         """
   284         """
   255         Return DestinationNetwork id by given DestinationNetworks name
   285         Return DestinationNetwork id by given DestinationNetworks name
   256         """
   286         """
   257         for dn in self.dns:
   287         for dn in self.dns:
   258             if dn.name == dnname:
   288             if dn.name == dnname:
   259                 return dn.id
   289                 return dn.id
       
   290         logger.warning('DnId not found by DnName: %s' % dnname)
   260         return None
   291         return None
   261     
   292     
   262     def get_apid_by_dnname_and_apname(self, dnname, apname):
   293     def get_apid_by_dnname_and_apname(self, dnname, apname):
   263         """
   294         """
   264         Returns AccessPoint id by given DestinationNetwork name and AccessPoint name.
   295         Returns AccessPoint id by given DestinationNetwork name and AccessPoint name.
   267             if dn.name == dnname:
   298             if dn.name == dnname:
   268                 iaps = dn.get_iaps()
   299                 iaps = dn.get_iaps()
   269                 for iap in range(len(iaps)):
   300                 for iap in range(len(iaps)):
   270                     if iaps[iap] != None and iaps[iap] == apname:
   301                     if iaps[iap] != None and iaps[iap] == apname:
   271                         return self.get_apid_by_apname(apname)
   302                         return self.get_apid_by_apname(apname)
       
   303         logger.warning('ApId not found by DnName: %s ApName: %s' % dnname, apname)
   272         return None
   304         return None
   273     
   305     
   274     def get_all_in_array(self):
   306     def get_all_in_array(self):
   275         """
   307         """
   276         Returns array containing all data:
   308         Returns array containing all data: