class Architect::Designer

Public Class Methods

create_plan() click to toggle source
# 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