Class: Topo::Provision::NodeGroupGenerator

Inherits:
ResourceGenerator show all
Includes:
Output
Defined in:
lib/topo/provision/generators/node_group.rb

Instance Attribute Summary collapse

Attributes inherited from ResourceGenerator

#name, #resource_attributes, #resource_type, #undeploy_action

Instance Method Summary collapse

Methods included from Output

#divert_stdout

Methods inherited from ResourceGenerator

#default_action, #default_resource_template, #do_action, #template, #template_root_dir

Methods included from Topo::ParseGen

#convert_keys_to_sym, #convert_keys_to_sym_deep, #expand_ref, #lazy_attribute_to_s, #topo_refs, #value_from_path

Constructor Details

#initialize(data, machine_generator = nil) ⇒ NodeGroupGenerator

Returns a new instance of NodeGroupGenerator.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/topo/provision/generators/node_group.rb', line 33

def initialize(data, machine_generator=nil)
  @resource_type ||= "machine_batch"
   super(data)
  @template_base_name = "node_group"
  machine_data = data.clone
  @size = value_from_path(data, %w[provisioning node_group size])
  # append a number to the name if size is specified
  if !@size.nil?
    machine_data['name'] = "#{data['name']}\#{i}"          
  end
  @size ||= 1
  @machine_generator = machine_generator || Topo::Provision::MachineGenerator.new(machine_data)
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



31
32
33
# File 'lib/topo/provision/generators/node_group.rb', line 31

def size
  @size
end

Instance Method Details

#batch_action(action) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/topo/provision/generators/node_group.rb', line 64

def batch_action(action)
  machine_names = []
  1.upto @size do |i|
    machine_names << "#{name}#{i}"
  end
  puts(template("action").result(binding))   
end

#deployObject



47
48
49
50
51
52
53
54
# File 'lib/topo/provision/generators/node_group.rb', line 47

def deploy() 
  # temporarily divert stdout & perform machine action
  machine_output = divert_stdout do
    @machine_generator.deploy
  end
  # put into batch
  puts(template("deploy").result(binding))   
end

#stopObject



60
61
62
# File 'lib/topo/provision/generators/node_group.rb', line 60

def stop()
  batch_action(:stop)
end

#undeployObject



56
57
58
# File 'lib/topo/provision/generators/node_group.rb', line 56

def undeploy()
  batch_action(:destroy)
end