summaryrefslogtreecommitdiff
path: root/costvm
blob: df0b542efdde31ac45f454d8a8e0f001ca54bd88 (plain)
1
2
3
4
5
6
7
8
9
10
11
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
71
#!/usr/bin/env ruby
# encoding: utf-8

if ARGV.length == 0 then
  puts "Usage: costvm CORES MEMORY DISKS [windows]"
  exit
end

CORES = ARGV.shift.chomp.to_i
MEM = ARGV.shift.chomp.to_i
DISKS = ARGV.shift.chomp.split(',')
WINDOWS = !ARGV.shift.nil?

if CORES > 16 then
  puts "Invalid machine. Too many cores: #{CORES}."
  exit 1
end

if MEM > 180 then
  puts "Invalid machine. Too much memory: #{MEM} GiB."
  exit 1
end

if DISKS.length > 8 then
  puts "Invalid machine. Too many disks: #{DISKS.length}."
  exit 1
end

memmin = (CORES - 1) * 4

def max(a,b)
  if a > b then
    return a
  else
    return b
  end
end

cost = max(memmin, MEM) * 10

firstdisk = true

DISKS.each do |disk|
  grade, size = disk.split(':')
  if size.nil? then
    size = grade
    grade = 'sata'
  end

  size = size.to_i

  case grade
  when 'sata'
    if firstdisk then
      cost += (max((size - 25), 0)/10.0).ceil * 2
      firstdisk = false
    else
      cost += (size/10.0).ceil * 2
    end
  when 'sas'
    cost += (size/5.0).ceil * 2
  when 'ssd'
    cost += (size/0.5).ceil * 2
  when 'archive'
    cost += (size/100.0).ceil * 2
  end
end

cost += MEM if WINDOWS

puts "Machine cost: £#{cost}.00"