Class: Bcome::Orchestrator::NodeTarget::Base

Inherits:
Object
  • Object
show all
Includes:
ValidateAndSet
Defined in:
lib/orchestrator/node_target/base.rb

Direct Known Subclasses

All, AllExcludingRoles, AllWithRoles, Single

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ValidateAndSet

#validate_and_set

Constructor Details

#initialize(json) ⇒ Base

Returns a new instance of Base.



26
27
28
# File 'lib/orchestrator/node_target/base.rb', line 26

def initialize(json)
  validate_and_set(json) unless override_validate_and_set?
end

Instance Attribute Details

#node_selectionsObject (readonly)

Returns the value of attribute node_selections.



24
25
26
# File 'lib/orchestrator/node_target/base.rb', line 24

def node_selections
  @node_selections
end

#target_keyObject (readonly)

Returns the value of attribute target_key.



24
25
26
# File 'lib/orchestrator/node_target/base.rb', line 24

def target_key
  @target_key
end

Class Method Details

.klass_for_typeObject



13
14
15
16
17
18
19
# File 'lib/orchestrator/node_target/base.rb', line 13

def klass_for_type
  {
    "single" => ::Bcome::Orchestrator::NodeTarget::Single,
    "all_excluding_roles" => ::Bcome::Orchestrator::NodeTarget::AllExcludingRoles,
    "all_with_roles" => ::Bcome::Orchestrator::NodeTarget::AllWithRoles
  } 
end

.new_of_type_from(json, machines) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/orchestrator/node_target/base.rb', line 5

def new_of_type_from(json, machines)
   raise "Missing node target type in #{json.inspect}" unless json.has_key?(:type)
   raise "Invalid node target of type #{json[:type]} in #{json.inspect}" unless klass_for_type.keys.include?(json[:type])
   node_target = klass_for_type[json[:type]].new(json)
   node_target.set_machines(machines)
   return node_target
end

Instance Method Details

#json_attributesObject



34
35
36
# File 'lib/orchestrator/node_target/base.rb', line 34

def json_attributes
  [:target_key, :selectors]
end

#override_validate_and_set?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/orchestrator/node_target/base.rb', line 30

def override_validate_and_set?
  false
end

#set_machines(*params) ⇒ Object



38
39
40
# File 'lib/orchestrator/node_target/base.rb', line 38

def set_machines(*params)
  raise "Override set_machines in derived types - each type has its own distinct selector, and is passed an array of machines available at the current bcome context." 
end