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.
-
#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
Returns a new instance of Cluster.
11 12 13 14 15 16 17 18 19 20 |
# 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' 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 |
#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
22 23 24 25 |
# File 'lib/linode_cluster/cluster.rb', line 22 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, self, ()) end |
#as_ansible_inventory ⇒ Object
35 36 37 |
# File 'lib/linode_cluster/cluster.rb', line 35 def as_ansible_inventory @node_groups.map { |_, group| group.as_ansible_inventory }.join end |
#cost_per_month ⇒ Object
43 44 45 |
# File 'lib/linode_cluster/cluster.rb', line 43 def cost_per_month nodes.map(&:cost_per_month).sum end |
#create! ⇒ Object
27 28 29 |
# File 'lib/linode_cluster/cluster.rb', line 27 def create! @node_groups.each_value(&:create!) end |
#create_node(attributes) ⇒ Object
47 48 49 50 51 |
# File 'lib/linode_cluster/cluster.rb', line 47 def create_node(attributes) result = node_factory.create(attributes) @nodes = nil result end |
#name_prefix ⇒ Object
31 32 33 |
# File 'lib/linode_cluster/cluster.rb', line 31 def name_prefix "#{app_name}-#{stage}-" end |
#nodes ⇒ Object
39 40 41 |
# File 'lib/linode_cluster/cluster.rb', line 39 def nodes @node_groups.values.flat_map(&:nodes) end |