Class: Cloudfinder::EC2::Command::List

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudfinder-ec2/command/list.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(finder, detector, stdout, stderr) ⇒ List

Returns a new instance of List.

Parameters:



23
24
25
26
27
28
# File 'lib/cloudfinder-ec2/command/list.rb', line 23

def initialize(finder, detector, stdout, stderr)
  @finder = finder
  @detector = detector
  @stdout = stdout
  @stderr = stderr
end

Class Method Details

.factoryObject

Factory an instance of the list command with concrete dependencies

Returns:

  • (Object)


10
11
12
13
14
15
16
17
# File 'lib/cloudfinder-ec2/command/list.rb', line 10

def self.factory
  self.new(
      Cloudfinder::EC2::Clusterfinder.new,
      Cloudfinder::EC2::Detector.new,
      STDOUT,
      STDERR
  )
end

Instance Method Details

#execute(query = {}) ⇒ Object

Locates the roles and instances that make up a cluster, and prints the result to STDOUT as JSON for consumption by other processes.

If the cluster_name or region are not provided, it will attempt to detect the cluster that the current instance belongs to (using the EC2 metadata service) and find other instances in the same cluster.

If cluster detection fails, an exception will be thrown

Parameters:

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

Options Hash (query):

  • :cluster_name (string)

    optionally specify cluster name to find

  • :region (string)

    optionally specify EC2 region to search

Returns:

  • void



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cloudfinder-ec2/command/list.rb', line 43

def execute(query = {})
  unless query[:region] && query[:cluster_name]
    detected = autodetect_cluster_or_throw
    [:region, :cluster_name].each do |key|
      query[key] = detected[key] if query[key].nil?
    end
  end

  cluster = @finder.find(query)
  @stdout.puts(JSON.pretty_generate(cluster.to_hash))
end