Example #1
0
class Link(Resource):

    """ A resource representing a symbolic link. The link will be from `name`
    to `to`. If you specify owner, group and/or mode then these settings will
    be applied to the link itself, not to the object linked to.

    For example::

      Link:
        name: /etc/init.d/exampled
        to: /usr/local/example/sbin/exampled
        owner: root
        group: root

    """

    name = FullPath()
    """The name of the file this resource represents."""

    owner = String(default="root")
    """A unix username or UID who will own created objects. An owner that
    begins with a digit will be interpreted as a UID, otherwise it will be
    looked up using the python 'pwd' module."""

    group = String(default="root")
    """A unix group or GID who will own created objects. A group that begins
    with a digit will be interpreted as a GID, otherwise it will be looked up
    using the python 'grp' module."""

    to = FullPath()
    """ The pathname to which to link the symlink. Dangling symlinks ARE
Example #2
0
class Special(Resource):
    """ A special file, as created by mknod. """

    name = FullPath()
    """ The full path to the special file on disk. """

    owner = String(default="root")
    """ The unix user who should own this special file. """

    group = String(default="root")
    """ The unix group who should own this special file. """

    mode = Octal(default=0644)
    """ The octal representation of the permissions for this special file. """

    type = String(default="fifo")
    """ One of the following strings:

      block
        create a block (buffered) special file
      character
        create a character (unbuffered) special file
      fifo
        create a fifo

    It defaults to fifo
    """

    major = Integer()
    """ The major number for the special file. If the type of the special file
    is block or character, then this must be specified. """

    minor = Integer()
    """ The minor number for the special file. If the type of the special file
Example #3
0
class Directory(Resource):
    """ A directory on disk. Directories have limited metadata, so this
    resource is quite limited.

    For example::

        Directory:
          name: /var/local/data
          owner: root
          group: root
          mode: 0755

    """

    name = FullPath()
    """ The full path to the directory on disk """

    owner = String(default="root")
    """ The unix username who should own this directory, by default this is 'root' """

    group = String(default="root")
    """ The unix group who should own this directory, by default this is 'root' """

    mode = Octal(default=0755)
    """ The octal mode that represents this directory's permissions, by default this is '755'. """

    parents = Boolean(default=False)
    """ Create parent directories as needed, using the same ownership and
Example #4
0
class Checkout(Resource):
    """ This represents a "working copy" from a Source Code Management system.
    This could be provided by, for example, Subversion or Git remote
    repositories.

    Note that this is '*a* checkout', not 'to checkout'. This represents the
    resource itself on disk. If you change the details of the working copy
    (for example changing the branch) the provider will execute appropriate
    commands (such as `svn switch`) to take the resource to the desired state.
    """

    name = FullPath()
    """ The full path to the working copy on disk. """

    repository = String()
    """ The identifier for the repository - this could be an http url for
    subversion or a git url for git, for example. """

    branch = String()
    """ The name of a branch to check out, if required. """

    revision = String()
    """ The revision to check out or move to. """

    scm = String()
    """ The source control management system to use, e.g. subversion, git. """

    scm_username = String()
    """ The username for the remote repository """

    scm_password = String()
    """ The password for the remote repository. """

    user = String(default="root")
    """ The user to perform actions as, and who will own the resulting files. """
Example #5
0
class Service(Resource):
    """ This represents service startup and shutdown via an init daemon. """

    name = String()
    """ A unique name representing an initd service.

    This would normally match the name as it appears in /etc/init.d.
    """

    priority = Integer(default=99)
    """ Priority of the service within the boot order.

    This attribute will have no effect when using a dependency or event based
    init.d subsystem like upstart or systemd. """

    start = String()
    """ A command that when executed will start the service.

    If not provided, the provider will use the default service start invocation
    for the init.d system in use.
    """

    stop = String()
    """ A command that when executed will start the service.

    If not provided, the provider will use the default service stop invocation
    for the init.d system in use.
    """

    restart = String()
    """ A command that when executed will restart the service.

    If not provided, the provider will use the default service restart invocation
    for the init.d system in use. If it is not possible to automatically determine
    if the restart script is avilable the service will be stopped and started instead.
    """

    reconfig = String()
    """ A command that when executed will make the service reload its
    configuration file. """

    pidfile = FullPath()
    """ Where the service creates its pid file.
