Class: VScripts::AWS::EC2
- Inherits:
-
Object
- Object
- VScripts::AWS::EC2
- Includes:
- Metadata
- Defined in:
- lib/vscripts/aws/ec2.rb
Overview
AWS Elastic Compute Cloud
Instance Attribute Summary collapse
- #ec2 ⇒ AWS::EC2 readonly
Instance Method Summary collapse
-
#all_tags ⇒ AWS::EC2::ResourceTagCollection
Tags collection.
-
#create_tag(resource, key, value) ⇒ AWS::EC2::Tag
Creates an EC2 Tag.
-
#functional_instances ⇒ Object
@return Lists instances that are not terminated.
-
#initialize ⇒ EC2
constructor
Load AWS SDK for EC2.
-
#instance ⇒ Object
Get instance object.
-
#name ⇒ Object
Looks for the value of the ‘Name’ tag for the given instance.
-
#named_instances ⇒ Object
@return Lists instances that have a ‘Name’ tag.
-
#similar_instances ⇒ Object
@return The ‘Name’ tag value except the local instance.
-
#tag(key) ⇒ AWS::EC2::ResourceTagCollection
Tags collection.
-
#tags_without(list = []) ⇒ Object
Get a list of tags.
Methods included from Metadata
#check_instance, #ec2_instance?, #instance_id, #metadata_url, #public_hostname, #region, #zone
Constructor Details
#initialize ⇒ EC2
Load AWS SDK for EC2
14 15 16 |
# File 'lib/vscripts/aws/ec2.rb', line 14 def initialize @ec2 ||= ::AWS::EC2.new(region: region) end |
Instance Attribute Details
Instance Method Details
#all_tags ⇒ AWS::EC2::ResourceTagCollection
Returns Tags collection.
28 29 30 |
# File 'lib/vscripts/aws/ec2.rb', line 28 def instance. end |
#create_tag(resource, key, value) ⇒ AWS::EC2::Tag
Returns Creates an EC2 Tag.
38 39 40 |
# File 'lib/vscripts/aws/ec2.rb', line 38 def create_tag(resource, key, value) ec2..create(resource, key, value) end |
#functional_instances ⇒ Object
@return Lists instances that are not terminated
61 62 63 64 65 66 |
# File 'lib/vscripts/aws/ec2.rb', line 61 def functional_instances named_instances.map do |named_instance| named_instance if [:running, :shutting_down, :stopping, :stopped] .include?(named_instance.status) end end |
#instance ⇒ Object
Get instance object
22 23 24 25 |
# File 'lib/vscripts/aws/ec2.rb', line 22 def instance check_instance ec2.instances[instance_id] end |
#name ⇒ Object
Looks for the value of the ‘Name’ tag for the given instance
50 51 52 |
# File 'lib/vscripts/aws/ec2.rb', line 50 def name ['Name'] end |
#named_instances ⇒ Object
@return Lists instances that have a ‘Name’ tag
56 57 58 |
# File 'lib/vscripts/aws/ec2.rb', line 56 def named_instances ec2.instances.tagged('Name') end |
#similar_instances ⇒ Object
@return The ‘Name’ tag value except the local instance
69 70 71 72 73 74 75 |
# File 'lib/vscripts/aws/ec2.rb', line 69 def similar_instances check_instance functional_instances.map do |functional_instance| next if functional_instance.id == instance_id functional_instance.['Name'] end end |
#tag(key) ⇒ AWS::EC2::ResourceTagCollection
Returns Tags collection.
33 34 35 |
# File 'lib/vscripts/aws/ec2.rb', line 33 def tag(key) instance.[key] end |
#tags_without(list = []) ⇒ Object
Get a list of tags
43 44 45 46 47 |
# File 'lib/vscripts/aws/ec2.rb', line 43 def (list = []) all = list.each { |excluded| all.delete(excluded) } all end |