Open Kilda Java Documentation
list.py
Go to the documentation of this file.
1 # Copyright 2017 Telstra Open Source
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 
16 import logging
17 import pprint
18 import json
19 
20 import click
21 
22 from kilda.probe.entity.message import create_list
23 from kilda.probe.messaging import send_with_context, \
24  receive_with_context_async
25 from prettytable import PrettyTable
26 
27 LOG = logging.getLogger(__name__)
28 
29 
30 def print_table(records):
31  table = PrettyTable(['Topology', 'Component', 'Task ID'])
32  for record in records:
33  data = json.loads(record.value)
34  payload = data['payload']
35  LOG.debug(pprint.pformat(data))
36  table.add_row(
37  [payload['topology'], payload['component'], payload['task_id']])
38  print(table)
39 
40 
41 @click.command(name='list')
42 @click.pass_obj
43 def list_command(ctx):
44  message = create_list(ctx.correlation_id)
45  LOG.debug('command = {}'.format(message.serialize()))
46 
47  with receive_with_context_async(ctx) as records:
48  send_with_context(ctx, message.serialize())
49 
50  print_table(records)
def send_with_context(context, message)
Definition: messaging.py:28
def print_table(records)
Definition: list.py:30
def receive_with_context_async(context, expected_count=None)
Definition: messaging.py:43
def create_list(correlation_id)
Definition: message.py:75
def list_command(ctx)
Definition: list.py:43