def sanitize_policy_profile_table(self):
     """Clear policy profiles from stale VSM."""
     db_session = db.get_session()
     hosts = config.get_vsm_hosts()
     vsm_info = db_session.query(
         n1kv_models.PolicyProfile.vsm_ip).distinct()
     if vsm_info is None or hosts is None:
         return
     vsm_ips = [vsm_ip[0] for vsm_ip in vsm_info if vsm_ip[0] not in hosts]
     for vsm_ip in vsm_ips:
         pprofiles = n1kv_db.get_policy_profiles_by_host(vsm_ip, db_session)
         for pprofile in pprofiles:
             # Do not delete profile if it is in use and if it
             # is the only VSM to have it configured
             pp_in_use = n1kv_db.policy_profile_in_use(pprofile['id'],
                                                       db_session)
             num_vsm_using_pp = db_session.query(
                 n1kv_models.PolicyProfile).filter_by(
                 id=pprofile['id']).count()
             if (not pp_in_use) or (num_vsm_using_pp > 1):
                 db_session.delete(pprofile)
                 db_session.flush()
             else:
                 LOG.warning(_LW('Cannot delete policy profile %s '
                                 'as it is in use.'), pprofile['id'])
Exemple #2
0
 def sanitize_policy_profile_table(self):
     """Clear policy profiles from stale VSM."""
     db_session = db.get_session()
     hosts = config.get_vsm_hosts()
     vsm_info = db_session.query(
         n1kv_models.PolicyProfile.vsm_ip).distinct()
     if vsm_info is None or hosts is None:
         return
     vsm_ips = [vsm_ip[0] for vsm_ip in vsm_info if vsm_ip[0] not in hosts]
     for vsm_ip in vsm_ips:
         pprofiles = n1kv_db.get_policy_profiles_by_host(vsm_ip, db_session)
         for pprofile in pprofiles:
             # Do not delete profile if it is in use and if it
             # is the only VSM to have it configured
             pp_in_use = n1kv_db.policy_profile_in_use(
                 pprofile['id'], db_session)
             num_vsm_using_pp = db_session.query(
                 n1kv_models.PolicyProfile).filter_by(
                     id=pprofile['id']).count()
             if (not pp_in_use) or (num_vsm_using_pp > 1):
                 db_session.delete(pprofile)
                 db_session.flush()
             else:
                 LOG.warning(
                     _LW('Cannot delete policy profile %s '
                         'as it is in use.'), pprofile['id'])
Exemple #3
0
 def _get_policy_profiles_by_host(self, vsm_ip):
     """Retrieve policy profiles by vsm_ip."""
     return n1kv_db.get_policy_profiles_by_host(vsm_ip)
 def _get_policy_profiles_by_host(self, vsm_ip):
     """Retrieve policy profiles by vsm_ip."""
     return n1kv_db.get_policy_profiles_by_host(vsm_ip)