$TITLE
Modules
private protected

Method __init__

__init__( self )
Undocumented

wrapper_descriptor

1.repr_() <==> repr(x)

wrapper_descriptor

1.str_() <==> str(x)

Class mode_sudo

Cuisine functions will be executed with sudo.

Method __init__

__init__( self )
Undocumented

Class mode_user

Cuisine functions will be executed as the current user.

Function command_check

command_check( command )

Tests if the given command is available on the system.

Function command_ensure

command_ensure( command, package=None )

Ensures that the given command is present, if not installs the package with the given name, which is the same as the command by default.

Function dir_attribs

dir_attribs( location, mode=None, owner=None, group=None, recursive=False )

Updates the mode/owner/group for the given remote directory.

Function dir_ensure

dir_ensure( location, recursive=False, mode=None, owner=None, group=None )

Ensures that there is a remote directory at the given location, optionally updating its mode/owner/group.

If we are not updating the owner/group then this can be done as a single ssh call, so use that method, otherwise set owner/group after creation.

Function dir_exists

dir_exists( location )

Tells if there is a remote directory at the given location.

Function dispatch

dispatch( prefix=None )

Dispatches the current function to specific implementation. The prefix parameter indicates the common option prefix, and the option_select() function will determine the function suffix.

For instance the package functions are defined like that:

{{{ @dispatch("package") def packageensure(...): ... def packageensureapt(...): ... def packageensure_yum(…): … }}}

and then when a user does

{{{ cuisine.optionselect("package", "yum") cuisine.packageensure(…) }}}

then the dispatch function will dispatch package_ensure to package_ensure_yum.

If your prefix is the first word of the function name before the first _ then you can simply use @dispatch without parameters.

Function file_append

file_append( location, content, mode=None, owner=None, group=None )

Appends the given content to the remote file at the given location, optionally updating its mode/owner/group.

Function file_attribs

file_attribs( location, mode=None, owner=None, group=None, recursive=False )

Updates the mode/owner/group for the remote file at the given location.

Function file_attribs_get

file_attribs_get( location )

Return mode, owner, and group for remote path. Return mode, owner, and group if remote path exists, None otherwise.

Function file_ensure

file_ensure( location, mode=None, owner=None, group=None, recursive=False )

Updates the mode/owner/group for the remote file at the given location.

Function file_exists

file_exists( location )

Tests if there is a remote file at the given location.

Function file_is_dir

file_is_dir( location )
Undocumented

Function file_is_file

file_is_file( location )
Undocumented

Function file_is_link

file_is_link( location )
Undocumented

Function file_link

file_link( source, destination, symbolic=True, mode=None, owner=None, group=None )

Creates a (symbolic) link between source and destination on the remote host, optionally setting its mode/owner/group.

Function file_local_read

file_local_read( location )

Reads a local file from the given location, expanding ~ and shell variables.

Function file_read

file_read( location )

Reads the remote file at the given location.

Function file_sha256

file_sha256( location )

Returns the SHA-256 sum (as a hex string) for the remote file at the given location.

Function file_unlink

file_unlink( path )
Undocumented

Function file_update

file_update( location, updater= at 0x1ed2938> )

Updates the content of the given by passing the existing content of the remote file at the given location to the updater function.

For instance, if you'd like to convert an existing file to all uppercase, simply do:

file_update("/etc/myfile", lambda _:_.upper())

Function file_upload

file_upload( remote, local, sudo=None )

Uploads the local file to the remote location only if the remote location does not exists or the content are different.

Function file_write

file_write( location, content, mode=None, owner=None, group=None, sudo=None )

Writes the given content to the file at the given remote location, optionally setting mode/owner/group.

Function group_check

group_check( name )

Checks if there is a group defined with the given name, returning its information as a {"name":<str>,"gid":<str>,"members":<list[str]>} or None if the group does not exists.

Function group_create

group_create( name, gid=None )

Creates a group with the given name, and optionally given gid.

Function group_ensure

group_ensure( name, gid=None )

