19 from collections
import OrderedDict
22 from datetime
import datetime
23 import prettytable.prettytable
as prettytable
24 from prettytable
import PrettyTable
29 create_resource_dump_state
33 LOG = logging.getLogger(__name__)
37 """Yield successive n-sized chunks from l.""" 38 for i
in range(0, len(l), n):
43 for record
in records:
44 data = json.loads(record.value)
45 payload = data[
'payload']
46 LOG.debug(pprint.pformat(data))
47 table = PrettyTable([
'Topology',
'Component',
'Task ID'],
50 [payload[
'topology'], payload[
'component'], payload[
'task_id']])
52 del payload[
'state'][
'clazz']
56 table = PrettyTable([
'Resource',
'List',
'Count'], border=border)
58 for k
in (
'cookies',
'vlans'):
62 data = payload[
'state'][k]
66 table.add_row([k, rep, len(payload[
'state'][k])])
70 table = PrettyTable([
'SW',
'List',
'Count'])
72 for sw
in payload[
'state'][
'meters']:
73 data = payload[
'state'][
'meters'][sw]
75 table.add_row([sw, rep, len(data)])
83 data = list(map(str, data))
91 @click.command(name=
'dump-resource-state')
92 @click.argument(
'destination')
93 @click.option(
'--border/--no-border', default=
True)
94 @click.option(
'--table',
'output_type', flag_value=
'table', default=
True)
95 @click.option(
'--json',
'output_type', flag_value=
'json')
99 destination=destination)
100 LOG.debug(
'command = {}'.
format(message.serialize()))
105 if output_type ==
'table':
107 elif output_type ==
'json':
108 for record
in records:
109 data = json.loads(record.value)
def format_int_list(data)
def send_with_context(context, message)
def dump_resource_state(ctx, destination, border, output_type)
def create_resource_dump_state(correlation_id, destination)
def receive_with_context_async(context, expected_count=None)
def print_table(records, border)