Module: MotherBrain::Provisioner

Defined in:
lib/mb/provisioner.rb,
lib/mb/provisioners/aws.rb,
lib/mb/provisioner/manager.rb,
lib/mb/provisioner/manifest.rb,
lib/mb/provisioner/provision_data.rb

Defined Under Namespace

Classes: AWS, Base, Manager, Manifest, ProvisionData

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.default_idObject (readonly)

Returns the value of attribute default_id.



8
9
10
# File 'lib/mb/provisioner.rb', line 8

def default_id
  @default_id
end

Class Method Details

.allSet<MB::Provisioner::Base>

List of all the registered provisioners

Returns:

  • (Set<MB::Provisioner::Base>)


39
40
41
# File 'lib/mb/provisioner.rb', line 39

def all
  @all ||= Set.new
end

.clear!Set

Clears all of the registered Provisioners.

Returns:

  • (Set)

    an empty Set



81
82
83
84
# File 'lib/mb/provisioner.rb', line 81

def clear!
  @default_id = nil
  @all        = Set.new
end

.defaultClass?

Return the default provisioner if one has been registered as the default

Returns:

  • (Class, nil)


72
73
74
75
# File 'lib/mb/provisioner.rb', line 72

def default
  _default_id = ENV['MB_DEFAULT_PROVISIONER'] || self.default_id
  get!(_default_id) if _default_id
end

.get(id) ⇒ Class?

Get registered provisioner class from the given ID. Return nil if no provisioner with the corresponding ID is found

Parameters:

  • id (#to_sym)

Returns:

  • (Class, nil)


49
50
51
# File 'lib/mb/provisioner.rb', line 49

def get(id)
  all.find { |klass| klass.provisioner_id == id.to_sym }
end

.get!(id) ⇒ Class

Get registered provisioner class fromt he given ID. Raise an error if no provisioner with the corresponding ID is found

Returns:

  • (Class)

Raises:



59
60
61
62
63
64
65
66
67
# File 'lib/mb/provisioner.rb', line 59

def get!(id)
  provisioner = get(id)

  if provisioner.nil?
    raise ProvisionerNotRegistered, "No provisioner registered with the ID: '#{id}'"
  end

  provisioner
end

.register(klass, options = {}) ⇒ Set

Parameters:

  • klass (Class)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :default (Boolean)

Returns:

  • (Set)

Raises:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mb/provisioner.rb', line 17

def register(klass, options = {})
  validate_provisioner_class(klass)

  unless get(klass.provisioner_id).nil?
    raise ProvisionerRegistrationError,
      "A provisioner with the id '#{klass.provisioner_id}' has already been registered"
  end

  if options[:default]
    unless @default_id.nil?
      raise ProvisionerRegistrationError, "A default provisioner has already been defined (#{default_id})"
    end

    @default_id = klass.provisioner_id
  end

  all.add(klass)
end

.validate_provisioner_class(klass) ⇒ Boolean

Parameters:

  • klass (Symbol)

Returns:

  • (Boolean)

Raises:



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/mb/provisioner.rb', line 91

def validate_provisioner_class(klass)
  unless klass.respond_to?(:provisioner_id)
    raise InvalidProvisionerClass, "Cannot register provisioner: all provisioners must respond to ':provisioner_id'"
  end

  if klass.provisioner_id.nil?
    raise InvalidProvisionerClass, "Cannot register provisioner: invalid provisioner_id '#{klass.provisioner_id}'"
  end

  true
end