Ensures that the group with the given name (and optional gid) exists.

Function group_user_add

group_user_add( group, user )

Adds the given user/list of users to the given group/groups.

Function group_user_check

group_user_check( group, user )

Checks if the given user is a member of the given group. It will return False if the group does not exist.

Function group_user_ensure

group_user_ensure( group, user )

Ensure that a given user is a member of a given group.

Function locale_check

locale_check( locale )
Undocumented

Function locale_ensure

locale_ensure( locale )
Undocumented

Function mode_local

mode_local( )

Sets Cuisine into local mode, where run/sudo won't go through Fabric's API, but directly through a popen. This allows you to easily test your Cuisine scripts without using Fabric.

Function mode_remote

mode_remote( )

Comes back to Fabric's API for run/sudo. This basically reverts the effect of calling mode_local().

Function package_clean

package_clean( *args, **kwargs )

Clean the repository for un-needed files .

Function package_clean_apt

package_clean_apt( package=None )
Undocumented

Function package_clean_yum

package_clean_yum( package=None )
Undocumented

Function package_ensure

package_ensure( *args, **kwargs )

Tests if the given package is installed, and installs it in case it's not already there. If update is true, then the package will be updated if it already exists.

Function package_ensure_apt

package_ensure_apt( package, update=False )
Undocumented

Function package_ensure_yum

package_ensure_yum( package, update=False )
Undocumented

Function package_install

package_install( *args, **kwargs )

Installs the given package/list of package, optionally updating the package database.

Function package_install_apt

package_install_apt( package, update=False )
Undocumented

Function package_install_yum

package_install_yum( package, update=False )
Undocumented

Function package_update

package_update( *args, **kwargs )

Upgrade the system.

Function package_update_apt

package_update_apt( package=None )
Undocumented

Function package_update_yum

package_update_yum( package=None )
Undocumented

Function package_upgrade

package_upgrade( *args, **kwargs )

Updates every package present on the system.

Function package_upgrade_apt

package_upgrade_apt( package=None )
Undocumented

Function package_upgrade_yum

package_upgrade_yum( package=None )
Undocumented

Function repository_ensure_apt

repository_ensure_apt( repository )
Undocumented

Function repository_ensure_yum

repository_ensure_yum( repository )
Undocumented

Function run

run( *args, **kwargs )

A wrapper to Fabric's run/sudo commands, using the 'cuisine.MODE' global to tell whether the command should be run as regular user or sudo.

Function run_local

run_local( command )

A wrapper around subprocess.

Function select_package

select_package( option=None )
Undocumented

Function ssh_authorize

ssh_authorize( user, key )

Adds the given key to the .ssh/authorized_keys for the given user.

Function ssh_keygen

ssh_keygen( user, keytype='dsa' )

Generates a pair of ssh keys in the user's home .ssh directory.

Function sudo

sudo( *args, **kwargs )

A wrapper to Fabric's run/sudo commands, using the 'cuisine.MODE_SUDO' global to tell whether the command should be run as regular user or sudo.

Function sudo_password

sudo_password( password )
Undocumented

Function system_uuid

system_uuid( )

Gets a machines UUID (Universally Unique Identifier).

Function system_uuid_alias_add

system_uuid_alias_add( )

Adds system UUID alias to /etc/hosts. Some tools/processes rely/want the hostname as an alias in /etc/hosts e.g. 127.0.0.1 localhost <hostname>.

Function text_detect_eol

text_detect_eol( text )
Undocumented

Function text_ensure_line

text_ensure_line( text, *lines )

Ensures that the given lines are present in the given text, otherwise appends the lines that are not already in the text at the end of it.

Function text_get_line

text_get_line( text, predicate )

Returns the first line that matches the given predicate.

Function text_normalize

text_normalize( text )

Converts tabs and spaces to single space and strips the text.

Function text_nospace

text_nospace( text )

Converts tabs and spaces to single space and strips the text.

Function text_replace_line

