Beispiel #1
0
    def get_policies_tables_data(self):
        try:
            policies = congress.policies_list(self.request)
        except Exception as e:
            msg = _('Unable to get policies list: %s') % e.message
            messages.error(self.request, msg)
            return []

        policies_tables = []
        for policy in policies:
            policy_name = policy['name']
            try:
                policy_tables = congress.policy_tables_list(self.request,
                                                            policy_name)
            except Exception as e:
                msg_args = {'policy_name': policy_name, 'error': e.message}
                msg = _('Unable to get tables list for policy '
                        '"%(policy_name)s": %(error)s') % msg_args
                messages.error(self.request, msg)
                return []

            for pt in policy_tables:
                pt.set_id_as_name_if_empty()
                pt.set_policy_details(policy)
            policies_tables.extend(policy_tables)
        return policies_tables
Beispiel #2
0
    def get_policies_tables_data(self):
        try:
            policies = congress.policies_list(self.request)
        except Exception as e:
            msg = _('Unable to get policies list: %s') % e.message
            messages.error(self.request, msg)
            return []

        policies_tables = []
        for policy in policies:
            policy_name = policy['name']
            try:
                policy_tables = congress.policy_tables_list(self.request,
                                                            policy_name)
            except Exception as e:
                msg_args = {'policy_name': policy_name, 'error': e.message}
                msg = _('Unable to get tables list for policy '
                        '"%(policy_name)s": %(error)s') % msg_args
                messages.error(self.request, msg)
                return []

            for pt in policy_tables:
                pt.set_id_as_name_if_empty()
                pt.set_policy_details(policy)
                # Object ids within a Horizon table must be unique. Otherwise,
                # Horizon will cache the column values for the object by id and
                # use the same column values for all rows with the same id.
                pt.set_value('table_id', pt['id'])
                pt.set_value('id', '%s-%s' % (policy_name, pt['table_id']))
            policies_tables.extend(policy_tables)

        return policies_tables
Beispiel #3
0
def _get_policy_tables(request):
    # Return all policy tables.
    all_tables = []
    try:
        # Get all the policies.
        policies = congress.policies_list(request)
    except Exception as e:
        LOG.error('Unable to get list of policies: %s' % e.message)
    else:
        try:
            for policy in policies:
                # Get all the tables in this policy.
                policy_name = policy['name']
                policy_tables = congress.policy_tables_list(request,
                                                            policy_name)
                # Get the names of the tables.
                datasource_tables = []
                for table in policy_tables:
                    table.set_id_as_name_if_empty()
                    table_name = table['name']
                    # Exclude service-derived tables.
                    if congress.TABLE_SEPARATOR not in table_name:
                        datasource_tables.append(table['name'])

                all_tables.append({'datasource': policy_name,
                                   'tables': datasource_tables})
        except Exception as e:
            LOG.error('Unable to get tables for policy "%s": %s' %
                      (policy_name, e.message))
    return all_tables
Beispiel #4
0
    def get_policies_tables_data(self):
        try:
            policies = congress.policies_list(self.request)
        except Exception as e:
            msg = _('Unable to get policies list: %s') % e.message
            messages.error(self.request, msg)
            return []

        policies_tables = []
        for policy in policies:
            policy_name = policy['name']
            try:
                policy_tables = congress.policy_tables_list(
                    self.request, policy_name)
            except Exception as e:
                msg_args = {'policy_name': policy_name, 'error': e.message}
                msg = _('Unable to get tables list for policy '
                        '"%(policy_name)s": %(error)s') % msg_args
                messages.error(self.request, msg)
                return []

            for pt in policy_tables:
                pt.set_id_as_name_if_empty()
                pt.set_policy_details(policy)
            policies_tables.extend(policy_tables)
        return policies_tables
Beispiel #5
0
    def get_policies_tables_data(self):
        policies = congress.policies_list(self.request)
        policies_tables = []

        for policy in policies:
            policy.set_id_as_name_if_empty()
            policy_name = policy['name']
            policy_tables = congress.policy_tables_list(self.request,
                                                        policy_name)
            for pt in policy_tables:
                pt.set_id_as_name_if_empty()
                pt.set_policy_details(policy)
            policies_tables.extend(policy_tables)

        # Group by policy name.
        return sorted(policies_tables,
                      cmp=lambda x, y: cmp(x['policy_name'], y['policy_name']))