#!/usr/bin/env python # Copyright 2016 Cisco Systems, Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # import bitmath from contextlib import contextmanager import math from specs import ChainType from tabulate import tabulate class Formatter(object): """Collection of string formatter methods""" @staticmethod def fixed(data): return data @staticmethod def int(data): return '{:,}'.format(data) @staticmethod def float(decimal): return lambda data: '%.{}f'.format(decimal) % (data) @staticmethod def standard(data): if type(data) == int: return Formatter.int(data) elif type(data) == float: return Formatter.float(4)(data) else: return Formatter.fixed(data) @staticmethod def suffix(suffix_str): return lambda data: Formatter.standard(data) + suffix_str @staticmethod def bits(data): # By default, `best_prefix` returns a value in byte format, this hack (multiply by 8.0) # will convert it into bit format. bit = 8.0 * bitmath.Bit(float(data)) bit = bit.best_prefix(bitmath.SI) byte_to_bit_classes = { 'kB': bitmath.kb, 'MB': bitmath.Mb, 'GB': bitmath.Gb, 'TB': bitmath.Tb, 'PB': bitmath.Pb, 'EB': bitmath.Eb, 'ZB': bitmath.Zb, 'YB': bitmath.Yb, } bps = byte_to_bit_classes.get(bit.unit, bitmath.Bit).from_other(bit) / 8.0 if bps.unit != 'Bit': return bps.format("{value:.4f} {unit}ps") else: return bps.format("{value:.4f} bps") @staticmethod def percentage(data): if data is None: return '' elif math.isnan(data): return '-' else: return Formatter.suffix('%')(Formatter.float(4)(data)) class Table(object): """ASCII readable table class""" def __init__(self, header): header_row, self.formatters = zip(*header) self.data = [header_row] self.columns = len(header_row) def add_row(self, row): assert(self.columns == len(row)) formatted_row = [] for entry, formatter in zip(row, self.formatters): formatted_row.append(formatter(entry)) self.data.append(formatted_row) def get_string(self, indent=0): spaces = ' ' * indent table = tabulate(self.data, headers='firstrow', tablefmt='grid', stralign='center', floatfmt='.2f') return table.replace('\n', '\n' + spaces) class Summarizer(object): """Generic summarizer class""" indent_per_level = 2 def __init__(self): self.indent_size = 0 self.marker_stack = [False] self.str = '' def __indent(self, marker): self.indent_size += self.indent_per_level self.marker_stack.append(marker) def __unindent(self): assert(self.indent_size >= self.indent_per_level) self.indent_size -= self.indent_per_level self.marker_stack.pop() def __get_indent_string(self): current_str = ' ' * self.indent_size if self.marker_stack[-1]: current_str = current_str[:-2] + '> ' return current_str def _put(self, *args): self.str += self.__get_indent_string() if len(args) and type(args[-1]) == dict: self.str += ' '.join(map(str, args[:-1])) + '\n' self._put_dict(args[-1]) else: self.str += ' '.join(map(str, args)) + '\n' def _put_dict(self, data): with self._create_block(False): for key, value in data.iteritems(): if type(value) == dict: self._put(key + ':') self._put_dict(value) else: self._put(key + ':', value) def _put_table(self, table): self.str += self.__get_indent_string() self.str += table.get_string(self.indent_size) + '\n' def __str__(self): return self.str @contextmanager def _create_block(self, marker=True): self.__indent(marker) yield self.__unindent() class NFVBenchSummarizer(Summarizer): """Summarize nfvbench json result""" ndr_pdr_header = [ ('-', Formatter.fixed),
# Copyright 2016 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# == Class: tripleo::profile::base::aodh::listener
#
# aodh listener profile for tripleo
#
# === Parameters
#
# [*step*]
#   (Optional) The current step in deployment. See tripleo-heat-templates
#   for more details.
#   Defaults to hiera('step')
#
class tripleo::profile