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
-
.default_id ⇒ Object
readonly
Returns the value of attribute default_id.
Class Method Summary collapse
-
.all ⇒ Set<MB::Provisioner::Base>
List of all the registered provisioners.
-
.clear! ⇒ Set
Clears all of the registered Provisioners.
-
.default ⇒ Class?
Return the default provisioner if one has been registered as the default.
-
.get(id) ⇒ Class?
Get registered provisioner class from the given ID.
-
.get!(id) ⇒ Class
Get registered provisioner class fromt he given ID.
- .register(klass, options = {}) ⇒ Set
- .validate_provisioner_class(klass) ⇒ Boolean
Class Attribute Details
.default_id ⇒ Object (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
.all ⇒ Set<MB::Provisioner::Base>
List of all the registered provisioners
39 40 41 |
# File 'lib/mb/provisioner.rb', line 39 def all @all ||= Set.new end |
.clear! ⇒ Set
Clears all of the registered Provisioners.
81 82 83 84 |
# File 'lib/mb/provisioner.rb', line 81 def clear! @default_id = nil @all = Set.new end |
.default ⇒ Class?
Return the default provisioner if one has been registered as the default
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
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
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
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, = {}) 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 [: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
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 |