Class: Elasticity::InstanceGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/elasticity/instance_group.rb

Constant Summary collapse

ROLES =
%w(MASTER CORE TASK)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInstanceGroup

Returns a new instance of InstanceGroup.



14
15
16
17
18
19
# File 'lib/elasticity/instance_group.rb', line 14

def initialize
  @count = 1
  @type = 'm1.small'
  @market = 'ON_DEMAND'
  @role = 'CORE'
end

Instance Attribute Details

#bid_priceObject (readonly)

Returns the value of attribute bid_price.



11
12
13
# File 'lib/elasticity/instance_group.rb', line 11

def bid_price
  @bid_price
end

#countObject

Returns the value of attribute count.



7
8
9
# File 'lib/elasticity/instance_group.rb', line 7

def count
  @count
end

#marketObject (readonly)

Returns the value of attribute market.



12
13
14
# File 'lib/elasticity/instance_group.rb', line 12

def market
  @market
end

#roleObject

Returns the value of attribute role.



9
10
11
# File 'lib/elasticity/instance_group.rb', line 9

def role
  @role
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/elasticity/instance_group.rb', line 8

def type
  @type
end

Instance Method Details

#set_on_demand_instancesObject



39
40
41
42
# File 'lib/elasticity/instance_group.rb', line 39

def set_on_demand_instances
  @bid_price = nil
  @market = 'ON_DEMAND'
end

#set_spot_instances(bid_price) ⇒ Object



33
34
35
36
37
# File 'lib/elasticity/instance_group.rb', line 33

def set_spot_instances(bid_price)
  raise_unless bid_price > 0, ArgumentError, "The bid price for spot instances should be greater than 0 (#{bid_price} requested)"
  @bid_price = bid_price
  @market = 'SPOT'
end

#to_aws_instance_configObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/elasticity/instance_group.rb', line 44

def to_aws_instance_config
  {
    :market => @market,
    :instance_count => @count,
    :instance_type => @type,
    :instance_role => @role,
  }.tap do |config|
    config.merge!(:bid_price => @bid_price) if @market == 'SPOT'
  end
end