Module: VScripts::AWS::EC2
- Included in:
- VScripts::AWS
- Defined in:
- lib/vscripts/aws/ec2.rb
Overview
AWS Elastic Compute Cloud
Instance Method Summary collapse
-
#all_tags ⇒ AWS::EC2::ResourceTagCollection
Tags collection.
-
#create_tag(resource, key, value) ⇒ AWS::EC2::Tag
Creates an EC2 Tag.
-
#ec2 ⇒ Object
Load AWS SDK for EC2.
-
#functional_instances ⇒ Object
@return Lists instances that are not terminated.
-
#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.
Instance Method Details
#all_tags ⇒ AWS::EC2::ResourceTagCollection
Returns Tags collection.
21 22 23 |
# File 'lib/vscripts/aws/ec2.rb', line 21 def instance. end |
#create_tag(resource, key, value) ⇒ AWS::EC2::Tag
Returns Creates an EC2 Tag.
31 32 33 |
# File 'lib/vscripts/aws/ec2.rb', line 31 def create_tag(resource, key, value) ec2..create(resource, key, value) end |
#ec2 ⇒ Object
Load AWS SDK for EC2
10 11 12 |
# File 'lib/vscripts/aws/ec2.rb', line 10 def ec2 ::AWS::EC2.new(region: region) end |
#functional_instances ⇒ Object
@return Lists instances that are not terminated
56 57 58 59 60 61 |
# File 'lib/vscripts/aws/ec2.rb', line 56 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
15 16 17 18 |
# File 'lib/vscripts/aws/ec2.rb', line 15 def instance check_instance ec2.instances[instance_id] end |
#name ⇒ Object
Looks for the value of the ‘Name’ tag for the given instance
45 46 47 |
# File 'lib/vscripts/aws/ec2.rb', line 45 def name ['Name'] end |
#named_instances ⇒ Object
@return Lists instances that have a ‘Name’ tag
51 52 53 |
# File 'lib/vscripts/aws/ec2.rb', line 51 def named_instances ec2.instances.tagged('Name') end |
#similar_instances ⇒ Object
@return The ‘Name’ tag value except the local instance
64 65 66 67 68 69 70 |
# File 'lib/vscripts/aws/ec2.rb', line 64 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.
26 27 28 |
# File 'lib/vscripts/aws/ec2.rb', line 26 def tag(key) instance.[key] end |
#tags_without(list = []) ⇒ Object
Get a list of tags
36 37 38 39 40 41 42 |
# File 'lib/vscripts/aws/ec2.rb', line 36 def (list = []) .each_with_object({}) do |tag, hash| key, value = tag[0], tag[1] hash[key] = value unless list.include? key hash end end |