Class: LinodeCluster::Cluster
- Inherits:
-
Object
- Object
- LinodeCluster::Cluster
- Defined in:
- lib/linode_cluster/cluster.rb
Overview
Cluster class
Instance Attribute Summary collapse
-
#ansible_ssh_user ⇒ Object
Returns the value of attribute ansible_ssh_user.
-
#app_name ⇒ Object
Returns the value of attribute app_name.
-
#client ⇒ Object
Returns the value of attribute client.
-
#image_name ⇒ Object
Returns the value of attribute image_name.
-
#stage ⇒ Object
Returns the value of attribute stage.
Instance Method Summary collapse
- #add_node_group(name, region, size, count, options = {}) ⇒ Object
- #as_ansible_inventory ⇒ Object
- #cost_per_month ⇒ Object
- #create! ⇒ Object
- #create_node(attributes) ⇒ Object
-
#initialize(api_key, app_name, stage, options) ⇒ Cluster
constructor
A new instance of Cluster.
- #name_prefix ⇒ Object
- #nodes ⇒ Object
Constructor Details
#initialize(api_key, app_name, stage, options) ⇒ Cluster
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/linode_cluster/cluster.rb', line 11 def initialize(api_key, app_name, stage, ) @node_groups = {} @app_name = app_name || '' @stage = stage || '' @client = ClientWrapper.new(Linode.new(api_key: api_key)) @ansible_ssh_user = [:ansible_ssh_user] || 'root' @image_name = [:image_name] raise 'app name cannot be blank' if app_name.empty? raise 'stage cannot be blank' if stage.empty? end |
Instance Attribute Details
#ansible_ssh_user ⇒ Object
Returns the value of attribute ansible_ssh_user.
9 10 11 |
# File 'lib/linode_cluster/cluster.rb', line 9 def ansible_ssh_user @ansible_ssh_user end |
#app_name ⇒ Object
Returns the value of attribute app_name.
9 10 11 |
# File 'lib/linode_cluster/cluster.rb', line 9 def app_name @app_name end |
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/linode_cluster/cluster.rb', line 9 def client @client end |
#image_name ⇒ Object
Returns the value of attribute image_name.
9 10 11 |
# File 'lib/linode_cluster/cluster.rb', line 9 def image_name @image_name end |
#stage ⇒ Object
Returns the value of attribute stage.
9 10 11 |
# File 'lib/linode_cluster/cluster.rb', line 9 def stage @stage end |
Instance Method Details
#add_node_group(name, region, size, count, options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/linode_cluster/cluster.rb', line 23 def add_node_group(name, region, size, count, = {}) 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, ()) end |
#as_ansible_inventory ⇒ Object
36 37 38 |
# 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 ⇒ Object
44 45 46 |
# File 'lib/linode_cluster/cluster.rb', line 44 def cost_per_month nodes.map(&:cost_per_month).sum end |
#create! ⇒ Object
28 29 30 |
# File 'lib/linode_cluster/cluster.rb', line 28 def create! @node_groups.each_value(&:create!) end |
#create_node(attributes) ⇒ Object
48 49 50 51 52 |
# File 'lib/linode_cluster/cluster.rb', line 48 def create_node(attributes) result = node_factory.create(attributes) @nodes = nil result end |
#name_prefix ⇒ Object
32 33 34 |
# File 'lib/linode_cluster/cluster.rb', line 32 def name_prefix "#{app_name}-#{stage}-" end |
#nodes ⇒ Object
40 41 42 |
# File 'lib/linode_cluster/cluster.rb', line 40 def nodes @node_groups.values.flat_map(&:nodes) end |