package Package

package Package

Roles in this namespace are meant to enable users to install packages using package managers such as Yum or Pip in CentOS distributions.

pip Module

Roles in this namespace are meant to provision packages installed via the PIP package manager for CentOS distributions.

class provy.more.centos.package.pip.PipRole(prov, context)[source]

Bases: provy.core.roles.Role

This role provides package management operations with PIP within CentOS distributions.

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(PipRole) as role:
            role.ensure_package_installed('django', version='1.1.1')
ensure_package_installed(package_name, version=None)[source]

Makes sure the package is installed with the specified version (latest if None specified). This method does not verify and upgrade the package on subsequent provisions, though. Use ensure_package_up_to_date() for this purpose instead.

Parameters:
  • package_name (str) – Name of the package to install.
  • version (str) – If specified, installs this version of the package. Installs latest version otherwise. You can use >= or <= before version number to ensure package version.
Returns:

Whether the package had to be installed or not.

Return type:

bool

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(PipRole) as role:
            role.ensure_package_installed('django', version='1.1.1')
ensure_package_up_to_date(package_name)[source]

Makes sure the package is installed and up-to-date with the latest version. This method verifies if there is a newer version for this package every time the server is provisioned. If a new version is found, it is installed.

Parameters:package_name (str) – Name of the package to install.

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(PipRole) as role:
            role.ensure_package_is_up_to_date('django')
ensure_requirements_installed(requirements_file_name)[source]

Makes sure the requirements file provided is installed.

Parameters:requirements_file_name (str) – Path to the requirements file (can be provided as absolute path or relative to the directory where provy is run from).

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(PipRole) as role:
            role.ensure_requirements_installed('/path/to/requirements.txt')
extract_package_data_from_input(input_line)[source]
get_package_latest_version(package_name)[source]

Returns the latest available version of the package at the Python Package Index. If package is not available, returns None.

Parameters:package_name (str) – Name of the package to verify
Returns:The package version.
Return type:str

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(PipRole) as role:
            version = role.get_package_remote_version('django')
            latest = role.get_package_latest_version('django')
            if version != latest:
                pass
                # this check is not needed if you use ensure_package_up_to_date.
get_package_remote_version(package_name)[source]

Returns the version of the package currently installed via PIP in the remote server. If package is not installed, returns None.

Parameters:package_name (str) – Name of the package to verify
Returns:The package version.
Return type:str

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(PipRole) as role:
            version = role.get_package_remote_version('django')
            if version and version == '1.1.1':
                pass
is_package_installed(package_name, version=None)[source]

Returns True if the given package is installed via pip in the remote server, False otherwise.

Parameters:
  • package_name (str) – Name of the package to verify
  • version (str) – Version to check for. Defaults to None, which makes it check for any version.
Returns:

Whether the package is installed or not.

Return type:

bool

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(PipRole) as role:
            if role.is_package_installed('django', version='1.1.1'):
                pass
package_can_be_updated(package_name)[source]

Returns True if there is an update for the given package in the Python Package Index, False otherwise.

Parameters:package_name (str) – Name of the package to verify
Returns:Whether the package can be updated.
Return type:bool

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(PipRole) as role:
            if role.package_can_be_updated('django'):
                pass
                # this check is not needed if you use ensure_package_up_to_date.
provision()[source]

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

Example:

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

Prepares the pip role instance to run its commands with sudo; This is useful when you had previously set a user, and want it to run back as sudo.

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(PipRole) as role:
            role.ensure_package_installed('django') # runs as sudo
            role.set_user('johndoe')
            role.ensure_package_installed('django') # runs as "johndoe" user
            role.set_sudo()
            role.ensure_package_installed('django') # runs as sudo
set_user(user)[source]

Prepares the pip role instance to run its commands as a specific user.

Parameters:user (str) – The username with which the role should run its commands.

Example:

class MySampleRole(Role):
    def provision(self):
        with self.using(PipRole) as role:
            role.ensure_package_installed('django') # runs as sudo
            role.set_user('johndoe')
            role.ensure_package_installed('django') # runs as "johndoe" user
use_sudo = True
user = None

yum Module

Roles in this namespace are meant to provision packages installed via the Yum package manager for CentOS distributions.

exception provy.more.centos.package.yum.PackageNotFound[source]

Bases: exceptions.Exception

Should be raised when a package doesn’t exist.

class provy.more.centos.package.yum.YumRole(prov, context)[source]

Bases: provy.core.roles.Role

This role provides package management operations with Yum within CentOS distributions.

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            role.ensure_package_installed('nginx')
ensure_gpg_key(url)[source]

Ensures that the specified gpg key is imported into rpm.

Parameters:url (str) – URL of the gpg key file.

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            role.ensure_gpg_key('http://some.url.com/to/key.gpg')
ensure_package_installed(package_name)[source]

Ensures that the given package is installed via Yum.

Parameters:package_name (str) – The name of the package to install.
Returns:Whether the package had to be installed or not.
Return type:bool

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            role.ensure_package_installed('nginx')
ensure_up_to_date()[source]

Makes sure Yum’s repository is updated if it hasn’t been updated in the last 30 minutes.

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            role.ensure_up_to_date()
ensure_yum_source(source_string)[source]

Ensures that the specified repository is in yum’s list of repositories.

Parameters:source_string (str) – Repository string.
Returns:Whether the repository had to be added or not.
Return type:bool

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            role.ensure_yum_source('some-path-to-a-repo')
force_update()[source]

Forces an update to Yum’s repository.

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            role.force_update()
get_last_update_date()[source]

Returns the date in the update_date_file().

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            last_update = role.get_last_update_date()
has_source(source_string)[source]

Ensures that the specified repository is in yum’s list of repositories.

Parameters:source_string (str) – Repository string.
Returns:Whether the repository is already configured or not.
Return type:bool

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            if role.has_source('some-path-to-a-repo'):
                pass
is_package_installed(package_name)[source]

Returns True if the given package is installed via Yum, False otherwise.

Parameters:package_name (str) – The name of the package to check.
Returns:Whether the package is installed or not.
Return type:bool

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            if role.is_package_installed('nginx'):
                pass
key = 'yum-up-to-date'
package_exists(package)[source]

Checks if the given package exists.

Parameters:package (str) – Name of the package to check.
Returns:Whether the package exists or not.
Return type:bool

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            role.package_exists('nginx') # True
provision()[source]

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

Example:

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

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

Updates the date in the update_date_file().

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            role.store_update_date()
time_format = '%d-%m-%y %H:%M:%S'
update_date_file

Returns the path for the file that contains the last update date to yum’s list of packages.

Example:

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

class MySampleRole(Role):
    def provision(self):
        with self.using(YumRole) as role:
            file_path = role.update_date_file