Class: RodeoClown::EC2

Inherits:
Struct
  • Object
show all
Includes:
InstanceBuilder
Defined in:
lib/rodeo_clown/ec2.rb

Constant Summary collapse

STATUS =
%w[pending running shutting-down terminated stopping stopped]

Instance Attribute Summary collapse

Attributes included from InstanceBuilder

#availability_zones, #key_pair, #options, #tags

Class Method Summary collapse

Instance Method Summary collapse

Methods included from InstanceBuilder

#build_instances, #build_options, #many_from_options

Instance Attribute Details

#ec2Object

Returns the value of attribute ec2

Returns:

  • (Object)

    the current value of ec2



3
4
5
# File 'lib/rodeo_clown/ec2.rb', line 3

def ec2
  @ec2
end

Class Method Details

.by_name(name) ⇒ Object



26
27
28
# File 'lib/rodeo_clown/ec2.rb', line 26

def self.by_name(name)
  new instances[name]
end

.by_tags(options = {}) ⇒ Object

Filter by had of tag values. Keys and values as strings

Examples

RodeoClown::EC2.by_tags("app" => "rodeo", "version" = "2.1")
# => [ instance-1, instanc-2 ]

Returns an array of instances



38
39
40
41
42
43
44
45
# File 'lib/rodeo_clown/ec2.rb', line 38

def self.by_tags(options = {})
  return instances if options.nil? || options.empty?

  instances.tagged_values(options.values).select do |instance|
    tags = instance.tags.to_h
    (options.to_a - tags.to_a).empty?
  end
end

.create_instance(options) ⇒ Object



16
17
18
19
20
# File 'lib/rodeo_clown/ec2.rb', line 16

def self.create_instance(options)
  new_instance = instances.create(options)
  instances.wait_for_status(:running, 2, [*new_instance])
  new_instance
end

.ec2Object



12
13
14
# File 'lib/rodeo_clown/ec2.rb', line 12

def self.ec2
  @ec2 ||= AWS::EC2.new
end

.instancesObject



8
9
10
# File 'lib/rodeo_clown/ec2.rb', line 8

def self.instances
  ec2.instances
end

Instance Method Details

#create_instance(options) ⇒ Object



22
23
24
# File 'lib/rodeo_clown/ec2.rb', line 22

def create_instance(options)
  self.class.create_instance(options)
end

#dns_nameObject



67
68
69
# File 'lib/rodeo_clown/ec2.rb', line 67

def dns_name
  ec2.dns_name
end

#pending?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/rodeo_clown/ec2.rb', line 51

def pending?
  ec2.status == :pending
end

#rebootObject



47
48
49
# File 'lib/rodeo_clown/ec2.rb', line 47

def reboot
  ec2.reboot
end

#running?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/rodeo_clown/ec2.rb', line 55

def running?
  ec2.status == :running
end

#stopped?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/rodeo_clown/ec2.rb', line 59

def stopped?
  ec2.status == :stopped
end

#terminated?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/rodeo_clown/ec2.rb', line 63

def terminated?
  ec2.status == :terminated
end