/
option.rb
67 lines (54 loc) · 2.24 KB
/
option.rb
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
# frozen_string_literal: true
require "yaml"
module Option
providers = YAML.load_file("config/providers.yml")
Provider = Struct.new(:name, :display_name)
Location = Struct.new(:provider, :name, :display_name, :visible)
PROVIDERS = {}
LOCATIONS = []
providers.each do |provider|
provider_internal_name = provider["provider_internal_name"]
PROVIDERS[provider_internal_name] = Provider.new(provider_internal_name, provider["provider_display_name"])
Provider.const_set(provider_internal_name.gsub(/[^a-zA-Z]/, "_").upcase, provider_internal_name)
provider["locations"].each do |location|
LOCATIONS.push(Location.new(
PROVIDERS[provider_internal_name],
location["internal_name"],
location["display_name"],
location["visible"]
))
end
end
PROVIDERS.freeze
LOCATIONS.freeze
def self.locations(only_visible: true)
Option::LOCATIONS.select { !only_visible || _1.visible }
end
def self.postgres_locations
Option::LOCATIONS.select { _1.name == "hetzner-fsn1" }
end
BootImage = Struct.new(:name, :display_name)
BootImages = [
["ubuntu-jammy", "Ubuntu Jammy 22.04 LTS"]
].map { |args| BootImage.new(*args) }.freeze
VmSize = Struct.new(:name, :family, :vcpu, :memory, :storage_size_gib, :visible, :gpu) do
alias_method :display_name, :name
end
VmSizes = [2, 4, 8, 16, 30].map {
VmSize.new("standard-#{_1}", "standard", _1, _1 * 4, (_1 / 2) * 25, true, false)
}.concat([6].map {
VmSize.new("standard-gpu-#{_1}", "standard-gpu", _1, (_1 * 5.34).to_i, (_1 / 2) * 60, false, true)
}).freeze
PostgresSize = Struct.new(:name, :vm_size, :family, :vcpu, :memory, :storage_size_gib) do
alias_method :display_name, :name
end
PostgresSizes = [2, 4, 8, 16].map {
PostgresSize.new("standard-#{_1}", "standard-#{_1}", "standard", _1, _1 * 4, (_1 / 2) * 128)
}.freeze
PostgresHaOption = Struct.new(:name, :standby_count, :title, :explanation)
PostgresHaOptions = [[PostgresResource::HaType::NONE, 0, "No Standbys", "No replication"],
[PostgresResource::HaType::ASYNC, 1, "1 Standby", "Asyncronous replication"],
[PostgresResource::HaType::SYNC, 2, "2 Standbys", "Syncronous replication with quorum"]].map {
PostgresHaOption.new(*_1)
}.freeze
end