Class: CORL::Machine::FogBase
- Inherits:
-
Object
- Object
- CORL::Machine::FogBase
- Includes:
- CORL::Mixin::Machine::SSH
- Defined in:
- lib/core/plugin/fog_machine.rb
Instance Method Summary collapse
- #compute ⇒ Object
-
#compute=(compute) ⇒ Object
—.
-
#create(options = {}, &code) ⇒ Object
—.
-
#create_image(options = {}, &code) ⇒ Object
—.
-
#created? ⇒ Boolean
—————————————————————————– Checks.
-
#destroy(options = {}, &code) ⇒ Object
—.
-
#download(remote_path, local_path, options = {}, &code) ⇒ Object
—.
-
#exec(commands, options = {}, &code) ⇒ Object
—.
-
#image ⇒ Object
—.
-
#images ⇒ Object
—.
-
#load ⇒ Object
—.
-
#machine_type ⇒ Object
—.
-
#machine_types ⇒ Object
—.
-
#normalize(reload) ⇒ Object
—————————————————————————– Machine plugin interface.
-
#private_ip ⇒ Object
—.
-
#public_ip ⇒ Object
—.
-
#reload(options = {}, &code) ⇒ Object
—.
-
#running? ⇒ Boolean
—.
- #server ⇒ Object
-
#server=(id) ⇒ Object
—.
-
#ssh_wait_for_ready ⇒ Object
—————————————————————————– Utilities.
-
#state ⇒ Object
—.
-
#stop(options = {}) ⇒ Object
—.
-
#terminal(user, options = {}) ⇒ Object
—.
-
#upload(local_path, remote_path, options = {}, &code) ⇒ Object
—.
Methods included from CORL::Mixin::Machine::SSH
#close_ssh_session, #init_ssh_session, #ssh_download, #ssh_exec, #ssh_terminal, #ssh_upload
Instance Method Details
#compute ⇒ Object
57 58 59 60 |
# File 'lib/core/plugin/fog_machine.rb', line 57 def compute set_connection unless @compute @compute end |
#compute=(compute) ⇒ Object
53 54 55 |
# File 'lib/core/plugin/fog_machine.rb', line 53 def compute=compute @compute = compute end |
#create(options = {}, &code) ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/core/plugin/fog_machine.rb', line 151 def create( = {}, &code) super do |config| if compute code.call(config) if code myself.server = compute.servers.bootstrap(config.export) end myself.server ? true : false end end |
#create_image(options = {}, &code) ⇒ Object
204 205 206 207 208 209 210 211 |
# File 'lib/core/plugin/fog_machine.rb', line 204 def create_image( = {}, &code) super do |config| image_name = sprintf("%s (%s)", node.plugin_name, Time.now.to_s) success = code ? code.call(image_name, config, success) : true success = init_ssh_session(true, config.get(:tries, 12), config.get(:sleep_time, 5)) if success end end |
#created? ⇒ Boolean
Checks
23 24 25 |
# File 'lib/core/plugin/fog_machine.rb', line 23 def created? server && ! server.state != 'DELETED' end |
#destroy(options = {}, &code) ⇒ Object
224 225 226 227 228 229 230 231 232 |
# File 'lib/core/plugin/fog_machine.rb', line 224 def destroy( = {}, &code) super do |config| success = server.destroy success = code.call(config) if success && code close_ssh_session if success success end end |
#download(remote_path, local_path, options = {}, &code) ⇒ Object
163 164 165 166 167 |
# File 'lib/core/plugin/fog_machine.rb', line 163 def download(remote_path, local_path, = {}, &code) super do |config, success| ssh_download(remote_path, local_path, config, &code) end end |
#exec(commands, options = {}, &code) ⇒ Object
179 180 181 182 183 |
# File 'lib/core/plugin/fog_machine.rb', line 179 def exec(commands, = {}, &code) super do |config| ssh_exec(commands, config, &code) end end |
#image ⇒ Object
125 126 127 128 |
# File 'lib/core/plugin/fog_machine.rb', line 125 def image return server.image.id if server nil end |
#images ⇒ Object
118 119 120 121 |
# File 'lib/core/plugin/fog_machine.rb', line 118 def images return compute.images if compute [] end |
#load ⇒ Object
142 143 144 145 146 147 |
# File 'lib/core/plugin/fog_machine.rb', line 142 def load super do myself.server = plugin_name if compute && plugin_name ! plugin_name && @server.nil? ? false : true end end |
#machine_type ⇒ Object
111 112 113 114 |
# File 'lib/core/plugin/fog_machine.rb', line 111 def machine_type return server.flavor.id if server nil end |
#machine_types ⇒ Object
104 105 106 107 |
# File 'lib/core/plugin/fog_machine.rb', line 104 def machine_types return compute.flavors if compute [] end |
#normalize(reload) ⇒ Object
Machine plugin interface
15 16 17 18 |
# File 'lib/core/plugin/fog_machine.rb', line 15 def normalize(reload) super myself.plugin_name = '' if myself.plugin_provider == myself.plugin_name.to_sym end |
#private_ip ⇒ Object
97 98 99 100 |
# File 'lib/core/plugin/fog_machine.rb', line 97 def private_ip return server.private_ip_address if server nil end |
#public_ip ⇒ Object
90 91 92 93 |
# File 'lib/core/plugin/fog_machine.rb', line 90 def public_ip return server.public_ip_address if server nil end |
#reload(options = {}, &code) ⇒ Object
195 196 197 198 199 200 |
# File 'lib/core/plugin/fog_machine.rb', line 195 def reload( = {}, &code) super do |config| success = code ? code.call(config) : true success = init_ssh_session(true, config.get(:tries, 12), config.get(:sleep_time, 5)) if success end end |
#running? ⇒ Boolean
29 30 31 |
# File 'lib/core/plugin/fog_machine.rb', line 29 def running? created? && server.ready? end |
#server ⇒ Object
75 76 77 78 79 |
# File 'lib/core/plugin/fog_machine.rb', line 75 def server compute load unless @server @server end |
#server=(id) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/core/plugin/fog_machine.rb', line 64 def server=id @server = nil if id.is_a?(String) @server = compute.servers.get(id) unless id.empty? elsif ! id.nil? @server = id end init_server end |
#ssh_wait_for_ready ⇒ Object
Utilities
237 238 239 |
# File 'lib/core/plugin/fog_machine.rb', line 237 def ssh_wait_for_ready server.wait_for { ready? } end |
#state ⇒ Object
83 84 85 86 |
# File 'lib/core/plugin/fog_machine.rb', line 83 def state return translate_state(server.state) if server translate_state(:aborted) end |
#stop(options = {}) ⇒ Object
215 216 217 218 219 220 |
# File 'lib/core/plugin/fog_machine.rb', line 215 def stop( = {}) super do |config| success = false success = destroy(config.import({ :stop => true })) if create_image(config) end end |
#terminal(user, options = {}) ⇒ Object
187 188 189 190 191 |
# File 'lib/core/plugin/fog_machine.rb', line 187 def terminal(user, = {}) super do |config| ssh_terminal(user, config) end end |
#upload(local_path, remote_path, options = {}, &code) ⇒ Object
171 172 173 174 175 |
# File 'lib/core/plugin/fog_machine.rb', line 171 def upload(local_path, remote_path, = {}, &code) super do |config, success| ssh_upload(local_path, remote_path, config, &code) end end |