예제 #1
0
 def test_query(self):
     pod1 = {
         'pod_id': 'test_pod1_uuid',
         'pod_name': 'test_pod1',
         'pod_az_name': 'test_pod_az_name1',
         'dc_name': 'test_dc_name1',
         'az_name': 'test_az1_uuid'
     }
     pod2 = {
         'pod_id': 'test_pod2_uuid',
         'pod_name': 'test_pod2',
         'pod_az_name': 'test_pod_az_name2',
         'dc_name': 'test_dc_name1',
         'az_name': 'test_az2_uuid'
     }
     api.create_pod(self.context, pod1)
     api.create_pod(self.context, pod2)
     filters = [{
         'key': 'pod_name',
         'comparator': 'eq',
         'value': 'test_pod2'
     }]
     pods = api.list_pods(self.context, filters)
     self.assertEqual(len(pods), 1)
     self.assertEqual(pods[0], pod2)
     filters = [{
         'key': 'pod_name',
         'comparator': 'eq',
         'value': 'test_pod3'
     }]
     pods = api.list_pods(self.context, filters)
     self.assertEqual(len(pods), 0)
예제 #2
0
 def _ensure_endpoint_set(self, cxt, service):
     handle = self.service_handle_map[service]
     if not handle.is_endpoint_url_set():
         pod_filters = [{
             'key': 'pod_name',
             'comparator': 'eq',
             'value': self.pod_name
         }]
         pod_list = api.list_pods(cxt, pod_filters)
         if len(pod_list) == 0:
             raise exceptions.ResourceNotFound(models.Pod, self.pod_name)
         # pod_name is unique key, safe to get the first element
         pod_id = pod_list[0]['pod_id']
         config_filters = [{
             'key': 'pod_id',
             'comparator': 'eq',
             'value': pod_id
         }, {
             'key': 'service_type',
             'comparator': 'eq',
             'value': service
         }]
         conf_list = self._get_config_with_retry(
             cxt, config_filters, pod_id, service,
             cfg.CONF.client.auto_refresh_endpoint)
         url = conf_list[0]['service_url']
         handle.update_endpoint_url(url)
예제 #3
0
 def test_sort(self):
     pod1 = {
         'pod_id': 'test_pod1_uuid',
         'pod_name': 'test_pod1',
         'pod_az_name': 'test_pod_az_name1',
         'dc_name': 'test_dc_name1',
         'az_name': 'test_az1_uuid'
     }
     pod2 = {
         'pod_id': 'test_pod2_uuid',
         'pod_name': 'test_pod2',
         'pod_az_name': 'test_pod_az_name2',
         'dc_name': 'test_dc_name1',
         'az_name': 'test_az2_uuid'
     }
     pod3 = {
         'pod_id': 'test_pod3_uuid',
         'pod_name': 'test_pod3',
         'pod_az_name': 'test_pod_az_name3',
         'dc_name': 'test_dc_name1',
         'az_name': 'test_az3_uuid'
     }
     pods = [pod1, pod2, pod3]
     for pod in pods:
         api.create_pod(self.context, pod)
     pods = api.list_pods(self.context, sorts=[(models.Pod.pod_id, False)])
     self.assertEqual(pods, [pod3, pod2, pod1])
예제 #4
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 = trio2o_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 pod
            pod_filters = [{
                'key': 'pod_name',
                'comparator': 'eq',
                'value': region
            }]
            pod_list = api.list_pods(cxt, pod_filters)
            # skip region/pod not registered in cascade service
            if len(pod_list) != 1:
                continue
            for service in endpoint_map[region]:
                pod_id = pod_list[0]['pod_id']
                config_filters = [{
                    'key': 'pod_id',
                    'comparator': 'eq',
                    'value': pod_id
                }, {
                    'key': 'service_type',
                    'comparator': 'eq',
                    'value': service
                }]
                config_list = api.list_pod_service_configurations(
                    cxt, config_filters)

                if len(config_list) > 1:
                    raise exceptions.EndpointNotUnique(pod_id, service)
                if len(config_list) == 1:
                    config_id = config_list[0]['service_id']
                    update_dict = {
                        'service_url': endpoint_map[region][service]
                    }
                    api.update_pod_service_configuration(
                        cxt, config_id, update_dict)
                else:
                    config_dict = {
                        'service_id': str(uuid.uuid4()),
                        'pod_id': pod_id,
                        'service_type': service,
                        'service_url': endpoint_map[region][service]
                    }
                    api.create_pod_service_configuration(cxt, config_dict)
