Module: Boucher::Servers
- Defined in:
- lib/boucher/servers.rb
Constant Summary collapse
- NotFound =
Class.new(StandardError)
Class Method Summary collapse
- .clear ⇒ Object
- .cultivate(thing) ⇒ Object
- .instance ⇒ Object
- .reload ⇒ Object
- .restart(servers) ⇒ Object
- .start(servers) ⇒ Object
- .stop(servers) ⇒ Object
- .terminate(servers) ⇒ Object
Instance Method Summary collapse
- #[](meal) ⇒ Object
- #all ⇒ Object
- #find(options = {}) ⇒ Object
- #in_env(env) ⇒ Object
- #in_state(state) ⇒ Object
- #of_meal(meal) ⇒ Object
- #search(options = {}) ⇒ Object
- #with_id(server_id) ⇒ Object
Class Method Details
.clear ⇒ Object
39 40 41 |
# File 'lib/boucher/servers.rb', line 39 def clear @instance = nil end |
.cultivate(thing) ⇒ Object
58 59 60 61 |
# File 'lib/boucher/servers.rb', line 58 def cultivate(thing) thing.extend(Boucher::Servers) if thing thing end |
.instance ⇒ Object
43 44 45 46 |
# File 'lib/boucher/servers.rb', line 43 def instance reload if !@instance @instance end |
.reload ⇒ Object
48 49 50 51 52 |
# File 'lib/boucher/servers.rb', line 48 def reload @instance = Boucher.compute.servers @instance.each {} # Wake up you lazy list! cultivate(@instance) end |
.restart(servers) ⇒ Object
110 111 112 113 |
# File 'lib/boucher/servers.rb', line 110 def self.restart(servers) Boucher.change_servers_state(servers, :stop, "stopped") Boucher.change_servers_state(servers, :start, "running") end |
.start(servers) ⇒ Object
102 103 104 |
# File 'lib/boucher/servers.rb', line 102 def self.start(servers) Boucher.change_servers_state(servers, :start, "running") end |
.stop(servers) ⇒ Object
106 107 108 |
# File 'lib/boucher/servers.rb', line 106 def self.stop(servers) Boucher.change_servers_state(servers, :stop, "stopped") end |
.terminate(servers) ⇒ Object
115 116 117 |
# File 'lib/boucher/servers.rb', line 115 def self.terminate(servers) Boucher.change_servers_state(servers, :destroy, "terminated") end |
Instance Method Details
#[](meal) ⇒ Object
123 124 125 |
# File 'lib/boucher/servers.rb', line 123 def [](meal) find(:env => Boucher::Config[:env], :meal => meal, :state => "running") end |
#all ⇒ Object
64 65 66 |
# File 'lib/boucher/servers.rb', line 64 def all self end |
#find(options = {}) ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/boucher/servers.rb', line 76 def find(={}) servers = search() first = servers.first if first.nil? raise Boucher::Servers::NotFound.new("No server matches criteria: #{.inspect}") end first end |
#in_env(env) ⇒ Object
85 86 87 |
# File 'lib/boucher/servers.rb', line 85 def in_env(env) Servers.cultivate(self.find_all { |s| s.["Env"] == env.to_s }) end |
#in_state(state) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/boucher/servers.rb', line 89 def in_state(state) if state[0] == "!" state = state[1..-1] Servers.cultivate(self.find_all { |s| s.state != state.to_s }) else Servers.cultivate(self.find_all { |s| s.state == state.to_s }) end end |
#of_meal(meal) ⇒ Object
98 99 100 |
# File 'lib/boucher/servers.rb', line 98 def of_meal(meal) Servers.cultivate(self.find_all { |s| s.["Meal"] == meal.to_s }) end |
#search(options = {}) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/boucher/servers.rb', line 68 def search(={}) servers = self servers = servers.of_meal([:meal]) if [:meal] servers = servers.in_env([:env]) if [:env] servers = servers.in_state([:state]) if [:state] servers end |