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



47
48
49
50
# File 'lib/elasticity/instance_group.rb', line 47

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

#set_spot_instances(bid_price) ⇒ Object



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

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

#to_aws_instance_configObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/elasticity/instance_group.rb', line 52

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