Module: VScripts::AWS::EC2
- Included in:
- VScripts::AWS
- Defined in:
- lib/vscripts/aws/ec2.rb
Overview
A collection of methods used for interaction with Amazon Web Service Elastic Compute Cloud.
Instance Method Summary collapse
-
#all_tags ⇒ AWS::EC2::ResourceTagCollection
All tags.
-
#create_tag(resource, key, value) ⇒ AWS::EC2::Tag
Creates an EC2 Tag.
-
#ec2 ⇒ Object
Loads AWS SDK for EC2.
-
#functional_instances ⇒ AWS::EC2::InstanceCollection
Instances that are not terminated.
-
#instance ⇒ AWS::EC2::Instance
The current instance.
-
#name ⇒ String
Looks for the value of the ‘Name’ tag for the given instance.
-
#named_instances ⇒ AWS::EC2::InstanceCollection
The value of the name tag.
-
#similar_instances ⇒ AWS::EC2::InstanceCollection
Running instances that have a Name tag.
-
#tag(key) ⇒ AWS::EC2::Tag
The value of the tag.
-
#tags_without(list = []) ⇒ Hash
Exclude tags.
Instance Method Details
#all_tags ⇒ AWS::EC2::ResourceTagCollection
Returns all tags.
22 23 24 |
# File 'lib/vscripts/aws/ec2.rb', line 22 def instance. end |
#create_tag(resource, key, value) ⇒ AWS::EC2::Tag
Creates an EC2 Tag
37 38 39 |
# File 'lib/vscripts/aws/ec2.rb', line 37 def create_tag(resource, key, value) ec2..create(resource, key, value) end |
#ec2 ⇒ Object
Loads AWS SDK for EC2
11 12 13 |
# File 'lib/vscripts/aws/ec2.rb', line 11 def ec2 ::AWS::EC2.new(region: region) end |
#functional_instances ⇒ AWS::EC2::InstanceCollection
Returns instances that are not terminated.
64 65 66 67 68 69 |
# File 'lib/vscripts/aws/ec2.rb', line 64 def functional_instances named_instances.map do |named_instance| named_instance if [:running, :shutting_down, :stopping, :stopped] .include?(named_instance.status) end end |
#instance ⇒ AWS::EC2::Instance
Returns the current instance.
16 17 18 19 |
# File 'lib/vscripts/aws/ec2.rb', line 16 def instance check_instance ec2.instances[instance_id] end |
#name ⇒ String
Looks for the value of the ‘Name’ tag for the given instance
54 55 56 |
# File 'lib/vscripts/aws/ec2.rb', line 54 def name ['Name'] end |
#named_instances ⇒ AWS::EC2::InstanceCollection
Returns the value of the name tag.
59 60 61 |
# File 'lib/vscripts/aws/ec2.rb', line 59 def named_instances ec2.instances.tagged('Name') end |
#similar_instances ⇒ AWS::EC2::InstanceCollection
Returns running instances that have a Name tag.
73 74 75 76 77 78 79 |
# File 'lib/vscripts/aws/ec2.rb', line 73 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::Tag
Returns the value of the tag.
28 29 30 |
# File 'lib/vscripts/aws/ec2.rb', line 28 def tag(key) instance.[key] end |
#tags_without(list = []) ⇒ Hash
Exclude tags
44 45 46 47 48 49 50 |
# File 'lib/vscripts/aws/ec2.rb', line 44 def (list = []) .each_with_object({}) do |tag, hash| key, value = tag[0], tag[1] hash[key] = value unless list.include? key hash end end |