# Path: raxcli/apps/registry/utils.py
# class BaseRegistryListCommand(BaseRegistryCommand, BaseListCommand):
#     def get_parser(self, prog_name):
#         parser = super(BaseRegistryListCommand, self) \
#             .get_parser(prog_name=prog_name)
#         parser.add_argument('--limit', dest='limit')
#         parser.add_argument('--marker', dest='marker')
#         return parser
# 
# Path: raxcli/apps/registry/utils.py
# def get_client(parsed_args):
#     config = get_config()
# 
#     username = config['username']
#     api_key = config['api_key']
# 
#     if parsed_args.username:
#         username = parsed_args.username
# 
#     if parsed_args.api_key:
#         api_key = parsed_args.api_key
# 
#     api_url = parsed_args.api_url
#     region = parsed_args.region
# 
#     if not username:
#         raise ValueError('Missing required argument: username')
# 
#     if not api_key:
#         raise ValueError('Missing required argument: api-key')
# 
#     kwargs = {}
# 
#     if api_url is not None:
#         kwargs['base_url'] = api_url
# 
#     if region is not None:
#         kwargs['region'] = region
# 
#     c = Client(username=username, api_key=api_key, **kwargs)
#     return c
# 
# Path: raxcli/apps/registry/utils.py
# def format_timestamp(timestamp):
#     if not timestamp:
#         return ''
# 
#     return datetime.fromtimestamp(timestamp / 1000) \
#                    .strftime('%Y-%m-%d %H:%M:%S')
# 
# Path: raxcli/apps/registry/utils.py
# def format_event_payload(event_response):
#     event_payload_str = ''
#     event_type = event_response['type']
#     event_payload = event_response['payload']
# 
#     if not event_payload:
#         return event_payload_str
# 
#     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)
#         event_payload_str = event_payload_str.strip(',\n')
# 
#     return event_payload_str


import logging
from raxcli.apps.registry.utils import BaseRegistryListCommand
from raxcli.apps.registry.utils import get_client
from raxcli.apps.registry.utils import format_timestamp
from raxcli.apps.registry.utils import format_event_payload
#     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 ListCommand(BaseRegistryListCommand):
    """
    Return a list of events.
    """
    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.events.list(marker=marker, limit=limit)
        values = reversed(result['values'])
        metadata = result['metadata']

        parsed_args.returned_metadata = metadata

        event_tuples = [(value['id'],

# Path: raxcli/apps/registry/utils.py
# class BaseRegistryListCommand(BaseRegistryCommand, BaseListCommand):
#     def get_parser(self, prog_name):
#         parser = super(BaseRegistryListCommand, self) \
#             .get_parser(prog_name=prog_name)
#         parser.add_argument('--limit', dest='limit')
#         parser.add_argument('--marker', dest='marker')
#         return parser
# 
# Path: raxcli/apps/registry/utils.py
# def get_client(parsed_args):
#     config = get_config()
# 
#     username = config['username']
#     api_key = config['api_key']
# 
#     if parsed_args.username:
#         username = parsed_args.username
# 
#     if parsed_args.api_key:
#         api_key = parsed_args.api_key
# 
#     api_url = parsed_args.api_url
#     region = parsed_args.region
# 
#     if not username:
#         raise ValueError('Missing required argument: username')
# 
#     if not api_key:
#         raise ValueError('Missing required argument: api-key')
# 
#     kwargs = {}
# 
#     if api_url is not None:
#         kwargs['base_url'] = api_url
# 
#     if region is not None:
#         kwargs['region'] = region
# 
#     c = Client(username=username, api_key=api_key, **kwargs)
#     return c
# 
# Path: raxcli/apps/registry/utils.py
# def format_timestamp(timestamp):
#     if not timestamp:
#         return ''
# 
#     return datetime.fromtimestamp(timestamp / 1000) \
#                    .strftime('%Y-%m-%d %H:%M:%S')
# 
# Path: raxcli/apps/registry/utils.py
# def format_event_payload(event_response):
#     event_payload_str = ''
#     event_type = event_response['type']
#     event_payload = event_response['payload']
# 
#     if not event_payload:
#         return event_payload_str
# 
#     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)
#         event_payload_str = event_payload_str.strip(',\n')
# 
#     return event_payload_str


# Path: raxcli/apps/registry/commands/events/list.py
import logging
from raxcli.apps.registry.utils import BaseRegistryListCommand
from raxcli.apps.registry.utils import get_client
from raxcli.apps.registry.utils import format_timestamp
from raxcli.apps.registry.utils import format_event_payload

#     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 ListCommand(BaseRegistryListCommand):
    """
    Return a list of events.
    """
    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.events.list(marker=marker, limit=limit)
        values = reversed(result['values'])
        metadata = result['metadata']

        parsed_args.returned_metadata = metadata

        event_tuples = [(value['id'],

                        format_timestamp(value['timestamp']),