Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
 def execute(self, args):
     manager = SoftLayer.MessagingManager(self.client)
     okay = manager.ping(datacenter=args['--datacenter'],
                         network=args['--network'])
     if okay:
         return 'OK'
     else:
         exceptions.CLIAbort('Ping failed')
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
 def execute(self, args):
     manager = SoftLayer.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]
Ejemplo n.º 6
0
    def execute(self, args):
        manager = SoftLayer.MessagingManager(self.client)
        mq_client = manager.get_connection(args['<account_id>'])
        topics = mq_client.get_topics()['items']

        table = formatting.Table(['name'])
        for topic in topics:
            table.add_row([topic['name']])
        return table
Ejemplo n.º 7
0
    def execute(self, args):
        manager = SoftLayer.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'))
Ejemplo n.º 8
0
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:
        return 'OK'
    else:
        exceptions.CLIAbort('Ping failed')
Ejemplo n.º 9
0
 def execute(self, args):
     manager = SoftLayer.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))
Ejemplo n.º 10
0
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
    return mq.message_table(mq_client.push_queue_message(queue_name, body))
Ejemplo n.º 11
0
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)
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
    def execute(self, args):
        manager = SoftLayer.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))
Ejemplo n.º 14
0
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])
Ejemplo n.º 15
0
    def execute(self, args):
        manager = SoftLayer.MessagingManager(self.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(),
            ])

        return table
Ejemplo n.º 16
0
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)))
Ejemplo n.º 17
0
    def execute(self, args):
        manager = SoftLayer.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(',')]

        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)
Ejemplo n.º 18
0
    def execute(self, args):
        manager = SoftLayer.MessagingManager(self.client)
        mq_client = manager.get_connection(args['<account_id>'])

        messages = mq_client.pop_messages(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
Ejemplo n.º 19
0
    def execute(self, args):
        manager = SoftLayer.MessagingManager(self.client)
        mq_client = manager.get_connection(args['<account_id>'])

        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'],
            ])
        return table
Ejemplo n.º 20
0
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(),
        ])

    return table
Ejemplo n.º 21
0
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,
    )
    return mq.topic_table(topic)
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
    def execute(self, args):
        manager = SoftLayer.MessagingManager(self.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'],
            ])

        return table
Ejemplo n.º 24
0
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)
Ejemplo n.º 25
0
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))
Ejemplo n.º 26
0
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']
        ])
    return table
Ejemplo n.º 27
0
    def connect(self, access, authentication_data, region):
        '''
        TBD
        '''

        try:
            _status = 100
            _fmsg = "An error has occurred, but no error message was captured"

            _username, _api_key, _api_type = authentication_data.split('-')
            if access.lower().count("private"):
                self.slconn = SoftLayer.create_client_from_env (username = _username.strip(), \
                                                                api_key= _api_key.strip(), \
                                                                endpoint_url = SoftLayer.API_PRIVATE_ENDPOINT)
            else:
                self.slconn = SoftLayer.create_client_from_env (username = _username.strip(), \
                                                                api_key= _api_key.strip(), \
                                                                endpoint_url = SoftLayer.API_PUBLIC_ENDPOINT)

            _resp = self.slconn.call('Account', 'getObject')

            _regions = SoftLayer.MessagingManager(self.slconn).get_endpoints()
            _region = region
            if region in _regions:
                if access.lower() in _regions[region]:
                    _region = _regions[region][access.lower()]

            _msg = "Selected region is " + str(region) + " (" + _region + ")"

            if _api_type.lower().count("baremetal"):
                self.nodeman = SoftLayer.HardwareManager(self.slconn)
            else:
                self.nodeman = SoftLayer.VSManager(self.slconn)

            self.sshman = SoftLayer.SshKeyManager(self.slconn)

            self.imageman = SoftLayer.ImageManager(self.slconn)

            _status = 0

        except Exception, msg:
            _fmsg = str(msg)
            _status = 23
Ejemplo n.º 28
0
 def execute(self, args):
     manager = SoftLayer.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 exceptions.ArgumentError(
             '--type should be either queue or http.')
     return subscription_table(subscription)
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))
Ejemplo n.º 30
0
 def set_up(self):
     self.client = mock.MagicMock()
     self.manager = SoftLayer.MessagingManager(self.client)