Example #6
0
class User(Resource):
    """ A resource representing a UNIX user in the password database. The underlying implementation currently uses the "useradd" and "usermod" commands to implement this resource.

    This resource can be used to create, change or delete UNIX users.

    For example::

        User:
          name: django
          fullname: Django Software Owner
          home: /var/local/django
          system: true
          disabled-password: true

    """

    name = String()
    """ The username this resource represents. """

    password = String()
    """ The encrypted password, as returned by crypt(3). You should make sure
    this password respects the system's password policy. """

    fullname = String()
    """ The comment field for the password file - generally used for the user's full name. """

    home = FullPath()
    """ The full path to the user's home directory. """

    uid = Integer()
    """ The user identifier for the user. This must be a non-negative integer. """

    gid = Integer()
    """ The group identifier for the user. This must be a non-negative integer. """

    group = String()
    """ The primary group for the user, if you wish to specify it by name. """

    groups = List()
    """ A list of supplementary groups that the user should be a member of. """

    append = Boolean(default=True)
    """ A boolean that sets how to apply the groups a user is in. If true then yaybu will
    add the user to groups as needed but will not remove a user from a group. If false then yaybu will replace
    all groups the user is a member of. Thus if a process outside of yaybu adds you to a group,
    the next deployment would remove you again. """

    system = Boolean(
        default=True)  # has no effect on modification, only creation
    """ A boolean representing whether this user is a system user or not. This only takes effect on
    creation - a user cannot be changed into a system user once created
    without deleting and recreating the user. """

    shell = FullPath(default="/bin/bash")
    """ The full path to the shell to use. """

    disabled_password = Boolean(default=False)
    """ A boolean for whether the password is locked for this account. """

    disabled_login = Boolean(default=False)
    """ A boolean for whether this entire account is locked or not. """
Example #7
0
class Execute(Resource):
    """ Execute a command. This command is not executed in a shell - if you
    want a shell, run it (for example bash -c).

    For example::

        Execute:
          name: core_packages_apt_key
          command: apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ${source.key}

    A much more complex example. This shows executing a command if a checkout synchronises::

        Execute.foreach bi in ${flavour.base_images}:
          name: base-image-${bi}
          policy:
              apply:
                  when: sync
                  on: /var/local/checkouts/ci
          command: ./vmbuilder-${bi}
          cwd: /var/local/checkouts/ci
          user: root

    """

    name = String()
    """ The name of this resource. This should be unique and descriptive, and
    is used so that resources can reference each other. """

    command = String()
    """ If you wish to run a single command, then this is the command. """

    commands = List()
    """ If you wish to run multiple commands, provide a list """

    cwd = FullPath(default='/')
    """ The current working directory in which to execute the command. """

    environment = Dict()
    """

    The environment to provide to the command, for example::

        Execute:
            name: example
            command: echo $FOO
            environment:
                FOO: bar
    """

    returncode = Integer(default=0)
    """ The expected return code from the command, defaulting to 0. If the
    command does not return this return code then the resource is considered
    to be in error. """

    user = String(default="root")
    """ The user to execute the command as.
    """

    group = String(default="root")
    """ The group to execute the command as.
    """

    unless = String(default="")
    """ A command to run to determine is this execute should be actioned
    """

    creates = FullPath()
    """ The full path to a file that execution of this command creates. This
    is used like a "touch test" in a Makefile. If this file exists then the
    execute command will NOT be executed. """

    touch = FullPath()
    """ The full path to a file that yaybu will touch once this command has
Example #8
0
class File(Resource):
    """ A provider for this resource will create or amend an existing file to
    the provided specification.

    For example, the following will create the /etc/hosts file based on a static local file::

        File:
          name: /etc/hosts
          owner: root
          group: root
          mode: 644
          static: my_hosts_file

    The following will create a file using a jinja2 template, and will back up
    the old version of the file if necessary::

        File:
          name: /etc/email_addresses
          owner: root
          group: root
          mode: 644
          template: email_addresses.j2
          template_args:
              foo: [email protected]
              bar: [email protected]
          backup: /etc/email_addresses.{year}-{month}-{day}

    """

    name = FullPath()
    """The full path to the file this resource represents."""

    owner = String(default="root")
    """A unix username or UID who will own created objects. An owner that
    begins with a digit will be interpreted as a UID, otherwise it will be
    looked up using the python 'pwd' module."""

    group = String(default="root")
    """A unix group or GID who will own created objects. A group that begins
    with a digit will be interpreted as a GID, otherwise it will be looked up
    using the python 'grp' module."""

    mode = Octal(default=0644)
    """A mode representation as an octal. This can begin with leading zeros if
    you like, but this is not required. DO NOT use yaml Octal representation
    (0o666), this will NOT work."""

    static = File()
    """A static file to copy into this resource. The file is located on the
    yaybu path, so can be colocated with your recipes."""

    encrypted = File()
    """A static encrypted file to copy to this resource. The file is located
    on the yaybu path, so can be colocated with your recipe."""

    template = File()
    """A jinja2 template, used to generate the contents of this resource. The
    template is located on the yaybu path, so can be colocated with your
    recipes"""

    template_args = Dict(default={})
    """The arguments passed to the template."""
    def hash(self):
        if not os.path.exists(self.name):
            return ""
        return hashlib.sha1(open(self.name).read()).hexdigest()