From 8ae6b250577de5b27ec37efe53e46d3ebda59e34 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sun, 10 Mar 2013 18:06:51 -0700 Subject: [PATCH 1/7] Bump version. --- service_registry_cli/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service_registry_cli/__init__.py b/service_registry_cli/__init__.py index d1b5980..d8066e4 100644 --- a/service_registry_cli/__init__.py +++ b/service_registry_cli/__init__.py @@ -15,4 +15,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.1.15' +__version__ = '0.2.0' From d21f2c897936c8da2effab972e983619da7d0478 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sun, 10 Mar 2013 18:09:26 -0700 Subject: [PATCH 2/7] Update readme. --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 3896979..aab2e59 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,6 @@ Command line client for Rackspace Service Registry. The client currently allows users to: * view account limits -* view display active sessions * vite active services * view events * view, set and remove configuration values From ed35b7e359b6ba9c01cd6b4188f28fbdde7e3ff9 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sun, 10 Mar 2013 18:13:34 -0700 Subject: [PATCH 3/7] Remove sessions command, update services command. --- service_registry_cli/commands/services/get.py | 9 ++-- .../commands/services/list.py | 9 ++-- .../commands/sessions/__init__.py | 0 service_registry_cli/commands/sessions/get.py | 39 --------------- .../commands/sessions/list.py | 49 ------------------- 5 files changed, 10 insertions(+), 96 deletions(-) delete mode 100644 service_registry_cli/commands/sessions/__init__.py delete mode 100644 service_registry_cli/commands/sessions/get.py delete mode 100644 service_registry_cli/commands/sessions/list.py diff --git a/service_registry_cli/commands/services/get.py b/service_registry_cli/commands/services/get.py index 5c1b485..852c6e3 100644 --- a/service_registry_cli/commands/services/get.py +++ b/service_registry_cli/commands/services/get.py @@ -28,7 +28,7 @@ class GetCommand(BaseShowCommand, ShowOne): """ - Return a single session. + Return a single service. """ log = logging.getLogger(__name__) @@ -37,8 +37,9 @@ def take_action(self, parsed_args): value = client.services.get(parsed_args.object_id) metadata_str = format_metadata(value['metadata']) service_tuple = (value['id'], - value['session_id'], + value['heartbeat_timeout'], + value['last_seen'], ', '.join(value['tags']), metadata_str) - return (('Service ID', 'Session ID', 'Tags', 'Metadata'), - service_tuple) + return (('Service ID', 'Heartbeat Timeout', 'Last Seen', 'Tags', + 'Metadata'), service_tuple) diff --git a/service_registry_cli/commands/services/list.py b/service_registry_cli/commands/services/list.py index b297819..73e44d6 100644 --- a/service_registry_cli/commands/services/list.py +++ b/service_registry_cli/commands/services/list.py @@ -20,7 +20,7 @@ from cliff.lister import Lister from service_registry_cli.utils import BaseListCommand, get_client -from service_registry_cli.utils import format_metadata +from service_registry_cli.utils import format_metadata, format_timestamp class ListCommand(BaseListCommand, Lister): @@ -53,9 +53,10 @@ def take_action(self, parsed_args): parsed_args.returned_metadata = metadata service_tuples = [(value['id'], - value['session_id'], + value['heartbeat_timeout'], + format_timestamp(value['last_seen']), ', '.join(value['tags']), format_metadata(value['metadata'])) for value in values] - return (('Service ID', 'Session ID', 'Tags', 'Metadata'), - service_tuples) + return (('Service ID', 'Heartbeat Timeout', 'Last Seen', 'Tags', + 'Metadata'), service_tuples) diff --git a/service_registry_cli/commands/sessions/__init__.py b/service_registry_cli/commands/sessions/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/service_registry_cli/commands/sessions/get.py b/service_registry_cli/commands/sessions/get.py deleted file mode 100644 index d6602ce..0000000 --- a/service_registry_cli/commands/sessions/get.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright 2012 Rackspace -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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 logging - -from cliff.show import ShowOne - -from service_registry_cli.utils import BaseShowCommand, get_client - - -class GetCommand(BaseShowCommand, ShowOne): - """ - Return a single session. - """ - log = logging.getLogger(__name__) - - def take_action(self, parsed_args): - client = get_client(parsed_args) - value = client.sessions.get(parsed_args.object_id) - session_tuple = (value['id'], - value['heartbeat_timeout'], - value['last_seen'], - value['metadata']) - return (('Session ID', 'Heartbeat Timeout', 'Last Seen', 'Metadata'), - session_tuple) diff --git a/service_registry_cli/commands/sessions/list.py b/service_registry_cli/commands/sessions/list.py deleted file mode 100644 index fef50f1..0000000 --- a/service_registry_cli/commands/sessions/list.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2012 Rackspace -# -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You 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 logging - -from cliff.lister import Lister - -from service_registry_cli.utils import BaseListCommand, get_client -from service_registry_cli.utils import format_metadata, format_timestamp - - -class ListCommand(BaseListCommand, Lister): - """ - Return a list of the available sessions. - """ - log = logging.getLogger(__name__) - - def take_action(self, parsed_args): - client = get_client(parsed_args) - marker = parsed_args.marker if parsed_args.marker else None - limit = parsed_args.limit if parsed_args.limit else None - - result = client.sessions.list(marker=marker, limit=limit) - values = result['values'] - metadata = result['metadata'] - - parsed_args.returned_metadata = metadata - - session_tuples = [(value['id'], - value['heartbeat_timeout'], - format_timestamp(value['last_seen']), - format_metadata(value['metadata'])) - for value in values] - return (('Session ID', 'Heartbeat Timeout', 'Last Seen', 'Metadata'), - session_tuples) From 54f80e41f9558eccaef61d93212dbde3d31f4883 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sun, 10 Mar 2013 18:16:03 -0700 Subject: [PATCH 4/7] pep8. --- service_registry_cli/commands/services/list.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service_registry_cli/commands/services/list.py b/service_registry_cli/commands/services/list.py index 73e44d6..02911f9 100644 --- a/service_registry_cli/commands/services/list.py +++ b/service_registry_cli/commands/services/list.py @@ -59,4 +59,4 @@ def take_action(self, parsed_args): format_metadata(value['metadata'])) for value in values] return (('Service ID', 'Heartbeat Timeout', 'Last Seen', 'Tags', - 'Metadata'), service_tuples) + 'Metadata'), service_tuples) From b22092f12c385f72d1a167442642334039087bd6 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Sun, 10 Mar 2013 18:16:17 -0700 Subject: [PATCH 5/7] Update service-registry dependency version. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 691a1b2..9180c1b 100644 --- a/setup.py +++ b/setup.py @@ -73,7 +73,7 @@ def run(self): 'cliff >= 1.2.2-dev', 'cliff-tablib >= 1.0', 'cliff-rackspace >= 0.1.1', - 'service-registry == 0.1.9' + 'service-registry >= 0.2.0, < 0.3.0' ], dependency_links = [ 'https://github.com/Kami/cliff/tarball/dev#egg=cliff-1.2.2-dev' From eb9584df112fbddf63db6e2966df7e140ae8407c Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 12 Mar 2013 21:41:35 -0700 Subject: [PATCH 6/7] Fix the import. --- service_registry_cli/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service_registry_cli/utils.py b/service_registry_cli/utils.py index 908f52b..78f4faf 100644 --- a/service_registry_cli/utils.py +++ b/service_registry_cli/utils.py @@ -19,7 +19,7 @@ from cliff.command import Command from cliff.lister import Lister -from service_registry import Client +from service_registry.client import Client class BaseCommand(Command): From 90be6a125abb27d8399fc3fe73f8f337d5ab9d9f Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Tue, 12 Mar 2013 21:58:57 -0700 Subject: [PATCH 7/7] Update event display formatting. --- service_registry_cli/utils.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/service_registry_cli/utils.py b/service_registry_cli/utils.py index 78f4faf..bdea92f 100644 --- a/service_registry_cli/utils.py +++ b/service_registry_cli/utils.py @@ -21,6 +21,8 @@ from service_registry.client import Client +SERVICE_EVENTS = ['service.join', 'service.timeout', 'service.remove'] + class BaseCommand(Command): def get_parser(self, prog_name): @@ -101,23 +103,21 @@ def format_timestamp(timestamp): def format_event_payload(event_response): event_payload_str = '' + event_type = event_response['type'] event_payload = event_response['payload'] - if event_payload == []: - event_payload_str = '' + + if not event_payload: return event_payload_str - if event_response['type'] in ['service.join', 'services.timeout']: - if event_response['type'] == 'service.join': - event_payload = [event_payload] - - for service in event_payload: - for key, value in service.iteritems(): - if key == 'metadata': - metadata_str = format_metadata(value) - event_payload_str += 'metadata: %s\n' % (metadata_str) - elif key == 'tags': - event_payload_str += '%s: %s\n' % (key, ', '.join(value)) - else: - event_payload_str += '%s: %s\n' % (key, value) + + if event_type in SERVICE_EVENTS: + for key, value in event_payload.iteritems(): + if key == 'metadata': + metadata_str = format_metadata(value) + event_payload_str += 'metadata: %s\n' % (metadata_str) + elif key == 'tags': + event_payload_str += '%s: %s\n' % (key, ', '.join(value)) + else: + event_payload_str += '%s: %s\n' % (key, value) else: for key, value in event_payload.iteritems(): event_payload_str += '%s: %s\n' % (key, value)