text_replace_line( text, old, new, find= at 0x1ed2140>, process= at 0x1ed21b8> )

Replaces lines equal to old with new, returning the new text and the count of replacements.

Function text_strip_margin

text_strip_margin( text, margin='|' )
Undocumented

Function text_template

text_template( text, variables )

Substitutes ${PLACEHOLDER}s within the text with the corresponding values from variables.

Function upstart_ensure

upstart_ensure( name )

Ensures that the given upstart service is running, restarting it if necessary.

Function user_check

user_check( name )

Checks if there is a user defined with the given name, returning its information as a {"name":<str>,"uid":<str>,"gid":<str>,"home":<str>,"shell":<str>} or None if the user does not exists.

Function user_create

user_create( name, passwd=None, home=None, uid=None, gid=None, shell=None, uid_min=None, uid_max=None )

Creates the user with the given name, optionally giving a specific password/home/uid/gid/shell.

Function user_ensure

user_ensure( name, passwd=None, home=None, uid=None, gid=None, shell=None )

Ensures that the given users exists, optionally updating their passwd/home/uid/gid/shell.

Function user_passwd

user_passwd( name, passwd )

Sets the given user password.

Function user_remove

user_remove( name, rmhome=None )

Removes the user with the given name, optionally removing the home directory and mail spool.

dict

{'package': 'apt'}

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

str

'\n'

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

bool

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

SRE_Pattern

Compiled regular expression objects

NoneType

Undocumented

str

'0.2.6'

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

str

'\r\n'

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

str

'package'

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

str

'apt'

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

Module cuisine

cuisine makes it easy to write automatic server installation and configuration recipes by wrapping common administrative tasks (installing packages, creating users and groups) in Python functions.

cuisine is designed to work with Fabric and provide all you need for getting your new server up and running in minutes.

Note, that right now, Cuisine only supports Debian-based Linux systems.

See also:

:copyright: (c) 2011,2012 by Sébastien Pierre. :license: BSD, see LICENSE for more details.

Function mode_remote

mode_remote( )

Comes back to Fabric's API for run/sudo. This basically reverts the effect of calling mode_local().

Function run

run( *args, **kwargs )

A wrapper to Fabric's run/sudo commands, using the 'cuisine.MODE' global to tell whether the command should be run as regular user or sudo.

Function text_template

text_template( text, variables )

Substitutes ${PLACEHOLDER}s within the text with the corresponding values from variables.

bool

bool(x) -> bool

Returns True when the argument x is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.

Function system_uuid_alias_add

system_uuid_alias_add( )

Adds system UUID alias to /etc/hosts. Some tools/processes rely/want the hostname as an alias in /etc/hosts e.g. 127.0.0.1 localhost <hostname>.

Function package_upgrade

package_upgrade( *args, **kwargs )

Updates every package present on the system.

Function package_update_apt

package_update_apt( package=None )
Undocumented

Function package_update_yum

package_update_yum( package=None )
Undocumented

Function package_ensure_apt

package_ensure_apt( package, update=False )
Undocumented

Function package_ensure_yum

package_ensure_yum( package, update=False )
Undocumented

Function package_clean_yum

package_clean_yum( package=None )
Undocumented

Function package_ensure

package_ensure( *args, **kwargs )

Tests if the given package is installed, and installs it in case it's not already there. If update is true, then the package will be updated if it already exists.

Function package_install_yum

package_install_yum( package, update=False )
Undocumented

Function package_update

package_update( *args, **kwargs )

Upgrade the system.

Function package_install

package_install( *args, **kwargs )

Installs the given package/list of package, optionally updating the package database.

Function package_install_apt

package_install_apt( package, update=False )
Undocumented

Function locale_check

locale_check( locale )
Undocumented

Function locale_ensure

locale_ensure( locale )
Undocumented

Function group_user_check

group_user_check( group, user )

Checks if the given user is a member of the given group. It will return False if the group does not exist.

Function group_user_ensure

group_user_ensure( group, user )

Ensure that a given user is a member of a given group.

