Class: Discotheque::Discover
- Inherits:
-
Object
- Object
- Discotheque::Discover
- Defined in:
- lib/discotheque/discover.rb
Constant Summary collapse
- VALID_FILTERS =
NOTE tags are not available via metadata calls therefore tag will need to be an explcit value passed in This actually makes sense if you want to discover a tag that isn’t yours Take the use case of a master/slave setup: You would tag the master node with “foo_slave” but you might need to find all slaves
%w[az sg tag ami arch]- FILTER_MAP =
{"az" => "availability-zone", "sg" => "group-name", "ami" => "image-id", "arch" => "architecture"}
Instance Attribute Summary collapse
-
#filters ⇒ Object
Returns the value of attribute filters.
Instance Method Summary collapse
- #clear_filters ⇒ Object
- #get_nodes(creds = {}) ⇒ Object
-
#initialize(filters = []) ⇒ Discover
constructor
A new instance of Discover.
Constructor Details
#initialize(filters = []) ⇒ Discover
Returns a new instance of Discover.
19 20 21 |
# File 'lib/discotheque/discover.rb', line 19 def initialize(filters=[]) @filters = filters end |
Instance Attribute Details
#filters ⇒ Object
Returns the value of attribute filters.
17 18 19 |
# File 'lib/discotheque/discover.rb', line 17 def filters @filters end |
Instance Method Details
#clear_filters ⇒ Object
36 37 38 |
# File 'lib/discotheque/discover.rb', line 36 def clear_filters @filters = [] end |
#get_nodes(creds = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/discotheque/discover.rb', line 23 def get_nodes(creds={}) # creds is a hash like so # creds = {:access_key_id => "YYYYYYYYYYYYYYYYYYYYYYYYYY", :secret_access_key => "XXXXXXXXXXXXX"} @filters.empty? ? f="ec2.instances" : f="ec2.instances.#{build_filter}" require 'aws-sdk' AWS.config creds ec2 = AWS::EC2.new candidates = AWS.memoize do ci = eval(f) ci.to_a.sort_by(&:ip_address).map {|i| i.ip_address} end end |