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

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

Instance Attribute Summary collapse

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

#resource

Class Method Summary collapse

Instance Method Summary collapse

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

#initialize

Constructor Details

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

Instance Attribute Details

#usernameObject

Returns the value of attribute username.



6
7
8
# File 'lib/phase/adapters/aws/server.rb', line 6

def username
  @username
end

Class Method Details

.allArray<AWS::Server>

Returns All known EC2 instances.

Returns:



17
18
19
# File 'lib/phase/adapters/aws/server.rb', line 17

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:



23
24
25
# File 'lib/phase/adapters/aws/server.rb', line 23

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/phase/adapters/aws/server.rb', line 37

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

Instance Method Details

#to_host_hash(host_method) ⇒ Object



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

def to_host_hash(host_method)
  {
    user:     username,
    hostname: resource.__send__(host_method)
  }
end