Module: Befog::Commands::Mixins::Selectable

Included in:
List, Remove, Run, Start, Stop
Defined in:
lib/befog/commands/mixins/selectable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(target) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/befog/commands/mixins/selectable.rb', line 5

def self.included(target)
  target.module_eval do
    
    option :provider,
      :short => :q,
      :description => "Select servers from this provider"

    option :region,
      :short => :r,
      :description => "Select servers from this region"

    option :image, 
      :short => :i,
      :description => "Select servers using this image"

    option :keypair, 
      :short => :x,
      :description => "Select servers using this keypair"

    option :group, 
      :short => :g,
      :description => "Select servers using this security group"

    option :type, 
      :short => :t,
      :description => "Select servers of this type (flavor)"

    option :id,
      :short => :z,
      :description => "Select server with the given ID"

  end
end

Instance Method Details

#run_for_selected(&block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/befog/commands/mixins/selectable.rb', line 39

def run_for_selected(&block)
  if bank? 
    servers.each(&block)
  else
    banks.keys.each do |name|
      options[:bank] = name
      if options[:id]
        block.call(options[:id]) if servers.include?(options[:id])
      else
        servers.each(&block) if ((not provider? or (bank["provider"] == provider_name)) and
          (not region? or (bank["region"] == region)) and
          (not image? or (bank["image"] == image)) and
          (not security_group? or (bank["group"] == security_group)) and
          (not flavor? or (bank["type"] == flavor)))
      end
    end
  end
  
end