Exemple #1
0
 def _get_config_with_retry(self, cxt, filters, site, service, retry):
     conf_list = models.list_site_service_configurations(cxt, filters)
     if len(conf_list) > 1:
         raise exception.EndpointNotUnique(site, service)
     if len(conf_list) == 0:
         if not retry:
             raise exception.EndpointNotFound(site, service)
         self._update_endpoint_from_keystone(cxt, True)
         return self._get_config_with_retry(cxt,
                                            filters, site, service, False)
     return conf_list
Exemple #2
0
    def _update_endpoint_from_keystone(self, cxt, is_internal):
        """Update the database by querying service endpoint url from Keystone

        :param cxt: context object
        :param is_internal: if True, this method utilizes pre-configured admin
        username and password to apply an new admin token, this happens only
        when auto_refresh_endpoint is set to True. if False, token in cxt is
        directly used, users should prepare admin token themselves
        :return: None
        """
        if is_internal:
            admin_context = tricircle_context.Context()
            admin_context.auth_token = self._get_admin_token()
            endpoint_map = self._get_endpoint_from_keystone(admin_context)
        else:
            endpoint_map = self._get_endpoint_from_keystone(cxt)

        for region in endpoint_map:
            # use region name to query site
            site_filters = [{'key': 'site_name', 'comparator': 'eq',
                             'value': region}]
            site_list = models.list_sites(cxt, site_filters)
            # skip region/site not registered in cascade service
            if len(site_list) != 1:
                continue
            for service in endpoint_map[region]:
                site_id = site_list[0]['site_id']
                config_filters = [{'key': 'site_id', 'comparator': 'eq',
                                   'value': site_id},
                                  {'key': 'service_type', 'comparator': 'eq',
                                   'value': service}]
                config_list = models.list_site_service_configurations(
                    cxt, config_filters)

                if len(config_list) > 1:
                    raise exception.EndpointNotUnique(site_id, service)
                if len(config_list) == 1:
                    config_id = config_list[0]['service_id']
                    update_dict = {
                        'service_url': endpoint_map[region][service]}
                    models.update_site_service_configuration(
                        cxt, config_id, update_dict)
                else:
                    config_dict = {
                        'service_id': str(uuid.uuid4()),
                        'site_id': site_id,
                        'service_type': service,
                        'service_url': endpoint_map[region][service]
                    }
                    models.create_site_service_configuration(
                        cxt, config_dict)