cache Package

cache Package

Roles in this namespace are meant to provision caching engines, such as Varnish or Memcached in Debian distributions.

memcached Module

Roles in this namespace are meant to provide Memcached configuration and execution utilities within Debian distributions.

class provy.more.debian.cache.memcached.MemcachedRole(prov, context)[source]

Bases: provy.core.roles.Role

This role provides utility methods for Memcached configuration and execution within Debian distributions.

Example:

from provy.core import Role
from provy.more.debian import Memcached

class MySampleRole(Role):
    def provision(self):
        with self.using(MemcachedRole) as role:
            role.ensure_conf(verbose_level=2)
cleanup()[source]

Restarts memcached if it needs to be restarted (any changes made during this server’s provisioning).

Example:

from provy.core import Role
from provy.more.debian import MemcachedRole

class MySampleRole(Role):
    def provision(self):
        with self.using(MemcachedRole) as role:
            role.cleanup() # No need to call this if using a with block.
ensure_conf(owner=None, log_folder='/var/log/memcached', verbose_level=0, memory_in_mb=64, host='127.0.0.1', port=11211, user='nobody', simultaneous_connections=1024, lock_down=False, error_when_memory_exhausted=False, maximize_core_file_limit=False, conf_path='/etc/memcached.conf')[source]

Ensures that Memcached’s configuration file at the specified path is up-to-date.

Parameters:
  • owner (str) – Owner of the config file. Defaults to root.
  • log_folder (str) – Log memcached’s output. Defaults to /var/log/memcached.
  • verbose_level (int) – 0 for no verbosity, 1 for verbose, 2 for extra-verbose. Defaults to 0.
  • memory_in_mb (int) – Start with a cap of 64 megs of memory. It’s reasonable, and the daemon default. Note that the daemon will grow to this size, but does not start out holding this much memory.
  • host (str) – Specify which IP address to listen on. The default is to listen on all IP addresses. This parameter is one of the only security measures that memcached has, so make sure it’s listening on a firewalled interface. Defaults to 127.0.0.1.
  • port (int) – Default connection port is 11211.
  • user (str) – Run the daemon as this user. Defaults to “nobody”.
  • simultaneous_connections (int) – Limit the number of simultaneous incoming connections. The default is 1024.
  • lock_down (bool) – Whether it should lock down all paged memory. Consult with the Memcached README and homepage before you do this. Defaults to False.
  • error_when_memory_exhausted (bool) – Whether it should return error when memory is exhausted (rather than removing items). Defaults to False.
  • maximize_core_file_limit (bool) – Whether it should maximize core file limit. Defaults to False.
  • conf_path (str) – The path that the configuration file will be in the remote server. Defaults to /etc/memcached.conf.

Example:

from provy.core import Role
from provy.more.debian import MemcachedRole

class MySampleRole(Role):
    def provision(self):
        with self.using(MemcachedRole) as role:
            role.ensure_conf()
ensure_restart()[source]

Ensures that Memcached is restarted on cleanup phase.

Example:

from provy.core import Role
from provy.more.debian import MemcachedRole

class MySampleRole(Role):
    def provision(self):
        with self.using(MemcachedRole) as role:
            role.ensure_restart() # No need to call this if using a with block.
provision()[source]

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

Example:

from provy.core import Role
from provy.more.debian import MemcachedRole

class MySampleRole(Role):
    def provision(self):
        self.provision_role(MemcachedRole) # does not need to be called if using with block.
restart()[source]

Forcefully restarts Memcached in the remote server.

Example:

from provy.core import Role
from provy.more.debian import MemcachedRole

class MySampleRole(Role):
    def provision(self):
        with self.using(MemcachedRole) as role:
            if not self.is_process_running('memcached'):
                role.restart()

varnish Module

Roles in this namespace are meant to provide Varnish configuration and execution utilities within Debian distributions.

class provy.more.debian.cache.varnish.VarnishRole(prov, context)[source]

Bases: provy.core.roles.Role

This role provides utility methods for Varnish configuration and execution within Debian distributions.

Example:

from provy.core import Role
from provy.more.debian import VarnishRole

class MySampleRole(Role):
    def provision(self):
        with self.using(VarnishRole) as role:
            role.ensure_vcl('default.vcl', owner='user')
            role.ensure_conf('default_varnish', owner='user')
cleanup()[source]

Restarts Varnish if it needs to be restarted (any changes made during this server’s provisioning).

Example:

from provy.core import Role
from provy.more.debian import VarnishRole

class MySampleRole(Role):
    def provision(self):
        with self.using(VarnishRole) as role:
            role.cleanup() # No need to call this if using a with block.
ensure_conf(template, varnish_conf_path='/etc/default/varnish', options={}, owner=None)[source]

Ensures that Varnish’s configuration file at the specified path is up-to-date.

Parameters:
  • template (str) – The name of the VCL template file.
  • varnish_conf_path (str) – The path that the configuration file will be in the remote server. Defaults to /etc/default/varnish.
  • options (dict) – Dictionary of options to pass to the configuration template file. Extends context.
  • owner (str) – Owner of the configuration file at the remote server. Defaults to None.

Example:

from provy.core import Role
from provy.more.debian import VarnishRole

class MySampleRole(Role):
    def provision(self):
        with self.using(VarnishRole) as role:
            role.ensure_conf('default_varnish', owner='user')
ensure_restart()[source]

Ensures that Varnish is restarted on cleanup phase.

Example:

from provy.core import Role
from provy.more.debian import VarnishRole

class MySampleRole(Role):
    def provision(self):
        with self.using(VarnishRole) as role:
            role.ensure_restart() # No need to call this if using a with block.
ensure_vcl(template, varnish_vcl_path='/etc/varnish/default.vcl', options={}, owner=None)[source]

Ensures that the VCL file at the specified path is up-to-date.

Parameters:
  • template (str) – The name of the VCL template file.
  • varnish_vcl_path (str) – The path that the VCL file will be in the remote server. Defaults to /etc/varnish/default.vcl.
  • options (dict) – Dictionary of options to pass to the VCL template file. Extends context.
  • owner (str) – Owner of the VCL file at the remote server. Defaults to None.

Example:

from provy.core import Role
from provy.more.debian import VarnishRole

class MySampleRole(Role):
    def provision(self):
        with self.using(VarnishRole) as role:
            role.ensure_vcl('default.vcl', owner='user')
provision()[source]

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

Example:

from provy.core import Role
from provy.more.debian import VarnishRole

class MySampleRole(Role):
    def provision(self):
        self.provision_role(VarnishRole) # does not need to be called if using with block.
restart()[source]

Forcefully restarts Varnish in the remote server.

Example:

from provy.core import Role
from provy.more.debian import VarnishRole

class MySampleRole(Role):
    def provision(self):
        with self.using(VarnishRole) as role:
            if not self.is_process_running('varnishd'):
                role.restart()