messaging Package

messaging Package

Roles in this namespace are meant to enable message queueing service management as RabbitMq, Apache Qpid and such, in CentOS distributions.

rabbitmq Module

Roles in this namespace are meant to provide RabbitMQ utilities methods within CentOS distributions.

class provy.more.centos.messaging.rabbitmq.RabbitMqRole(prov, context)[source]

Bases: provy.core.roles.Role

This role provides utility methods for RabbitMQ utilities within CentOS distributions.

Example:

from provy.core import Role
from provy.more.centos import RabbitMqRole
from provy.more.centos import HostNameRole

class MySampleRole(Role):
    def provision(self):

        with self.using(HostNameRole) as role:
            # From rabbitmq docs [1]:
            # "RabbitMQ names the database directory using the current
            # hostname of the system. If the hostname changes, a new empty
            # database is created.  To avoid data loss it's crucial to set
            # up a fixed and resolvable hostname"
            #
            # [1] http://www.rabbitmq.com/ec2.html

            role.ensure_hostname('rabbit')

        with self.using(RabbitMqRole) as role:
            role.delete_user('guest')
            role.ensure_user(
                self.context['rabbit_user'],
                self.context['rabbit_password'],
            )
            role.ensure_vhost(self.context['rabbit_vhost'])
            role.ensure_permission(
                self.context['rabbit_vhost'],
                self.context['rabbit_user'],
                '".*" ".*" ".*"',
            )
delete_user(user)[source]

Delete user from rabbitmq if exists

Parameters:user (str) – Name of the user to be deleted.

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(RabbitMqRole) as role:
            role.delete_user('guest', some_pass)
ensure_permission(vhost, username, perms)[source]

Ensure the given user has the given permissions on the specified vhost

Parameters:
  • vhost (str) – Virtual host name to assign the permissions at.
  • username (str) – User to assign permissions to.
  • perms (str) – Permissions to assign to user (e.g.: ‘”.*” ”.*” ”.*”’).
Returns:

Whether the permissions could be assigned or not.

Return type:

bool

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(RabbitMqRole) as role:
            role.ensure_permission(
                'previous_created_vhost',
                'previous_created_user',
                '".*" ".*" ".*"',
            )
ensure_user(username, password, is_admin=False)[source]

Ensure the given user is created in the database and can authenticate with RabbitMQ.

Parameters:
  • username (str) – Name of the user to be created.
  • password (str) – Password that the user will use to authenticate to RabbitMQ.
Returns:

Whether the user had to be created or not.

Return type:

bool

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(RabbitMqRole) as role:
            role.ensure_user(some_user, some_pass)
ensure_vhost(vhost)[source]

Ensure the given vhost is created.

Parameters:vhost (str) – Name of the vhost to be checked/created.
Returns:Whether the vhost had to be created or not.
Return type:bool

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(RabbitMqRole) as role:
            role.ensure_vhost('/some_vhost')
provision()[source]

Installs RabbitMQ and dependencies. This method should be called upon if overriden in base classes, or RabbitMQ won’t work properly in the remote server.

Example:

from provy.core import Role
from provy.more.centos import HgRole

class MySampleRole(Role):
    def provision(self):
        self.provision_role(RabbitMqRole)
user_exists(username)[source]

Checks if the RabbitMQ user exists.

Parameters:username (str) – Name of the user to be checked.
Returns:Whether the user exists or not.
Return type:bool

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(RabbitMqRole) as role:
            role.user_exists('johndoe')
vhost_exists(vhost)[source]

Checks if the RabbitMQ vhost exists.

Parameters:vhost (str) – Name of the vhost to be checked.
Returns:Whether the vhost exists or not.
Return type:bool

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(RabbitMqRole) as role:
            role.vhost_exists('foobarhost')