class LinodeCluster::Cluster

Cluster class

Attributes

ansible_ssh_user[RW]
app_name[RW]
client[RW]
image_name[RW]
stage[RW]

Public Class Methods

new(api_key, app_name, stage, options) click to toggle source
# File lib/linode_cluster/cluster.rb, line 11
def initialize(api_key, app_name, stage, options)
  @node_groups = {}
  @app_name = app_name || ''
  @stage = stage || ''
  @client = ClientWrapper.new(Linode.new(api_key: api_key))
  @ansible_ssh_user = options[:ansible_ssh_user] || 'root'
  @image_name = options[:image_name]

  raise 'app name cannot be blank' if app_name.empty?
  raise 'stage cannot be blank' if stage.empty?
end

Public Instance Methods

add_node_group(name, region, size, count, options = {}) click to toggle source
# File lib/linode_cluster/cluster.rb, line 23
def add_node_group(name, region, size, count, options = {})
  raise "Group with name '#{name}' already exists" if @node_groups[name]
  @node_groups[name] = NodeGroup.new(name, name_prefix, region, size, count, image_name, self, default_options(options))
end
as_ansible_inventory() click to toggle source
# File lib/linode_cluster/cluster.rb, line 36
def as_ansible_inventory
  @node_groups.map { |_, group| group.as_ansible_inventory }.join
end
cost_per_month() click to toggle source
# File lib/linode_cluster/cluster.rb, line 44
def cost_per_month
  nodes.map(&:cost_per_month).sum
end
create!() click to toggle source
# File lib/linode_cluster/cluster.rb, line 28
def create!
  @node_groups.each_value(&:create!)
end
create_node(attributes) click to toggle source
# File lib/linode_cluster/cluster.rb, line 48
def create_node(attributes)
  result = node_factory.create(attributes)
  @nodes = nil
  result
end
name_prefix() click to toggle source
# File lib/linode_cluster/cluster.rb, line 32
def name_prefix
  "#{app_name}-#{stage}-"
end
nodes() click to toggle source
# File lib/linode_cluster/cluster.rb, line 40
def nodes
  @node_groups.values.flat_map(&:nodes)
end

Private Instance Methods

default_options(options) click to toggle source
# File lib/linode_cluster/cluster.rb, line 60
def default_options(options)
  actual_options = options.dup
  actual_options[:ansible_ssh_user] ||= ansible_ssh_user
  actual_options[:ansible_ssh_host] ||= '{{ ip_address }}'
  actual_options
end
node_factory() click to toggle source
# File lib/linode_cluster/cluster.rb, line 56
def node_factory
  NodeFactory.new(client)
end