Function package_clean

package_clean( *args, **kwargs )

Clean the repository for un-needed files .

Function package_clean_apt

package_clean_apt( package=None )
Undocumented

Function mode_local

mode_local( )

Sets Cuisine into local mode, where run/sudo won't go through Fabric's API, but directly through a popen. This allows you to easily test your Cuisine scripts without using Fabric.

Function package_upgrade_yum

package_upgrade_yum( package=None )
Undocumented

Function file_upload

file_upload( remote, local, sudo=None )

Uploads the local file to the remote location only if the remote location does not exists or the content are different.

Function file_write

file_write( location, content, mode=None, owner=None, group=None, sudo=None )

Writes the given content to the file at the given remote location, optionally setting mode/owner/group.

Function file_update

file_update( location, updater= at 0x1ed2938> )

Updates the content of the given by passing the existing content of the remote file at the given location to the updater function.

For instance, if you'd like to convert an existing file to all uppercase, simply do:

file_update("/etc/myfile", lambda _:_.upper())

Function group_ensure

group_ensure( name, gid=None )

Ensures that the group with the given name (and optional gid) exists.

Function group_user_add

group_user_add( group, user )

Adds the given user/list of users to the given group/groups.

Function group_check

group_check( name )

Checks if there is a group defined with the given name, returning its information as a {"name":<str>,"gid":<str>,"members":<list[str]>} or None if the group does not exists.

Function group_create

group_create( name, gid=None )

Creates a group with the given name, and optionally given gid.

Function file_unlink

file_unlink( path )
Undocumented

Function file_read

file_read( location )

Reads the remote file at the given location.

Function file_sha256

file_sha256( location )

Returns the SHA-256 sum (as a hex string) for the remote file at the given location.

Function text_nospace

text_nospace( text )

Converts tabs and spaces to single space and strips the text.

Function file_exists

file_exists( location )

Tests if there is a remote file at the given location.

Function file_is_dir

file_is_dir( location )
Undocumented

Function file_attribs_get

file_attribs_get( location )

Return mode, owner, and group for remote path. Return mode, owner, and group if remote path exists, None otherwise.

Function file_ensure

file_ensure( location, mode=None, owner=None, group=None, recursive=False )

Updates the mode/owner/group for the remote file at the given location.

Function file_link

file_link( source, destination, symbolic=True, mode=None, owner=None, group=None )

Creates a (symbolic) link between source and destination on the remote host, optionally setting its mode/owner/group.

Function file_local_read

file_local_read( location )

Reads a local file from the given location, expanding ~ and shell variables.

Function file_is_file

file_is_file( location )
Undocumented

Function file_is_link

file_is_link( location )
Undocumented

Function dir_attribs

dir_attribs( location, mode=None, owner=None, group=None, recursive=False )

Updates the mode/owner/group for the given remote directory.

Function dir_ensure

dir_ensure( location, recursive=False, mode=None, owner=None, group=None )

Ensures that there is a remote directory at the given location, optionally updating its mode/owner/group.

If we are not updating the owner/group then this can be done as a single ssh call, so use that method, otherwise set owner/group after creation.

SRE_Pattern

Compiled regular expression objects

Function command_ensure

command_ensure( command, package=None )

Ensures that the given command is present, if not installs the package with the given name, which is the same as the command by default.

Function file_append

file_append( location, content, mode=None, owner=None, group=None )

Appends the given content to the remote file at the given location, optionally updating its mode/owner/group.

Function file_attribs

file_attribs( location, mode=None, owner=None, group=None, recursive=False )

Updates the mode/owner/group for the remote file at the given location.

Function dir_exists

dir_exists( location )

Tells if there is a remote directory at the given location.

Function dispatch

dispatch( prefix=None )

Dispatches the current function to specific implementation. The prefix parameter indicates the common option prefix, and the option_select() function will determine the function suffix.

For instance the package functions are defined like that:

{{{ @dispatch("package") def packageensure(...): ... def packageensureapt(...): ... def packageensure_yum(…): … }}}

