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.



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

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.



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

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

#ebs_configurationObject (readonly)

Returns the value of attribute ebs_configuration.



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

def ebs_configuration
  @ebs_configuration
end

#marketObject (readonly)

Returns the value of attribute market.



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

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_ebs_configuration(ebs_configuration) ⇒ Object



53
54
55
56
57
# File 'lib/elasticity/instance_group.rb', line 53

def set_ebs_configuration(ebs_configuration)
  if ebs_configuration.is_a?(Elasticity::EbsConfiguration)
    @ebs_configuration = ebs_configuration
  end
end

#set_on_demand_instancesObject



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

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

#set_spot_instances(bid_price) ⇒ Object



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

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



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/elasticity/instance_group.rb', line 59

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'
    config.merge!(:ebs_configuration => @ebs_configuration.to_aws_ebs_config) if @ebs_configuration != nil
  end
end