Class: Cloudfinder::EC2::Command::List
- Inherits:
-
Object
- Object
- Cloudfinder::EC2::Command::List
- Defined in:
- lib/cloudfinder-ec2/command/list.rb
Class Method Summary collapse
-
.factory ⇒ Object
Factory an instance of the list command with concrete dependencies.
Instance Method Summary collapse
-
#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.
-
#initialize(finder, detector, stdout, stderr) ⇒ List
constructor
A new instance of List.
Constructor Details
#initialize(finder, detector, stdout, stderr) ⇒ List
Returns a new instance of List.
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
.factory ⇒ Object
Factory an instance of the list command with concrete dependencies
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
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 |