Пример #1
0
    def execute(self, args):
        manager = MessagingManager(self.client)
        mq_client = manager.get_connection(args['<account_id>'])

        mq_client.delete_subscription(
            args['<topic_name>'],
            args['<subscription_id>'])
Пример #2
0
 def execute(self, args):
     manager = MessagingManager(self.client)
     okay = manager.ping(
         datacenter=args['--datacenter'], network=args['--network'])
     if okay:
         return 'OK'
     else:
         CLIAbort('Ping failed')
Пример #3
0
    def execute(self, args):
        manager = MessagingManager(self.client)
        mq_client = manager.get_connection(args['<account_id>'])

        if args['<message_id>']:
            mq_client.delete_message(args['<queue_name>'],
                                     args['<message_id>'])
        else:
            mq_client.delete_queue(args['<queue_name>'], args.get('--force'))
Пример #4
0
def queue_list(account_id):
    manager = MessagingManager(get_client())
    mq_client = manager.get_connection(account_id)

    queues = mq_client.get_queues()['items']

    print queues

    return ''
Пример #5
0
    def execute(self, args):
        manager = MessagingManager(self.client)
        mq_client = manager.get_connection(args['<account_id>'])
        topics = mq_client.get_topics()['items']

        table = Table(['name'])
        for topic in topics:
            table.add_row([topic['name']])
        return table
Пример #6
0
 def execute(self, args):
     manager = MessagingManager(self.client)
     mq_client = manager.get_connection(args['<account_id>'])
     topic = mq_client.get_topic(args['<topic_name>'])
     subscriptions = mq_client.get_subscriptions(args['<topic_name>'])
     tables = []
     for sub in subscriptions['items']:
         tables.append(subscription_table(sub))
     return [topic_table(topic), tables]
 def execute(cls, client, args):
     manager = MessagingManager(client)
     mq_client = manager.get_connection(args['<account_id>'])
     body = ''
     if args['<message>'] is not None:
         body = args['<message>']
     else:
         body = sys.stdin.read()
     return message_table(
         mq_client.push_queue_message(args['<queue_name>'], body))
Пример #8
0
 def execute(self, args):
     manager = MessagingManager(self.client)
     mq_client = manager.get_connection(args['<account_id>'])
     body = ''
     if args['<message>'] == '-':
         body = sys.stdin.read()
     else:
         body = args['<message>']
     return message_table(
         mq_client.push_queue_message(args['<queue_name>'], body))
Пример #9
0
    def execute(self, args):
        manager = MessagingManager(self.client)
        mq_client = manager.get_connection(args['<account_id>'])

        # the message body comes from the positional argument or stdin
        body = ''
        if args['<message>'] == '-':
            body = sys.stdin.read()
        else:
            body = args['<message>']
        return message_table(
            mq_client.push_topic_message(args['<topic_name>'], body))
Пример #10
0
    def execute(self, args):
        manager = MessagingManager(self.client)
        mq_client = manager.get_connection(args['<account_id>'])
        tags = None
        if args.get('--tags'):
            tags = [tag.strip() for tag in args.get('--tags').split(',')]

        queue = mq_client.create_queue(
            args['<queue_name>'],
            visibility_interval=int(args.get('--visibility_interval') or 30),
            expiration=int(args.get('--expiration') or 604800),
            tags=tags,
        )
        return queue_table(queue)
Пример #11
0
    def execute(cls, client, args):
        manager = MessagingManager(client)
        mq_client = manager.get_connection(args['<account_id>'])
        tags = None
        if args.get('--tags'):
            tags = [tag.strip() for tag in args.get('--tags').split(',')]

        topic = mq_client.create_topic(
            args['<topic_name>'],
            visibility_interval=int(
                args.get('--visibility_interval') or 30),
            expiration=int(args.get('--expiration') or 604800),
            tags=tags,
        )
        return topic_table(topic)
Пример #12
0
    def execute(self, args):
        manager = MessagingManager(self.client)
        regions = manager.get_endpoints()

        table = Table([
            'name', 'public', 'private'
        ])
        for region, endpoints in regions.items():
            table.add_row([
                region,
                endpoints.get('public') or blank(),
                endpoints.get('private') or blank(),
            ])

        return table
