Class: VScripts::AWS::EC2

Inherits:
Object
  • Object
show all
Includes:
Metadata
Defined in:
lib/vscripts/aws/ec2.rb

Overview

AWS Elastic Compute Cloud

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Metadata

#check_instance, #ec2_instance?, #instance_id, #metadata_url, #public_hostname, #region, #zone

Constructor Details

#initializeEC2

Load AWS SDK for EC2



14
15
16
# File 'lib/vscripts/aws/ec2.rb', line 14

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

Instance Attribute Details

#ec2AWS::EC2 (readonly)

Returns:



19
20
21
# File 'lib/vscripts/aws/ec2.rb', line 19

def ec2
  @ec2
end

Instance Method Details

#all_tagsAWS::EC2::ResourceTagCollection

Returns Tags collection.

Returns:

  • (AWS::EC2::ResourceTagCollection)

    Tags collection



28
29
30
# File 'lib/vscripts/aws/ec2.rb', line 28

def all_tags
  instance.tags
end

#functional_instancesObject

@return Lists instances that are not terminated



51
52
53
54
55
56
# File 'lib/vscripts/aws/ec2.rb', line 51

def functional_instances
  named_instances.map do |named_instance|
    named_instance if [:running, :shutting_down, :stopping, :stopped]
      .include?(named_instance.status)
  end
end

#instanceObject

Get instance object



22
23
24
25
# File 'lib/vscripts/aws/ec2.rb', line 22

def instance
  check_instance
  ec2.instances[instance_id]
end

#nameObject

Looks for the value of the ‘Name’ tag for the given instance



40
41
42
# File 'lib/vscripts/aws/ec2.rb', line 40

def name
  all_tags_hash['Name']
end

#named_instancesObject

@return Lists instances that have a ‘Name’ tag



46
47
48
# File 'lib/vscripts/aws/ec2.rb', line 46

def named_instances
  ec2.instances.tagged('Name')
end

#similar_instancesObject

@return The ‘Name’ tag value except the local instance



59
60
61
62
63
64
65
66
# File 'lib/vscripts/aws/ec2.rb', line 59

def similar_instances
  check_instance
  functional_instances.map do |functional_instance|
    if functional_instance.id != instance_id
      functional_instance.tags['Name']
    end
  end
end

#tags_without(list = []) ⇒ Object

Get a list of tags



33
34
35
36
37
# File 'lib/vscripts/aws/ec2.rb', line 33

def tags_without(list = [])
  all = all_tags
  list.each { |excluded| all.delete(excluded) }
  all
end