예제 #5
0
 def get_available_pods(self, context, az_name, pod_group):
     if az_name != '':
         filter_q = [{
             'key': 'az_name',
             'comparator': 'eq',
             'value': az_name
         }]
     else:
         filter_q = None
     pods = db_api.list_pods(context, filter_q)
     for filter_ in self.default_filters:
         objs_ = filter_.filter_all(pods, pod_group)
         pods = list(objs_)
     return pods
예제 #6
0
파일: server.py 프로젝트: zwxhnu/trio2o
 def _get_all(self, context, params):
     filters = [{
         'key': key,
         'comparator': 'eq',
         'value': value
     } for key, value in params.iteritems()]
     ret = []
     pods = db_api.list_pods(context)
     for pod in pods:
         if not pod['az_name']:
             continue
         client = self._get_client(pod['pod_name'])
         servers = client.list_servers(context, filters=filters)
         ret.extend(servers)
     return ret
예제 #7
0
파일: pod.py 프로젝트: OpenCloudNeXt/trio2o
    def get_all(self):
        context = t_context.extract_context_from_environ()

        if not policy.enforce(context, policy.ADMIN_API_PODS_LIST):
            pecan.abort(401, _('Unauthorized to list pods'))
            return

        try:
            return {'pods': db_api.list_pods(context)}
        except Exception as e:
            LOG.exception(_LE('Failed to list all pods: %(exception)s '),
                          {'exception': e})

            pecan.abort(500, _('Failed to list pods'))
            return
예제 #8
0
파일: pod.py 프로젝트: zwxhnu/trio2o
    def get_all(self):
        context = t_context.extract_context_from_environ()

        if not t_context.is_admin_context(context):
            pecan.abort(400, _('Admin role required to list pods'))
            return

        try:
            return {'pods': db_api.list_pods(context)}
        except Exception as e:
            LOG.exception(_LE('Failed to list all pods: %(exception)s '),
                          {'exception': e})

            pecan.abort(500, _('Failed to list pods'))
            return
예제 #9
0
def get_pod_by_az_tenant(context, az_name, tenant_id):
    pod_bindings = core.query_resource(context, models.PodBinding,
                                       [{
                                           'key': 'tenant_id',
                                           'comparator': 'eq',
                                           'value': tenant_id
                                       }], [])
    for pod_b in pod_bindings:
        pod = core.get_resource(context, models.Pod, pod_b['pod_id'])
        if az_name and pod['az_name'] == az_name:
            return pod, pod['pod_az_name']
        elif az_name == '' and pod['az_name'] != '':
            # if the az_name is not specified, a defult bottom
            # pod will be selected
            return pod, pod['pod_az_name']
        else:
            pass

    # TODO(joehuang): schedule one dynamically in the future
    if az_name != '':
        filters = [{'key': 'az_name', 'comparator': 'eq', 'value': az_name}]
    else:
        filters = None

    # if az_name is valid, select a pod under this az_name
    # if az_name is '', select the first valid bottom pod.
    # change to dynamic schedluing in the future
    pods = db_api.list_pods(context, filters=filters)
    for pod in pods:
        if pod['pod_name'] != '' and pod['az_name'] != '':
            try:
                with context.session.begin():
                    core.create_resource(
                        context, models.PodBinding, {
                            'id': uuidutils.generate_uuid(),
                            'tenant_id': tenant_id,
                            'pod_id': pod['pod_id'],
                            'is_binding': True
                        })
                    return pod, pod['pod_az_name']
            except Exception as e:
                LOG.error(_LE('Fail to create pod binding: %(exception)s'),
                          {'exception': e})
                return None, None

    return None, None