and then when a user does

{{{ cuisine.optionselect("package", "yum") cuisine.packageensure(…) }}}

then the dispatch function will dispatch package_ensure to package_ensure_yum.

If your prefix is the first word of the function name before the first _ then you can simply use @dispatch without parameters.

Class mode_sudo

Cuisine functions will be executed with sudo.

Method __init__

__init__( self )
Undocumented

Module cuisine

cuisine makes it easy to write automatic server installation and configuration recipes by wrapping common administrative tasks (installing packages, creating users and groups) in Python functions.

cuisine is designed to work with Fabric and provide all you need for getting your new server up and running in minutes.

Note, that right now, Cuisine only supports Debian-based Linux systems.

See also:

:copyright: (c) 2011,2012 by Sébastien Pierre. :license: BSD, see LICENSE for more details.

Class mode_user

Cuisine functions will be executed as the current user.

Method __init__

__init__( self )
Undocumented

wrapper_descriptor

1.repr_() <==> repr(x)

Function sudo

sudo( *args, **kwargs )

A wrapper to Fabric's run/sudo commands, using the 'cuisine.MODE_SUDO' global to tell whether the command should be run as regular user or sudo.

Function text_ensure_line

text_ensure_line( text, *lines )

Ensures that the given lines are present in the given text, otherwise appends the lines that are not already in the text at the end of it.

str

'package'

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

Function select_package

select_package( option=None )
Undocumented

Function user_check

user_check( name )

Checks if there is a user defined with the given name, returning its information as a {"name":<str>,"uid":<str>,"gid":<str>,"home":<str>,"shell":<str>} or None if the user does not exists.

Function command_check

command_check( command )

Tests if the given command is available on the system.

NoneType

Undocumented

Function repository_ensure_yum

repository_ensure_yum( repository )
Undocumented

Function text_strip_margin

text_strip_margin( text, margin='|' )
Undocumented

Function system_uuid

system_uuid( )

Gets a machines UUID (Universally Unique Identifier).

wrapper_descriptor

1.str_() <==> str(x)

str

'0.2.6'

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

Function user_create

user_create( name, passwd=None, home=None, uid=None, gid=None, shell=None, uid_min=None, uid_max=None )

Creates the user with the given name, optionally giving a specific password/home/uid/gid/shell.

Function package_upgrade_apt

package_upgrade_apt( package=None )
Undocumented

Function text_get_line

text_get_line( text, predicate )

Returns the first line that matches the given predicate.

Function ssh_keygen

ssh_keygen( user, keytype='dsa' )

Generates a pair of ssh keys in the user's home .ssh directory.

Function text_detect_eol

text_detect_eol( text )
Undocumented

Function user_ensure

user_ensure( name, passwd=None, home=None, uid=None, gid=None, shell=None )

Ensures that the given users exists, optionally updating their passwd/home/uid/gid/shell.

str

'\r\n'

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

Function run_local

run_local( command )

A wrapper around subprocess.

Function text_normalize

text_normalize( text )

Converts tabs and spaces to single space and strips the text.

Methods
Inhertied Values
Methods
Inhertied Values

Function upstart_ensure

upstart_ensure( name )

Ensures that the given upstart service is running, restarting it if necessary.

Function user_remove

user_remove( name, rmhome=None )

Removes the user with the given name, optionally removing the home directory and mail spool.

Function repository_ensure_apt

repository_ensure_apt( repository )
Undocumented

Function user_passwd

user_passwd( name, passwd )

Sets the given user password.

Function sudo_password

sudo_password( password )
Undocumented

dict

{'package': 'apt'}

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)

Function text_replace_line

text_replace_line( text, old, new, find= at 0x1ed2140>, process= at 0x1ed21b8> )

Replaces lines equal to old with new, returning the new text and the count of replacements.

str

'apt'

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

str

'\n'

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

Function ssh_authorize

ssh_authorize( user, key )

Adds the given key to the .ssh/authorized_keys for the given user.