From e674e13e9f9bfee31ac6ff9d99d5ad4dc7ac16ca Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Thu, 21 Feb 2019 14:35:16 -0600 Subject: [PATCH 1/2] #1089 removed legacy SL message queue commands --- SoftLayer/CLI/mq/__init__.py | 57 ---- SoftLayer/CLI/mq/accounts_list.py | 28 -- SoftLayer/CLI/mq/endpoints_list.py | 27 -- SoftLayer/CLI/mq/ping.py | 25 -- SoftLayer/CLI/mq/queue_add.py | 46 --- SoftLayer/CLI/mq/queue_detail.py | 26 -- SoftLayer/CLI/mq/queue_edit.py | 46 --- SoftLayer/CLI/mq/queue_list.py | 34 -- SoftLayer/CLI/mq/queue_pop.py | 42 --- SoftLayer/CLI/mq/queue_push.py | 32 -- SoftLayer/CLI/mq/queue_remove.py | 30 -- SoftLayer/CLI/mq/topic_add.py | 46 --- SoftLayer/CLI/mq/topic_detail.py | 30 -- SoftLayer/CLI/mq/topic_list.py | 29 -- SoftLayer/CLI/mq/topic_push.py | 34 -- SoftLayer/CLI/mq/topic_remove.py | 25 -- SoftLayer/CLI/mq/topic_subscribe.py | 46 --- SoftLayer/CLI/mq/topic_unsubscribe.py | 25 -- SoftLayer/CLI/routes.py | 19 -- SoftLayer/managers/__init__.py | 2 - SoftLayer/managers/messaging.py | 405 ---------------------- tests/managers/queue_tests.py | 467 -------------------------- 22 files changed, 1521 deletions(-) delete mode 100644 SoftLayer/CLI/mq/__init__.py delete mode 100644 SoftLayer/CLI/mq/accounts_list.py delete mode 100644 SoftLayer/CLI/mq/endpoints_list.py delete mode 100644 SoftLayer/CLI/mq/ping.py delete mode 100644 SoftLayer/CLI/mq/queue_add.py delete mode 100644 SoftLayer/CLI/mq/queue_detail.py delete mode 100644 SoftLayer/CLI/mq/queue_edit.py delete mode 100644 SoftLayer/CLI/mq/queue_list.py delete mode 100644 SoftLayer/CLI/mq/queue_pop.py delete mode 100644 SoftLayer/CLI/mq/queue_push.py delete mode 100644 SoftLayer/CLI/mq/queue_remove.py delete mode 100644 SoftLayer/CLI/mq/topic_add.py delete mode 100644 SoftLayer/CLI/mq/topic_detail.py delete mode 100644 SoftLayer/CLI/mq/topic_list.py delete mode 100644 SoftLayer/CLI/mq/topic_push.py delete mode 100644 SoftLayer/CLI/mq/topic_remove.py delete mode 100644 SoftLayer/CLI/mq/topic_subscribe.py delete mode 100644 SoftLayer/CLI/mq/topic_unsubscribe.py delete mode 100644 SoftLayer/managers/messaging.py delete mode 100644 tests/managers/queue_tests.py diff --git a/SoftLayer/CLI/mq/__init__.py b/SoftLayer/CLI/mq/__init__.py deleted file mode 100644 index 3f8947b89..000000000 --- a/SoftLayer/CLI/mq/__init__.py +++ /dev/null @@ -1,57 +0,0 @@ -"""Message queue service.""" -# :license: MIT, see LICENSE for more details. - -from SoftLayer.CLI import formatting - - -def queue_table(queue): - """Returns a table with details about a queue.""" - table = formatting.Table(['property', 'value']) - table.align['property'] = 'r' - table.align['value'] = 'l' - - table.add_row(['name', queue['name']]) - table.add_row(['message_count', queue['message_count']]) - table.add_row(['visible_message_count', queue['visible_message_count']]) - table.add_row(['tags', formatting.listing(queue['tags'] or [])]) - table.add_row(['expiration', queue['expiration']]) - table.add_row(['visibility_interval', queue['visibility_interval']]) - return table - - -def message_table(message): - """Returns a table with details about a message.""" - table = formatting.Table(['property', 'value']) - table.align['property'] = 'r' - table.align['value'] = 'l' - - table.add_row(['id', message['id']]) - table.add_row(['initial_entry_time', message['initial_entry_time']]) - table.add_row(['visibility_delay', message['visibility_delay']]) - table.add_row(['visibility_interval', message['visibility_interval']]) - table.add_row(['fields', message['fields']]) - return [table, message['body']] - - -def topic_table(topic): - """Returns a table with details about a topic.""" - table = formatting.Table(['property', 'value']) - table.align['property'] = 'r' - table.align['value'] = 'l' - - table.add_row(['name', topic['name']]) - table.add_row(['tags', formatting.listing(topic['tags'] or [])]) - return table - - -def subscription_table(sub): - """Returns a table with details about a subscription.""" - table = formatting.Table(['property', 'value']) - table.align['property'] = 'r' - table.align['value'] = 'l' - - table.add_row(['id', sub['id']]) - table.add_row(['endpoint_type', sub['endpoint_type']]) - for key, val in sub['endpoint'].items(): - table.add_row([key, val]) - return table diff --git a/SoftLayer/CLI/mq/accounts_list.py b/SoftLayer/CLI/mq/accounts_list.py deleted file mode 100644 index 484881b5b..000000000 --- a/SoftLayer/CLI/mq/accounts_list.py +++ /dev/null @@ -1,28 +0,0 @@ -"""List SoftLayer Message Queue Accounts.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import formatting - - -@click.command() -@environment.pass_env -def cli(env): - """List SoftLayer Message Queue Accounts.""" - - manager = SoftLayer.MessagingManager(env.client) - accounts = manager.list_accounts() - - table = formatting.Table(['id', 'name', 'status']) - for account in accounts: - if not account['nodes']: - continue - - table.add_row([account['nodes'][0]['accountName'], - account['name'], - account['status']['name']]) - - env.fout(table) diff --git a/SoftLayer/CLI/mq/endpoints_list.py b/SoftLayer/CLI/mq/endpoints_list.py deleted file mode 100644 index 556642ccd..000000000 --- a/SoftLayer/CLI/mq/endpoints_list.py +++ /dev/null @@ -1,27 +0,0 @@ -"""List SoftLayer Message Queue Endpoints.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import formatting - - -@click.command() -@environment.pass_env -def cli(env): - """List SoftLayer Message Queue Endpoints.""" - - manager = SoftLayer.MessagingManager(env.client) - regions = manager.get_endpoints() - - table = formatting.Table(['name', 'public', 'private']) - for region, endpoints in regions.items(): - table.add_row([ - region, - endpoints.get('public') or formatting.blank(), - endpoints.get('private') or formatting.blank(), - ]) - - env.fout(table) diff --git a/SoftLayer/CLI/mq/ping.py b/SoftLayer/CLI/mq/ping.py deleted file mode 100644 index 2a8fa2435..000000000 --- a/SoftLayer/CLI/mq/ping.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Ping the SoftLayer Message Queue service.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import exceptions - - -@click.command() -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, datacenter, network): - """Ping the SoftLayer Message Queue service.""" - - manager = SoftLayer.MessagingManager(env.client) - okay = manager.ping(datacenter=datacenter, network=network) - if okay: - env.fout('OK') - else: - exceptions.CLIAbort('Ping failed') diff --git a/SoftLayer/CLI/mq/queue_add.py b/SoftLayer/CLI/mq/queue_add.py deleted file mode 100644 index 594527116..000000000 --- a/SoftLayer/CLI/mq/queue_add.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Create a queue.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import helpers -from SoftLayer.CLI import mq - - -@click.command() -@click.argument('account-id') -@click.argument('queue-name') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@click.option('--visibility-interval', - type=click.INT, - default=30, - show_default=True, - help="Time in seconds that messages will re-appear after being " - "popped") -@click.option('--expiration', - type=click.INT, - default=604800, - show_default=True, - help="Time in seconds that messages will live") -@helpers.multi_option('--tag', '-g', help="Tags to add to the queue") -@environment.pass_env -def cli(env, account_id, queue_name, datacenter, network, visibility_interval, - expiration, tag): - """Create a queue.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - - queue = mq_client.create_queue( - queue_name, - visibility_interval=visibility_interval, - expiration=expiration, - tags=tag, - ) - env.fout(mq.queue_table(queue)) diff --git a/SoftLayer/CLI/mq/queue_detail.py b/SoftLayer/CLI/mq/queue_detail.py deleted file mode 100644 index 3cd1694d5..000000000 --- a/SoftLayer/CLI/mq/queue_detail.py +++ /dev/null @@ -1,26 +0,0 @@ -"""Detail a queue.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import mq - - -@click.command() -@click.argument('account-id') -@click.argument('queue-name') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, account_id, queue_name, datacenter, network): - """Detail a queue.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - queue = mq_client.get_queue(queue_name) - env.fout(mq.queue_table(queue)) diff --git a/SoftLayer/CLI/mq/queue_edit.py b/SoftLayer/CLI/mq/queue_edit.py deleted file mode 100644 index 1f97788bf..000000000 --- a/SoftLayer/CLI/mq/queue_edit.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Modify a queue.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import helpers -from SoftLayer.CLI import mq - - -@click.command() -@click.argument('account-id') -@click.argument('queue-name') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@click.option('--visibility-interval', - type=click.INT, - default=30, - show_default=True, - help="Time in seconds that messages will re-appear after being " - "popped") -@click.option('--expiration', - type=click.INT, - default=604800, - show_default=True, - help="Time in seconds that messages will live") -@helpers.multi_option('--tag', '-g', help="Tags to add to the queue") -@environment.pass_env -def cli(env, account_id, queue_name, datacenter, network, visibility_interval, - expiration, tag): - """Modify a queue.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - - queue = mq_client.modify_queue( - queue_name, - visibility_interval=visibility_interval, - expiration=expiration, - tags=tag, - ) - env.fout(mq.queue_table(queue)) diff --git a/SoftLayer/CLI/mq/queue_list.py b/SoftLayer/CLI/mq/queue_list.py deleted file mode 100644 index 1059fa3c9..000000000 --- a/SoftLayer/CLI/mq/queue_list.py +++ /dev/null @@ -1,34 +0,0 @@ -"""List all queues on an account.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import formatting - - -@click.command() -@click.argument('account-id') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, account_id, datacenter, network): - """List all queues on an account.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - - queues = mq_client.get_queues()['items'] - - table = formatting.Table(['name', - 'message_count', - 'visible_message_count']) - for queue in queues: - table.add_row([queue['name'], - queue['message_count'], - queue['visible_message_count']]) - env.fout(table) diff --git a/SoftLayer/CLI/mq/queue_pop.py b/SoftLayer/CLI/mq/queue_pop.py deleted file mode 100644 index 1d81e9ea9..000000000 --- a/SoftLayer/CLI/mq/queue_pop.py +++ /dev/null @@ -1,42 +0,0 @@ -"""Pops a message from a queue.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import mq - - -@click.command() -@click.argument('account-id') -@click.argument('queue-name') -@click.option('--count', - default=1, - show_default=True, - type=click.INT, - help="Count of messages to pop") -@click.option('--delete-after', - is_flag=True, - help="Remove popped messages from the queue") -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, account_id, queue_name, count, delete_after, datacenter, network): - """Pops a message from a queue.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - - messages = mq_client.pop_messages(queue_name, count) - formatted_messages = [] - for message in messages['items']: - formatted_messages.append(mq.message_table(message)) - - if delete_after: - for message in messages['items']: - mq_client.delete_message(queue_name, message['id']) - env.fout(formatted_messages) diff --git a/SoftLayer/CLI/mq/queue_push.py b/SoftLayer/CLI/mq/queue_push.py deleted file mode 100644 index c025dcf94..000000000 --- a/SoftLayer/CLI/mq/queue_push.py +++ /dev/null @@ -1,32 +0,0 @@ -"""Push a message into a queue.""" -# :license: MIT, see LICENSE for more details. -import sys - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import mq - - -@click.command() -@click.argument('account-id') -@click.argument('queue-name') -@click.argument('message') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, account_id, queue_name, message, datacenter, network): - """Push a message into a queue.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - body = '' - if message == '-': - body = sys.stdin.read() - else: - body = message - env.fout(mq.message_table(mq_client.push_queue_message(queue_name, body))) diff --git a/SoftLayer/CLI/mq/queue_remove.py b/SoftLayer/CLI/mq/queue_remove.py deleted file mode 100644 index 4396dac1a..000000000 --- a/SoftLayer/CLI/mq/queue_remove.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Delete a queue or a queued message.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment - - -@click.command() -@click.argument('account-id') -@click.argument('queue-name') -@click.argument('message-id', required=False) -@click.option('--force', is_flag=True, help="Force the deletion of the queue") -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, account_id, queue_name, message_id, force, datacenter, network): - """Delete a queue or a queued message.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - - if message_id: - mq_client.delete_message(queue_name, message_id) - else: - mq_client.delete_queue(queue_name, force) diff --git a/SoftLayer/CLI/mq/topic_add.py b/SoftLayer/CLI/mq/topic_add.py deleted file mode 100644 index 0b48874c2..000000000 --- a/SoftLayer/CLI/mq/topic_add.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Create a new topic.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import helpers -from SoftLayer.CLI import mq - - -@click.command() -@click.argument('account-id') -@click.argument('topic-name') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@click.option('--visibility-interval', - type=click.INT, - default=30, - show_default=True, - help="Time in seconds that messages will re-appear after being " - "popped") -@click.option('--expiration', - type=click.INT, - default=604800, - show_default=True, - help="Time in seconds that messages will live") -@helpers.multi_option('--tag', '-g', help="Tags to add to the topic") -@environment.pass_env -def cli(env, account_id, topic_name, datacenter, network, - visibility_interval, expiration, tag): - """Create a new topic.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - - topic = mq_client.create_topic( - topic_name, - visibility_interval=visibility_interval, - expiration=expiration, - tags=tag, - ) - env.fout(mq.topic_table(topic)) diff --git a/SoftLayer/CLI/mq/topic_detail.py b/SoftLayer/CLI/mq/topic_detail.py deleted file mode 100644 index bb0b80349..000000000 --- a/SoftLayer/CLI/mq/topic_detail.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Detail a topic.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import mq - - -@click.command() -@click.argument('account-id') -@click.argument('topic-name') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, account_id, topic_name, datacenter, network): - """Detail a topic.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - topic = mq_client.get_topic(topic_name) - subscriptions = mq_client.get_subscriptions(topic_name) - tables = [] - for sub in subscriptions['items']: - tables.append(mq.subscription_table(sub)) - env.fout([mq.topic_table(topic), tables]) diff --git a/SoftLayer/CLI/mq/topic_list.py b/SoftLayer/CLI/mq/topic_list.py deleted file mode 100644 index f86d13334..000000000 --- a/SoftLayer/CLI/mq/topic_list.py +++ /dev/null @@ -1,29 +0,0 @@ -"""List all topics on an account.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import formatting - - -@click.command() -@click.argument('account-id') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, account_id, datacenter, network): - """List all topics on an account.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - topics = mq_client.get_topics()['items'] - - table = formatting.Table(['name']) - for topic in topics: - table.add_row([topic['name']]) - env.fout(table) diff --git a/SoftLayer/CLI/mq/topic_push.py b/SoftLayer/CLI/mq/topic_push.py deleted file mode 100644 index e0384492f..000000000 --- a/SoftLayer/CLI/mq/topic_push.py +++ /dev/null @@ -1,34 +0,0 @@ -"""Push a message into a topic.""" -# :license: MIT, see LICENSE for more details. -import sys - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import mq - - -@click.command() -@click.argument('account-id') -@click.argument('topic-name') -@click.argument('message') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, account_id, topic_name, message, datacenter, network): - """Push a message into a topic.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - - # the message body comes from the positional argument or stdin - body = '' - if message == '-': - body = sys.stdin.read() - else: - body = message - env.fout(mq.message_table(mq_client.push_topic_message(topic_name, body))) diff --git a/SoftLayer/CLI/mq/topic_remove.py b/SoftLayer/CLI/mq/topic_remove.py deleted file mode 100644 index cdfb22c0f..000000000 --- a/SoftLayer/CLI/mq/topic_remove.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Delete a topic.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment - - -@click.command() -@click.argument('account-id') -@click.argument('topic-name') -@click.option('--force', is_flag=True, help="Force the deletion of the queue") -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, account_id, topic_name, force, datacenter, network): - """Delete a topic.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - mq_client.delete_topic(topic_name, force) diff --git a/SoftLayer/CLI/mq/topic_subscribe.py b/SoftLayer/CLI/mq/topic_subscribe.py deleted file mode 100644 index 226e20103..000000000 --- a/SoftLayer/CLI/mq/topic_subscribe.py +++ /dev/null @@ -1,46 +0,0 @@ -"""Create a subscription on a topic.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment -from SoftLayer.CLI import mq - - -@click.command() -@click.argument('account-id') -@click.argument('topic-name') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@click.option('--sub-type', - type=click.Choice(['http', 'queue']), - help="Type of endpoint") -@click.option('--queue-name', help="Queue name. Required if --type is queue") -@click.option('--http-method', help="HTTP Method to use if --type is http") -@click.option('--http-url', - help="HTTP/HTTPS URL to use. Required if --type is http") -@click.option('--http-body', - help="HTTP Body template to use if --type is http") -@environment.pass_env -def cli(env, account_id, topic_name, datacenter, network, sub_type, queue_name, - http_method, http_url, http_body): - """Create a subscription on a topic.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - if sub_type == 'queue': - subscription = mq_client.create_subscription(topic_name, 'queue', - queue_name=queue_name) - elif sub_type == 'http': - subscription = mq_client.create_subscription( - topic_name, - 'http', - method=http_method, - url=http_url, - body=http_body, - ) - env.fout(mq.subscription_table(subscription)) diff --git a/SoftLayer/CLI/mq/topic_unsubscribe.py b/SoftLayer/CLI/mq/topic_unsubscribe.py deleted file mode 100644 index 48d4b4940..000000000 --- a/SoftLayer/CLI/mq/topic_unsubscribe.py +++ /dev/null @@ -1,25 +0,0 @@ -"""Remove a subscription on a topic.""" -# :license: MIT, see LICENSE for more details. - -import click - -import SoftLayer -from SoftLayer.CLI import environment - - -@click.command() -@click.argument('account-id') -@click.argument('topic-name') -@click.argument('subscription-id') -@click.option('--datacenter', help="Datacenter, E.G.: dal05") -@click.option('--network', - type=click.Choice(['public', 'private']), - help="Network type") -@environment.pass_env -def cli(env, account_id, topic_name, subscription_id, datacenter, network): - """Remove a subscription on a topic.""" - - manager = SoftLayer.MessagingManager(env.client) - mq_client = manager.get_connection(account_id, - datacenter=datacenter, network=network) - mq_client.delete_subscription(topic_name, subscription_id) diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py index cc6a86abe..e5b28c0e3 100644 --- a/SoftLayer/CLI/routes.py +++ b/SoftLayer/CLI/routes.py @@ -181,25 +181,6 @@ ('loadbal:service-edit', 'SoftLayer.CLI.loadbal.service_edit:cli'), ('loadbal:service-toggle', 'SoftLayer.CLI.loadbal.service_toggle:cli'), - ('messaging', 'SoftLayer.CLI.mq'), - ('messaging:accounts-list', 'SoftLayer.CLI.mq.accounts_list:cli'), - ('messaging:endpoints-list', 'SoftLayer.CLI.mq.endpoints_list:cli'), - ('messaging:ping', 'SoftLayer.CLI.mq.ping:cli'), - ('messaging:queue-add', 'SoftLayer.CLI.mq.queue_add:cli'), - ('messaging:queue-detail', 'SoftLayer.CLI.mq.queue_detail:cli'), - ('messaging:queue-edit', 'SoftLayer.CLI.mq.queue_edit:cli'), - ('messaging:queue-list', 'SoftLayer.CLI.mq.queue_list:cli'), - ('messaging:queue-pop', 'SoftLayer.CLI.mq.queue_pop:cli'), - ('messaging:queue-push', 'SoftLayer.CLI.mq.queue_push:cli'), - ('messaging:queue-remove', 'SoftLayer.CLI.mq.queue_remove:cli'), - ('messaging:topic-add', 'SoftLayer.CLI.mq.topic_add:cli'), - ('messaging:topic-detail', 'SoftLayer.CLI.mq.topic_detail:cli'), - ('messaging:topic-list', 'SoftLayer.CLI.mq.topic_list:cli'), - ('messaging:topic-push', 'SoftLayer.CLI.mq.topic_push:cli'), - ('messaging:topic-remove', 'SoftLayer.CLI.mq.topic_remove:cli'), - ('messaging:topic-subscribe', 'SoftLayer.CLI.mq.topic_subscribe:cli'), - ('messaging:topic-unsubscribe', 'SoftLayer.CLI.mq.topic_unsubscribe:cli'), - ('metadata', 'SoftLayer.CLI.metadata:cli'), ('nas', 'SoftLayer.CLI.nas'), diff --git a/SoftLayer/managers/__init__.py b/SoftLayer/managers/__init__.py index d93b810de..5c489345d 100644 --- a/SoftLayer/managers/__init__.py +++ b/SoftLayer/managers/__init__.py @@ -18,7 +18,6 @@ from SoftLayer.managers.image import ImageManager from SoftLayer.managers.ipsec import IPSECManager from SoftLayer.managers.load_balancer import LoadBalancerManager -from SoftLayer.managers.messaging import MessagingManager from SoftLayer.managers.metadata import MetadataManager from SoftLayer.managers.network import NetworkManager from SoftLayer.managers.object_storage import ObjectStorageManager @@ -44,7 +43,6 @@ 'ImageManager', 'IPSECManager', 'LoadBalancerManager', - 'MessagingManager', 'MetadataManager', 'NetworkManager', 'ObjectStorageManager', diff --git a/SoftLayer/managers/messaging.py b/SoftLayer/managers/messaging.py deleted file mode 100644 index 3ce1c17aa..000000000 --- a/SoftLayer/managers/messaging.py +++ /dev/null @@ -1,405 +0,0 @@ -""" - SoftLayer.messaging - ~~~~~~~~~~~~~~~~~~~ - Manager for the SoftLayer Message Queue service - - :license: MIT, see LICENSE for more details. -""" -import json - -import requests.auth - -from SoftLayer import consts -from SoftLayer import exceptions -# pylint: disable=no-self-use - - -ENDPOINTS = { - "dal05": { - "public": "dal05.mq.softlayer.net", - "private": "dal05.mq.service.networklayer.com" - } -} - - -class QueueAuth(requests.auth.AuthBase): - """SoftLayer Message Queue authentication for requests. - - :param endpoint: endpoint URL - :param username: SoftLayer username - :param api_key: SoftLayer API Key - :param auth_token: (optional) Starting auth token - """ - - def __init__(self, endpoint, username, api_key, auth_token=None): - self.endpoint = endpoint - self.username = username - self.api_key = api_key - self.auth_token = auth_token - - def auth(self): - """Authenticate.""" - headers = { - 'X-Auth-User': self.username, - 'X-Auth-Key': self.api_key - } - resp = requests.post(self.endpoint, headers=headers) - if resp.ok: - self.auth_token = resp.headers['X-Auth-Token'] - else: - raise exceptions.Unauthenticated("Error while authenticating: %s" - % resp.status_code) - - def handle_error(self, resp, **_): - """Handle errors.""" - resp.request.deregister_hook('response', self.handle_error) - if resp.status_code == 503: - resp.connection.send(resp.request) - elif resp.status_code == 401: - self.auth() - resp.request.headers['X-Auth-Token'] = self.auth_token - resp.connection.send(resp.request) - - def __call__(self, resp): - """Attach auth token to the request. - - Do authentication if an auth token isn't available - """ - if not self.auth_token: - self.auth() - resp.register_hook('response', self.handle_error) - resp.headers['X-Auth-Token'] = self.auth_token - return resp - - -class MessagingManager(object): - """Manage SoftLayer Message Queue accounts. - - See product information here: http://www.softlayer.com/message-queue - - :param SoftLayer.API.BaseClient client: the client instance - - """ - - def __init__(self, client): - self.client = client - - def list_accounts(self, **kwargs): - """List message queue accounts. - - :param dict \\*\\*kwargs: response-level options (mask, limit, etc.) - """ - if 'mask' not in kwargs: - items = [ - 'id', - 'name', - 'status', - 'nodes', - ] - kwargs['mask'] = "mask[%s]" % ','.join(items) - - return self.client['Account'].getMessageQueueAccounts(**kwargs) - - def get_endpoint(self, datacenter=None, network=None): - """Get a message queue endpoint based on datacenter/network type. - - :param datacenter: datacenter code - :param network: network ('public' or 'private') - """ - if datacenter is None: - datacenter = 'dal05' - if network is None: - network = 'public' - try: - host = ENDPOINTS[datacenter][network] - return "https://%s" % host - except KeyError: - raise TypeError('Invalid endpoint %s/%s' - % (datacenter, network)) - - def get_endpoints(self): - """Get all known message queue endpoints.""" - return ENDPOINTS - - def get_connection(self, account_id, datacenter=None, network=None): - """Get connection to Message Queue Service. - - :param account_id: Message Queue Account id - :param datacenter: Datacenter code - :param network: network ('public' or 'private') - """ - if any([not self.client.auth, - not getattr(self.client.auth, 'username', None), - not getattr(self.client.auth, 'api_key', None)]): - raise exceptions.SoftLayerError( - 'Client instance auth must be BasicAuthentication.') - - client = MessagingConnection( - account_id, endpoint=self.get_endpoint(datacenter, network)) - client.authenticate(self.client.auth.username, - self.client.auth.api_key) - return client - - def ping(self, datacenter=None, network=None): - """Ping a message queue endpoint.""" - resp = requests.get('%s/v1/ping' % - self.get_endpoint(datacenter, network)) - resp.raise_for_status() - return True - - -class MessagingConnection(object): - """Message Queue Service Connection. - - :param account_id: Message Queue Account id - :param endpoint: Endpoint URL - """ - - def __init__(self, account_id, endpoint=None): - self.account_id = account_id - self.endpoint = endpoint - self.auth = None - - def _make_request(self, method, path, **kwargs): - """Make request. Generally not called directly. - - :param method: HTTP Method - :param path: resource Path - :param dict \\*\\*kwargs: extra request arguments - """ - headers = { - 'Content-Type': 'application/json', - 'User-Agent': consts.USER_AGENT, - } - headers.update(kwargs.get('headers', {})) - kwargs['headers'] = headers - kwargs['auth'] = self.auth - - url = '/'.join((self.endpoint, 'v1', self.account_id, path)) - resp = requests.request(method, url, **kwargs) - try: - resp.raise_for_status() - except requests.HTTPError as ex: - content = json.loads(ex.response.content) - raise exceptions.SoftLayerAPIError(ex.response.status_code, - content['message']) - return resp - - def authenticate(self, username, api_key, auth_token=None): - """Authenticate this connection using the given credentials. - - :param username: SoftLayer username - :param api_key: SoftLayer API Key - :param auth_token: (optional) Starting auth token - """ - auth_endpoint = '/'.join((self.endpoint, 'v1', - self.account_id, 'auth')) - auth = QueueAuth(auth_endpoint, username, api_key, - auth_token=auth_token) - auth.auth() - self.auth = auth - - def stats(self, period='hour'): - """Get account stats. - - :param period: 'hour', 'day', 'week', 'month' - """ - resp = self._make_request('get', 'stats/%s' % period) - return resp.json() - - # QUEUE METHODS - - def get_queues(self, tags=None): - """Get listing of queues. - - :param list tags: (optional) list of tags to filter by - """ - params = {} - if tags: - params['tags'] = ','.join(tags) - resp = self._make_request('get', 'queues', params=params) - return resp.json() - - def create_queue(self, queue_name, **kwargs): - """Create Queue. - - :param queue_name: Queue Name - :param dict \\*\\*kwargs: queue options - """ - queue = {} - queue.update(kwargs) - data = json.dumps(queue) - resp = self._make_request('put', 'queues/%s' % queue_name, data=data) - return resp.json() - - def modify_queue(self, queue_name, **kwargs): - """Modify Queue. - - :param queue_name: Queue Name - :param dict \\*\\*kwargs: queue options - """ - return self.create_queue(queue_name, **kwargs) - - def get_queue(self, queue_name): - """Get queue details. - - :param queue_name: Queue Name - """ - resp = self._make_request('get', 'queues/%s' % queue_name) - return resp.json() - - def delete_queue(self, queue_name, force=False): - """Delete Queue. - - :param queue_name: Queue Name - :param force: (optional) Force queue to be deleted even if there - are pending messages - """ - params = {} - if force: - params['force'] = 1 - self._make_request('delete', 'queues/%s' % queue_name, params=params) - return True - - def push_queue_message(self, queue_name, body, **kwargs): - """Create Queue Message. - - :param queue_name: Queue Name - :param body: Message body - :param dict \\*\\*kwargs: Message options - """ - message = {'body': body} - message.update(kwargs) - resp = self._make_request('post', 'queues/%s/messages' % queue_name, - data=json.dumps(message)) - return resp.json() - - def pop_messages(self, queue_name, count=1): - """Pop messages from a queue. - - :param queue_name: Queue Name - :param count: (optional) number of messages to retrieve - """ - resp = self._make_request('get', 'queues/%s/messages' % queue_name, - params={'batch': count}) - return resp.json() - - def pop_message(self, queue_name): - """Pop a single message from a queue. - - If no messages are returned this returns None - - :param queue_name: Queue Name - """ - messages = self.pop_messages(queue_name, count=1) - if messages['item_count'] > 0: - return messages['items'][0] - else: - return None - - def delete_message(self, queue_name, message_id): - """Delete a message. - - :param queue_name: Queue Name - :param message_id: Message id - """ - self._make_request('delete', 'queues/%s/messages/%s' - % (queue_name, message_id)) - return True - - # TOPIC METHODS - - def get_topics(self, tags=None): - """Get listing of topics. - - :param list tags: (optional) list of tags to filter by - """ - params = {} - if tags: - params['tags'] = ','.join(tags) - resp = self._make_request('get', 'topics', params=params) - return resp.json() - - def create_topic(self, topic_name, **kwargs): - """Create Topic. - - :param topic_name: Topic Name - :param dict \\*\\*kwargs: Topic options - """ - data = json.dumps(kwargs) - resp = self._make_request('put', 'topics/%s' % topic_name, data=data) - return resp.json() - - def modify_topic(self, topic_name, **kwargs): - """Modify Topic. - - :param topic_name: Topic Name - :param dict \\*\\*kwargs: Topic options - """ - return self.create_topic(topic_name, **kwargs) - - def get_topic(self, topic_name): - """Get topic details. - - :param topic_name: Topic Name - """ - resp = self._make_request('get', 'topics/%s' % topic_name) - return resp.json() - - def delete_topic(self, topic_name, force=False): - """Delete Topic. - - :param topic_name: Topic Name - :param force: (optional) Force topic to be deleted even if there - are attached subscribers - """ - params = {} - if force: - params['force'] = 1 - self._make_request('delete', 'topics/%s' % topic_name, params=params) - return True - - def push_topic_message(self, topic_name, body, **kwargs): - """Create Topic Message. - - :param topic_name: Topic Name - :param body: Message body - :param dict \\*\\*kwargs: Topic message options - """ - message = {'body': body} - message.update(kwargs) - resp = self._make_request('post', 'topics/%s/messages' % topic_name, - data=json.dumps(message)) - return resp.json() - - def get_subscriptions(self, topic_name): - """Listing of subscriptions on a topic. - - :param topic_name: Topic Name - """ - resp = self._make_request('get', - 'topics/%s/subscriptions' % topic_name) - return resp.json() - - def create_subscription(self, topic_name, subscription_type, **kwargs): - """Create Subscription. - - :param topic_name: Topic Name - :param subscription_type: type ('queue' or 'http') - :param dict \\*\\*kwargs: Subscription options - """ - resp = self._make_request( - 'post', 'topics/%s/subscriptions' % topic_name, - data=json.dumps({ - 'endpoint_type': subscription_type, 'endpoint': kwargs})) - return resp.json() - - def delete_subscription(self, topic_name, subscription_id): - """Delete a subscription. - - :param topic_name: Topic Name - :param subscription_id: Subscription id - """ - self._make_request('delete', 'topics/%s/subscriptions/%s' % - (topic_name, subscription_id)) - return True diff --git a/tests/managers/queue_tests.py b/tests/managers/queue_tests.py deleted file mode 100644 index beecaf616..000000000 --- a/tests/managers/queue_tests.py +++ /dev/null @@ -1,467 +0,0 @@ -""" - SoftLayer.tests.managers.queue_tests - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - :license: MIT, see LICENSE for more details. -""" -import mock - -import SoftLayer -from SoftLayer import consts -from SoftLayer.managers import messaging -from SoftLayer import testing - -QUEUE_1 = { - 'expiration': 40000, - 'message_count': 0, - 'name': 'example_queue', - 'tags': ['tag1', 'tag2', 'tag3'], - 'visibility_interval': 10, - 'visible_message_count': 0} -QUEUE_LIST = {'item_count': 1, 'items': [QUEUE_1]} -MESSAGE_1 = { - 'body': '', - 'fields': {'field': 'value'}, - 'id': 'd344a01133b61181f57d9950a852eb10', - 'initial_entry_time': 1343402631.3917992, - 'message': 'Object created', - 'visibility_delay': 0, - 'visibility_interval': 30000} -MESSAGE_POP = { - 'item_count': 1, - 'items': [MESSAGE_1], -} -MESSAGE_POP_EMPTY = { - 'item_count': 0, - 'items': [] -} - -TOPIC_1 = {'name': 'example_topic', 'tags': ['tag1', 'tag2', 'tag3']} -TOPIC_LIST = {'item_count': 1, 'items': [TOPIC_1]} -SUBSCRIPTION_1 = { - 'endpoint': { - 'account_id': 'test', - 'queue_name': 'topic_subscription_queue'}, - 'endpoint_type': 'queue', - 'id': 'd344a01133b61181f57d9950a85704d4', - 'message': 'Object created'} -SUBSCRIPTION_LIST = {'item_count': 1, 'items': [SUBSCRIPTION_1]} - - -def mocked_auth_call(self): - self.auth_token = 'NEW_AUTH_TOKEN' - - -class QueueAuthTests(testing.TestCase): - def set_up(self): - self.auth = messaging.QueueAuth( - 'endpoint', 'username', 'api_key', auth_token='auth_token') - - def test_init(self): - auth = SoftLayer.managers.messaging.QueueAuth( - 'endpoint', 'username', 'api_key', auth_token='auth_token') - self.assertEqual(auth.endpoint, 'endpoint') - self.assertEqual(auth.username, 'username') - self.assertEqual(auth.api_key, 'api_key') - self.assertEqual(auth.auth_token, 'auth_token') - - @mock.patch('SoftLayer.managers.messaging.requests.post') - def test_auth(self, post): - post().headers = {'X-Auth-Token': 'NEW_AUTH_TOKEN'} - post().ok = True - self.auth.auth() - self.auth.auth_token = 'NEW_AUTH_TOKEN' - - post().ok = False - self.assertRaises(SoftLayer.Unauthenticated, self.auth.auth) - - @mock.patch('SoftLayer.managers.messaging.QueueAuth.auth', - mocked_auth_call) - def test_handle_error_200(self): - # No op on no error - request = mock.MagicMock() - request.status_code = 200 - self.auth.handle_error(request) - - self.assertEqual(self.auth.auth_token, 'auth_token') - self.assertFalse(request.request.send.called) - - @mock.patch('SoftLayer.managers.messaging.QueueAuth.auth', - mocked_auth_call) - def test_handle_error_503(self): - # Retry once more on 503 error - request = mock.MagicMock() - request.status_code = 503 - self.auth.handle_error(request) - - self.assertEqual(self.auth.auth_token, 'auth_token') - request.connection.send.assert_called_with(request.request) - - @mock.patch('SoftLayer.managers.messaging.QueueAuth.auth', - mocked_auth_call) - def test_handle_error_401(self): - # Re-auth on 401 - request = mock.MagicMock() - request.status_code = 401 - request.request.headers = {'X-Auth-Token': 'OLD_AUTH_TOKEN'} - self.auth.handle_error(request) - - self.assertEqual(self.auth.auth_token, 'NEW_AUTH_TOKEN') - request.connection.send.assert_called_with(request.request) - - @mock.patch('SoftLayer.managers.messaging.QueueAuth.auth', - mocked_auth_call) - def test_call_unauthed(self): - request = mock.MagicMock() - request.headers = {} - self.auth.auth_token = None - self.auth(request) - - self.assertEqual(self.auth.auth_token, 'NEW_AUTH_TOKEN') - request.register_hook.assert_called_with( - 'response', self.auth.handle_error) - self.assertEqual(request.headers, {'X-Auth-Token': 'NEW_AUTH_TOKEN'}) - - -class MessagingManagerTests(testing.TestCase): - - def set_up(self): - self.client = mock.MagicMock() - self.manager = SoftLayer.MessagingManager(self.client) - - def test_list_accounts(self): - self.manager.list_accounts() - self.client['Account'].getMessageQueueAccounts.assert_called_with( - mask=mock.ANY) - - def test_get_endpoints(self): - endpoints = self.manager.get_endpoints() - self.assertEqual(endpoints, SoftLayer.managers.messaging.ENDPOINTS) - - @mock.patch('SoftLayer.managers.messaging.ENDPOINTS', { - 'datacenter01': { - 'private': 'private_endpoint', 'public': 'public_endpoint'}, - 'dal05': { - 'private': 'dal05_private', 'public': 'dal05_public'}}) - def test_get_endpoint(self): - # Defaults to dal05, public - endpoint = self.manager.get_endpoint() - self.assertEqual(endpoint, 'https://dal05_public') - - endpoint = self.manager.get_endpoint(network='private') - self.assertEqual(endpoint, 'https://dal05_private') - - endpoint = self.manager.get_endpoint(datacenter='datacenter01') - self.assertEqual(endpoint, 'https://public_endpoint') - - endpoint = self.manager.get_endpoint(datacenter='datacenter01', - network='private') - self.assertEqual(endpoint, 'https://private_endpoint') - - endpoint = self.manager.get_endpoint(datacenter='datacenter01', - network='private') - self.assertEqual(endpoint, 'https://private_endpoint') - - # ERROR CASES - self.assertRaises( - TypeError, - self.manager.get_endpoint, datacenter='doesnotexist') - - self.assertRaises( - TypeError, - self.manager.get_endpoint, network='doesnotexist') - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection') - def test_get_connection(self, conn): - queue_conn = self.manager.get_connection('QUEUE_ACCOUNT_ID') - conn.assert_called_with( - 'QUEUE_ACCOUNT_ID', endpoint='https://dal05.mq.softlayer.net') - conn().authenticate.assert_called_with( - self.client.auth.username, self.client.auth.api_key) - self.assertEqual(queue_conn, conn()) - - def test_get_connection_no_auth(self): - self.client.auth = None - self.assertRaises(SoftLayer.SoftLayerError, - self.manager.get_connection, 'QUEUE_ACCOUNT_ID') - - def test_get_connection_no_username(self): - self.client.auth.username = None - self.assertRaises(SoftLayer.SoftLayerError, - self.manager.get_connection, 'QUEUE_ACCOUNT_ID') - - def test_get_connection_no_api_key(self): - self.client.auth.api_key = None - self.assertRaises(SoftLayer.SoftLayerError, - self.manager.get_connection, 'QUEUE_ACCOUNT_ID') - - @mock.patch('SoftLayer.managers.messaging.requests.get') - def test_ping(self, get): - result = self.manager.ping() - - get.assert_called_with('https://dal05.mq.softlayer.net/v1/ping') - get().raise_for_status.assert_called_with() - self.assertTrue(result) - - -class MessagingConnectionTests(testing.TestCase): - - def set_up(self): - self.conn = SoftLayer.managers.messaging.MessagingConnection( - 'acount_id', endpoint='endpoint') - self.auth = mock.MagicMock() - self.conn.auth = self.auth - - def test_init(self): - self.assertEqual(self.conn.account_id, 'acount_id') - self.assertEqual(self.conn.endpoint, 'endpoint') - self.assertEqual(self.conn.auth, self.auth) - - @mock.patch('SoftLayer.managers.messaging.requests.request') - def test_make_request(self, request): - resp = self.conn._make_request('GET', 'path') - request.assert_called_with( - 'GET', 'endpoint/v1/acount_id/path', - headers={ - 'Content-Type': 'application/json', - 'User-Agent': consts.USER_AGENT}, - auth=self.auth) - request().raise_for_status.assert_called_with() - self.assertEqual(resp, request()) - - @mock.patch('SoftLayer.managers.messaging.QueueAuth') - def test_authenticate(self, auth): - self.conn.authenticate('username', 'api_key', auth_token='auth_token') - - auth.assert_called_with( - 'endpoint/v1/acount_id/auth', 'username', 'api_key', - auth_token='auth_token') - auth().auth.assert_called_with() - self.assertEqual(self.conn.auth, auth()) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_stats(self, make_request): - content = { - 'notifications': [{'key': [2012, 7, 27, 14, 31], 'value': 2}], - 'requests': [{'key': [2012, 7, 27, 14, 31], 'value': 11}]} - make_request().json.return_value = content - result = self.conn.stats() - - make_request.assert_called_with('get', 'stats/hour') - self.assertEqual(content, result) - - # Queue-based Tests - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_get_queues(self, make_request): - make_request().json.return_value = QUEUE_LIST - result = self.conn.get_queues() - - make_request.assert_called_with('get', 'queues', params={}) - self.assertEqual(QUEUE_LIST, result) - - # with tags - result = self.conn.get_queues(tags=['tag1', 'tag2']) - - make_request.assert_called_with( - 'get', 'queues', params={'tags': 'tag1,tag2'}) - self.assertEqual(QUEUE_LIST, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_create_queue(self, make_request): - make_request().json.return_value = QUEUE_1 - result = self.conn.create_queue('example_queue') - - make_request.assert_called_with( - 'put', 'queues/example_queue', data='{}') - self.assertEqual(QUEUE_1, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_modify_queue(self, make_request): - make_request().json.return_value = QUEUE_1 - result = self.conn.modify_queue('example_queue') - - make_request.assert_called_with( - 'put', 'queues/example_queue', data='{}') - self.assertEqual(QUEUE_1, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_get_queue(self, make_request): - make_request().json.return_value = QUEUE_1 - result = self.conn.get_queue('example_queue') - - make_request.assert_called_with('get', 'queues/example_queue') - self.assertEqual(QUEUE_1, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_delete_queue(self, make_request): - result = self.conn.delete_queue('example_queue') - make_request.assert_called_with( - 'delete', 'queues/example_queue', params={}) - self.assertTrue(result) - - # With Force - result = self.conn.delete_queue('example_queue', force=True) - make_request.assert_called_with( - 'delete', 'queues/example_queue', params={'force': 1}) - self.assertTrue(result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_push_queue_message(self, make_request): - make_request().json.return_value = MESSAGE_1 - result = self.conn.push_queue_message('example_queue', '') - - make_request.assert_called_with( - 'post', 'queues/example_queue/messages', data='{"body": ""}') - self.assertEqual(MESSAGE_1, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_pop_messages(self, make_request): - make_request().json.return_value = MESSAGE_POP - result = self.conn.pop_messages('example_queue') - - make_request.assert_called_with( - 'get', 'queues/example_queue/messages', params={'batch': 1}) - self.assertEqual(MESSAGE_POP, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_pop_message(self, make_request): - make_request().json.return_value = MESSAGE_POP - result = self.conn.pop_message('example_queue') - - make_request.assert_called_with( - 'get', 'queues/example_queue/messages', params={'batch': 1}) - self.assertEqual(MESSAGE_1, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_pop_message_empty(self, make_request): - make_request().json.return_value = MESSAGE_POP_EMPTY - result = self.conn.pop_message('example_queue') - - make_request.assert_called_with( - 'get', 'queues/example_queue/messages', params={'batch': 1}) - self.assertEqual(None, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_delete_message(self, make_request): - result = self.conn.delete_message('example_queue', MESSAGE_1['id']) - - make_request.assert_called_with( - 'delete', 'queues/example_queue/messages/%s' % MESSAGE_1['id']) - self.assertTrue(result) - - # Topic-based Tests - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_get_topics(self, make_request): - make_request().json.return_value = TOPIC_LIST - result = self.conn.get_topics() - - make_request.assert_called_with('get', 'topics', params={}) - self.assertEqual(TOPIC_LIST, result) - - # with tags - result = self.conn.get_topics(tags=['tag1', 'tag2']) - - make_request.assert_called_with( - 'get', 'topics', params={'tags': 'tag1,tag2'}) - self.assertEqual(TOPIC_LIST, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_create_topic(self, make_request): - make_request().json.return_value = TOPIC_1 - result = self.conn.create_topic('example_topic') - - make_request.assert_called_with( - 'put', 'topics/example_topic', data='{}') - self.assertEqual(TOPIC_1, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_modify_topic(self, make_request): - make_request().json.return_value = TOPIC_1 - result = self.conn.modify_topic('example_topic') - - make_request.assert_called_with( - 'put', 'topics/example_topic', data='{}') - self.assertEqual(TOPIC_1, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_get_topic(self, make_request): - make_request().json.return_value = TOPIC_1 - result = self.conn.get_topic('example_topic') - - make_request.assert_called_with('get', 'topics/example_topic') - self.assertEqual(TOPIC_1, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_delete_topic(self, make_request): - result = self.conn.delete_topic('example_topic') - make_request.assert_called_with( - 'delete', 'topics/example_topic', params={}) - self.assertTrue(result) - - # With Force - result = self.conn.delete_topic('example_topic', force=True) - make_request.assert_called_with( - 'delete', 'topics/example_topic', params={'force': 1}) - self.assertTrue(result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_push_topic_message(self, make_request): - make_request().json.return_value = MESSAGE_1 - result = self.conn.push_topic_message('example_topic', '') - - make_request.assert_called_with( - 'post', 'topics/example_topic/messages', data='{"body": ""}') - self.assertEqual(MESSAGE_1, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_get_subscriptions(self, make_request): - make_request().json.return_value = SUBSCRIPTION_LIST - result = self.conn.get_subscriptions('example_topic') - - make_request.assert_called_with( - 'get', 'topics/example_topic/subscriptions') - self.assertEqual(SUBSCRIPTION_LIST, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection' - '._make_request') - def test_create_subscription(self, make_request): - make_request().json.return_value = SUBSCRIPTION_1 - endpoint_details = { - 'account_id': 'test', - 'queue_name': 'topic_subscription_queue'} - result = self.conn.create_subscription( - 'example_topic', 'queue', **endpoint_details) - - make_request.assert_called_with( - 'post', 'topics/example_topic/subscriptions', data=mock.ANY) - self.assertEqual(SUBSCRIPTION_1, result) - - @mock.patch('SoftLayer.managers.messaging.MessagingConnection.' - '_make_request') - def test_delete_subscription(self, make_request): - make_request().json.return_value = SUBSCRIPTION_1 - result = self.conn.delete_subscription( - 'example_topic', SUBSCRIPTION_1['id']) - - make_request.assert_called_with( - 'delete', - 'topics/example_topic/subscriptions/%s' % SUBSCRIPTION_1['id']) - self.assertTrue(result) From 8ef829cd63e9b52aa38161ce0448b3eebf5aa122 Mon Sep 17 00:00:00 2001 From: Christopher Gallo Date: Tue, 26 Feb 2019 21:04:40 -0600 Subject: [PATCH 2/2] #1089 fixed old docs --- docs/api/managers/messaging.rst | 5 ----- docs/cli.rst | 37 +++++++++++++++++---------------- docs/index.rst | 11 ++++------ 3 files changed, 23 insertions(+), 30 deletions(-) delete mode 100644 docs/api/managers/messaging.rst diff --git a/docs/api/managers/messaging.rst b/docs/api/managers/messaging.rst deleted file mode 100644 index f86bbc980..000000000 --- a/docs/api/managers/messaging.rst +++ /dev/null @@ -1,5 +0,0 @@ -.. _messaging: - -.. automodule:: SoftLayer.managers.messaging - :members: - :inherited-members: diff --git a/docs/cli.rst b/docs/cli.rst index 7701dc625..bf79aa697 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -60,43 +60,43 @@ Usage Examples To discover the available commands, simply type `slcli`. :: - $ slcli + $ slcli Usage: slcli [OPTIONS] COMMAND [ARGS]... - + SoftLayer Command-line Client - + Options: - --format [table|raw|json|jsonraw] - Output format [default: table] - -C, --config PATH Config file location [default: - ~/.softlayer] - -v, --verbose Sets the debug noise level, specify multiple - times for more verbosity. - --proxy TEXT HTTP[S] proxy to be use to make API calls - -y, --really / --not-really Confirm all prompt actions - --demo / --no-demo Use demo data instead of actually making API - calls - --version Show the version and exit. - -h, --help Show this message and exit. - + --format [table|raw|json|jsonraw] Output format [default: raw] + -C, --config PATH Config file location [default: ~\.softlayer] + -v, --verbose Sets the debug noise level, specify multiple times for more verbosity. + --proxy TEXT HTTP[S] proxy to be use to make API calls + -y, --really / --not-really Confirm all prompt actions + --demo / --no-demo Use demo data instead of actually making API calls + --version Show the version and exit. + -h, --help Show this message and exit. + Commands: block Block Storage. call-api Call arbitrary API endpoints. cdn Content Delivery Network. config CLI configuration. + dedicatedhost Dedicated Host. dns Domain Name System. + event-log Event Logs. file File Storage. firewall Firewalls. globalip Global IP addresses. hardware Hardware servers. image Compute images. + ipsec IPSEC VPN loadbal Load balancers. - messaging Message queue service. metadata Find details about this machine. nas Network Attached Storage. object-storage Object Storage. + order View and order from the catalog. report Reports. rwhois Referral Whois. + securitygroup Network security groups. setup Edit configuration. shell Enters a shell for slcli. sshkey SSH Keys. @@ -104,9 +104,10 @@ To discover the available commands, simply type `slcli`. subnet Network subnets. summary Account summary. ticket Support tickets. + user Manage Users. virtual Virtual Servers. vlan Network VLANs. - + To use most commands your SoftLayer username and api_key need to be configured. The easiest way to do that is to use: 'slcli setup' diff --git a/docs/index.rst b/docs/index.rst index d4bf7dd70..1b3c2b390 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -2,17 +2,15 @@ SoftLayer API Python Client |version| ======================================== -`API Docs `_ ``|`` +`API Docs `_ ``|`` `GitHub `_ ``|`` `Issues `_ ``|`` `Pull Requests `_ ``|`` `PyPI `_ ``|`` -`Twitter `_ ``|`` -`#softlayer on freenode `_ This is the documentation to SoftLayer's Python API Bindings. These bindings -use SoftLayer's `XML-RPC interface `_ +use SoftLayer's `XML-RPC interface `_ in order to manage SoftLayer services. .. toctree:: @@ -38,10 +36,9 @@ Contributing External Links -------------- -* `SoftLayer API Documentation `_ +* `SoftLayer API Documentation `_ * `Source on GitHub `_ * `Issues `_ * `Pull Requests `_ * `PyPI `_ -* `Twitter `_ -* `#softlayer on freenode `_ +