Class: Architect::Designer

Inherits:
Object
  • Object
show all
Defined in:
lib/architect/designer.rb

Class Method Summary collapse

Class Method Details

.create_planObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/architect/designer.rb', line 12

def self.create_plan
  questions = {
    'environment' => 'Puppet environment',
    'hostgroup'   => 'Foreman hostgroup',
    'domain'     	=> 'DNS domain',
    'subnet'	=> 'Foreman subnet',
    'network_interface' => 'libvirt network interface',
    'cpus'	=> 'Number of virtual CPUs',
    'memory'	=> 'Amount of memory',
    'disk_capacity' => 'Disk sizes; separate multiple disks with a comma',
    'storage_pool' => 'libvirt storage pool',
    'owner' => 'Foreman owner',
    }
  
  defaults = {
    'environment' => 'staging',
    'hostgroup'   => 'staging/generic',
    'domain'     	=> 'brontolabs.local',
    'subnet'	=> 'staging_200',
    'network_interface' => 'vnet0.200',
    'cpus'	=> '1',
    'memory'	=> '1G',
    'disk_capacity' => '20G,20G',
    'storage_pool' => 'gvol',
    'owner' 	=> 'Systems Engineering',
  }

puts "\n------\n\nPlease provide default settings for the instances to be created.\n"

  answers = { 'version' => 1, 'defaults' => {} }
questions.each do |k,question|
    puts "\n" + question + "  (default: " + defaults[k] + ")\n" 
  printf ": "
  res = STDIN.readline.chomp
    res = defaults[k] if res.empty?
  answers['defaults'][k] = res
end

puts "\n------\n\nEnter the name(s) of the instances to be created. Separate multiple instances with a comma. To specify a range, use (x..y) notation.\n"

printf ": "
answers['instances'] = []
STDIN.readline.chomp.split(/\s*,\s*/).sort.each do |tok|
  # Expand (x..y) notation
  # This assumes a host naming convention of foo-prod-(x..y)
  if tok =~ /\((\d+)\.\.(\d+)\)/
prefix = $`
r = Range.new($1,$2)
puts prefix
r.each { |x| answers['instances'].push(prefix + sprintf("%03d", x)) }
  else
answers['instances'].push tok
  end
end


  puts "\n\nHere is the plan you requested:\n\n"
puts answers.to_yaml
end