Class: Pot::Policy

Inherits:
Object
  • Object
show all
Defined in:
lib/pot/policy.rb

Overview

Policies

A policy defines a set of packages which are required for a certain role (app, database, etc.). All policies defined will be run and all packages required by the policy will be installed. So whereas defining a Pot::Package merely defines it, defining a Pot::Policy actually causes those packages to install.

A Basic Example

policy :blog, :roles => :app do
  require :webserver
  require :database
  require :rails
end

This says that for the blog on the app role, it requires certain packages. The :roles option is exactly the same as a capistrano or vlad role. A role merely defines what server the commands are run on. This way, a single Pot script can provision an entire group of servers.

To define a role, put in your actor specific configuration file (recipe or script file):

role :app, "208.28.38.44"

The capistrano and vlad syntax is the same for that. If you’re using a custom actor, you may have to do it differently.

Multiple Policies

You may specify as many policies as you’d like. If the packages you’re requiring are properly defined with verification blocks, then no software will be installed twice, so you may require a webserver on multiple packages within the same role without having to wait for that package to install repeatedly.

Constant Summary collapse

REGISTER =

:nodoc:

{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, metadata = {}, &block) ⇒ Policy

Returns a new instance of Policy.



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/pot/policy.rb', line 46

def initialize(name,  = {}, &block)
  raise 'No name provided' unless name
  raise 'No roles provided' unless [:roles]

  @name = name.to_sym
  @roles = [:roles]
  @package_tree = Pot::Bundle.new

  REGISTER[@name] = self

  self.instance_eval(&block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



42
43
44
# File 'lib/pot/policy.rb', line 42

def name
  @name
end

#packagesObject (readonly)

Returns the value of attribute packages.



42
43
44
# File 'lib/pot/policy.rb', line 42

def packages
  @packages
end

#rolesObject (readonly)

Returns the value of attribute roles.



42
43
44
# File 'lib/pot/policy.rb', line 42

def roles
  @roles
end

Instance Method Details

#process(actor) ⇒ Object



67
68
69
70
71
# File 'lib/pot/policy.rb', line 67

def process(actor)
  @package_tree.list do |package|
    package.process(actor)
  end
end

#requires(package, options = {}) ⇒ Object



59
60
61
# File 'lib/pot/policy.rb', line 59

def requires(package, options = {})
  @package_tree.add(package)
end

#to_sObject



63
64
65
# File 'lib/pot/policy.rb', line 63

def to_s
  name
end