Esempio n. 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') % str(e)
            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': str(e)}
                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
Esempio n. 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') % str(e)
            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': str(e)}
                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
Esempio n. 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', str(e))
    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,
                      str(e))
    return all_tables
Esempio n. 4
0
def _get_policy_violations_tables(request):
    """Return error and warning tables info for all policies. """
    try:
        # Get all the policies.
        policies = congress.policies_list(request)
    except Exception as e:
        LOG.error('Unable to get list of policies: %s', str(e))
    else:
        try:
            tables_data = []
            for policy in policies:
                policy_name = policy['name']
                policy_table_info = {}
                error_warning_tables = []
                # Get all the tables in this policy.
                policy_tables = congress.policy_tables_list(
                    request, policy_name)
                for table in policy_tables:
                    table_name = table['id']
                    if congress.TABLE_SEPARATOR in table_name:
                        continue
                    if table_name == 'error' or table_name == 'warning':
                        policy_table_info['policy'] = policy
                        error_warning_tables.append(table_name)
                if error_warning_tables:
                    policy_table_info['tables'] = error_warning_tables
                    tables_data.append(policy_table_info)
        except Exception as e:
            LOG.error('Unable to get tables for policy "%s": %s', policy_name,
                      str(e))
    return tables_data
Esempio n. 5
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', str(e))
    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, str(e))
    return all_tables