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.
-
#all_tags_hash ⇒ Hash
A correct Hash object with all tags and keys.
-
#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 |
#all_tags_hash ⇒ Hash
Returns a correct Hash object with all tags and keys.
42 43 44 45 46 47 48 |
# File 'lib/vscripts/aws/ec2.rb', line 42 def hash = {} .each do |key, value| hash = hash.merge(Hash[key, value]) end hash 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.
73 74 75 76 77 78 |
# File 'lib/vscripts/aws/ec2.rb', line 73 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
63 64 65 |
# File 'lib/vscripts/aws/ec2.rb', line 63 def name ['Name'] end |
#named_instances ⇒ AWS::EC2::InstanceCollection
Returns the value of the name tag.
68 69 70 |
# File 'lib/vscripts/aws/ec2.rb', line 68 def named_instances ec2.instances.tagged('Name') end |
#similar_instances ⇒ AWS::EC2::InstanceCollection
Returns running instances that have a Name tag.
82 83 84 85 86 87 88 |
# File 'lib/vscripts/aws/ec2.rb', line 82 def similar_instances check_instance functional_instances.compact.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
53 54 55 56 57 58 59 |
# File 'lib/vscripts/aws/ec2.rb', line 53 def (list = []) hash = list.each do |key| hash.delete(key) end hash end |