Пример #13
0
    def execute(client, args):
        manager = MessagingManager(client)
        accounts = manager.list_accounts()

        t = Table([
            'id', 'name', 'status'
        ])
        for account in accounts:
            t.add_row([
                account['nodes'][0]['accountName'],
                account['name'],
                account['status']['name'],
            ])

        return t
Пример #14
0
    def execute(self, args):
        manager = MessagingManager(self.client)
        mq_client = manager.get_connection(args['<account_id>'])

        queues = mq_client.get_queues()['items']

        table = Table([
            'name', 'message_count', 'visible_message_count'
        ])
        for queue in queues:
            table.add_row([
                queue['name'],
                queue['message_count'],
                queue['visible_message_count'],
            ])
        return table
Пример #15
0
    def execute(self, args):
        manager = MessagingManager(self.client)
        mq_client = manager.get_connection(args['<account_id>'])

        messages = mq_client.pop_message(
            args['<queue_name>'],
            args.get('--count') or 1)
        formatted_messages = []
        for message in messages['items']:
            formatted_messages.append(message_table(message))

        if args.get('--delete-after'):
            for message in messages['items']:
                mq_client.delete_message(
                    args['<queue_name>'],
                    message['id'])
        return formatted_messages
Пример #16
0
    def execute(self, args):
        manager = MessagingManager(self.client)
        accounts = manager.list_accounts()

        table = 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'],
            ])

        return table
Пример #17
0
 def execute(self, args):
     manager = MessagingManager(self.client)
     mq_client = manager.get_connection(args['<account_id>'])
     if args['--type'] == 'queue':
         subscription = mq_client.create_subscription(
             args['<topic_name>'],
             'queue',
             queue_name=args['--queue-name'],
         )
     elif args['--type'] == 'http':
         subscription = mq_client.create_subscription(
             args['<topic_name>'],
             'http',
             method=args['--http-method'] or 'GET',
             url=args['--http-url'],
             body=args['--http-body']
         )
     else:
         raise ArgumentError(
             '--type should be either queue or http.')
     return subscription_table(subscription)
Пример #18
0
 def setUp(self):
     self.client = MagicMock()
     self.manager = MessagingManager(self.client)
Пример #19
0
 def execute(self, args):
     manager = MessagingManager(self.client)
     mq_client = manager.get_connection(args['<account_id>'])
     mq_client.delete_topic(args['<topic_name>'], args.get('--force'))
Пример #20
0
 def execute(self, args):
     manager = MessagingManager(self.client)
     mq_client = manager.get_connection(args['<account_id>'])
     queue = mq_client.get_queue(args['<queue_name>'])
     return queue_table(queue)
Пример #21
0
 def render(self):
     mgr = MessagingManager(get_client())
     return render_template('mq_widget_summary.html',
                            accounts=mgr.list_accounts())
Пример #22
0
class MessagingManagerTests(unittest.TestCase):

    def setUp(self):
        self.client = MagicMock()
        self.manager = MessagingManager(self.client)

    def test_list_accounts(self):
        self.manager.list_accounts()
        self.client['Account'].getMessageQueueAccounts.assert_called_with(
            mask=ANY)

    def test_get_endpoints(self):
        endpoints = self.manager.get_endpoints()
        self.assertEqual(endpoints, SoftLayer.managers.messaging.ENDPOINTS)

    @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')

    @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(SoftLayerError,
                          self.manager.get_connection, 'QUEUE_ACCOUNT_ID')

    def test_get_connection_no_username(self):
        self.client.auth.username = None
        self.assertRaises(SoftLayerError,
                          self.manager.get_connection, 'QUEUE_ACCOUNT_ID')

    def test_get_connection_no_api_key(self):
        self.client.auth.api_key = None
        self.assertRaises(SoftLayerError,
                          self.manager.get_connection, 'QUEUE_ACCOUNT_ID')

    @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)