Class: Phase::Adapters::AWS::Server

Inherits:
Phase::Adapters::Abstract::Server show all
Defined in:
lib/phase/adapters/aws/server.rb

Instance Attribute Summary

Attributes inherited from Phase::Adapters::Abstract::Base

#resource

Class Method Summary collapse

Methods inherited from Phase::Adapters::Abstract::Base

#initialize

Constructor Details

This class inherits a constructor from Phase::Adapters::Abstract::Base

Class Method Details

.allArray<AWS::Server>

Returns All known EC2 instances.

Returns:



8
9
10
# File 'lib/phase/adapters/aws/server.rb', line 8

def all
  where
end

.find(instance_id, options = {}) ⇒ AWS::Server

Returns The requested EC2 instance.

Parameters:

  • instance_id (String)

    The ID of the requested EC2 instance

Returns:



14
15
16
# File 'lib/phase/adapters/aws/server.rb', line 14

def find(instance_id, options = {})
  new(api.servers.get(instance_id))
end

.where(options = {}) ⇒ Array<AWS::Server>

Finds servers through the provided filter options.

Parameters:

  • options (Hash) (defaults to: {})

    Filtering options

Options Hash (options):

  • :vpc_id (String)

    The ID of a VPC

  • :name (String)

    The value of the ‘Name’ tag

  • :role (String)

    The value of the ‘Role’ tag

  • :environment (String)

    The value of the ‘Environment’ tag

  • :instance_ids (Array<String>)

    A list of specific instance IDs

  • :subnet_id (String)

    The ID of a subnet

Returns:

  • (Array<AWS::Server>)

    All EC2 instances matching the optional filters



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/phase/adapters/aws/server.rb', line 28

def where(options = {})
  filters = {}

  filters["vpc-id"] = options.delete(:vpc_id)               if options.has_key?(:vpc_id)
  filters["tag:Name"] = options.delete(:name)               if options.has_key?(:name)
  filters["instance-ids"] = options.delete(:ids)            if options.has_key?(:ids)
  filters["subnet-id"] = options.delete(:subnet_id)         if options.has_key?(:subnet_id)
  filters["tag:Role"] = options.delete(:role)               if options.has_key?(:role)
  filters["tag:Environment"] = options.delete(:environment) if options.has_key?(:environment)

  if options.any?
    raise ArgumentError, "Unknown filters '#{options.keys.join(", ")}'!"
  end

  api.servers.all(filters).map {|server| new(server) }
end