Class: Coral::Machine::Fog
- Inherits:
-
Plugin::Machine
- Object
- Config
- Core
- Plugin::Base
- Plugin::Machine
- Coral::Machine::Fog
- Includes:
- Coral::Mixin::SubConfig
- Defined in:
- lib/coral/machine/fog.rb
Instance Attribute Summary
Attributes inherited from Core
Instance Method Summary collapse
-
#compute ⇒ Object
—.
-
#create(options = {}) ⇒ Object
—————————————————————————– Management.
-
#create_image(name, options = {}) ⇒ Object
—.
-
#created? ⇒ Boolean
—————————————————————————– Checks.
-
#destroy(options = {}) ⇒ Object
—.
-
#exec(options = {}) ⇒ Object
—.
-
#flavor ⇒ Object
—.
-
#flavors ⇒ Object
—.
-
#hostname ⇒ Object
—.
-
#image ⇒ Object
—.
-
#images ⇒ Object
—.
-
#name ⇒ Object
—.
-
#name=(id) ⇒ Object
—.
-
#normalize ⇒ Object
—————————————————————————– Machine plugin interface.
-
#private_ip ⇒ Object
—.
-
#public_ip ⇒ Object
—.
-
#reload(options = {}) ⇒ Object
—.
-
#running? ⇒ Boolean
—.
-
#server ⇒ Object
—.
-
#start(options = {}) ⇒ Object
—.
-
#state ⇒ Object
—.
-
#stop(options = {}) ⇒ Object
—.
Methods included from Coral::Mixin::SubConfig
#clear, #config, #config=, #defaults, #delete, #directory, #directory=, #export, #get, #import, #load, #save, #set
Methods inherited from Plugin::Machine
Methods inherited from Plugin::Base
build_info, ensure_plugin_collection, #initialize, #initialized?, #meta, #method_missing, #plugin_directory, #plugin_file, #plugin_instance_name, #plugin_parent, #plugin_parent=, #plugin_provider, #plugin_type, #set_meta, translate
Methods inherited from Core
#initialize, #inspect, #logger, logger, logger=, ui
Methods inherited from Config
#[], #[]=, array, #array, #clear, #defaults, #delete, ensure, #export, #filter, filter, #get, #get_array, #get_hash, #hash, hash, #import, init, #init, init_flat, #initialize, #set, #string, string, string_map, #string_map, #symbol, symbol, symbol_map, #symbol_map, test, #test
Methods included from Coral::Mixin::ConfigOptions
#clear_options, #contexts, #get_options, #set_options
Methods included from Coral::Mixin::ConfigCollection
#all_properties, #clear_properties, #delete_property, #get_property, #save_properties, #set_property
Methods included from Coral::Mixin::Lookup
#hiera, #hiera_config, #initialized?, #lookup, #lookup_array, #lookup_hash
Methods included from Coral::Mixin::ConfigOps
Constructor Details
This class inherits a constructor from Coral::Plugin::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Coral::Plugin::Base
Instance Method Details
#compute ⇒ Object
39 40 41 |
# File 'lib/coral/machine/fog.rb', line 39 def compute return get(:compute) end |
#create(options = {}) ⇒ Object
Management
120 121 122 123 124 125 126 |
# File 'lib/coral/machine/fog.rb', line 120 def create( = {}) success = super() if success && ! created? set(:server, compute.servers.bootstrap()) end return success end |
#create_image(name, options = {}) ⇒ Object
201 202 203 204 205 206 207 208 |
# File 'lib/coral/machine/fog.rb', line 201 def create_image(name, = {}) success = super() if success && created? image = server.create_image(name, ) return ( image ? image.id : false ) end return success end |
#created? ⇒ Boolean
Checks
19 20 21 |
# File 'lib/coral/machine/fog.rb', line 19 def created? return server && ! server.state != 'DELETED' end |
#destroy(options = {}) ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/coral/machine/fog.rb', line 179 def destroy( = {}) success = super() if success && created? return server.destroy() end return success end |
#exec(options = {}) ⇒ Object
189 190 191 192 193 194 195 196 197 |
# File 'lib/coral/machine/fog.rb', line 189 def exec( = {}) success = super() if success && running? if commands = .delete(:commands) return server.ssh(commands, ) end end return success end |
#flavor ⇒ Object
98 99 100 101 |
# File 'lib/coral/machine/fog.rb', line 98 def flavor return server.flavor if server return nil end |
#flavors ⇒ Object
91 92 93 94 |
# File 'lib/coral/machine/fog.rb', line 91 def flavors return compute.flavors if compute return nil end |
#hostname ⇒ Object
63 64 65 66 |
# File 'lib/coral/machine/fog.rb', line 63 def hostname return server.name if server return '' end |
#image ⇒ Object
112 113 114 115 |
# File 'lib/coral/machine/fog.rb', line 112 def image return server.image if server return nil end |
#images ⇒ Object
105 106 107 108 |
# File 'lib/coral/machine/fog.rb', line 105 def images return compute.images if compute return nil end |
#name ⇒ Object
51 52 53 |
# File 'lib/coral/machine/fog.rb', line 51 def name return ( server ? server.id : '' ) end |
#name=(id) ⇒ Object
57 58 59 |
# File 'lib/coral/machine/fog.rb', line 57 def name=id set(:server, compute.servers.get(id)) if id end |
#normalize ⇒ Object
Machine plugin interface
11 12 13 14 |
# File 'lib/coral/machine/fog.rb', line 11 def normalize super set_connection end |
#private_ip ⇒ Object
84 85 86 87 |
# File 'lib/coral/machine/fog.rb', line 84 def private_ip return server.private_ip_address if server return nil end |
#public_ip ⇒ Object
77 78 79 80 |
# File 'lib/coral/machine/fog.rb', line 77 def public_ip return server.public_ip_address if server return nil end |
#reload(options = {}) ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/coral/machine/fog.rb', line 168 def reload( = {}) success = super() if success && created? # Don't quite know what this should do yet?? return server.reboot() end return success end |
#running? ⇒ Boolean
25 26 27 |
# File 'lib/coral/machine/fog.rb', line 25 def running? return created? && server.ready? end |
#server ⇒ Object
45 46 47 |
# File 'lib/coral/machine/fog.rb', line 45 def server return get(:server) end |
#start(options = {}) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/coral/machine/fog.rb', line 130 def start( = {}) success = super() if success unless created? return create() end unless running? server_info = compute.servers.create() Fog.wait_for do compute.servers.get(server_info.id).ready? ? true : false end @server = compute.servers.get(server_info.id) end end return success end |
#state ⇒ Object
70 71 72 73 |
# File 'lib/coral/machine/fog.rb', line 70 def state return server.state if server return nil end |
#stop(options = {}) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/coral/machine/fog.rb', line 150 def stop( = {}) success = super() if success && running? if image_id = create_image(name) Fog.wait_for do compute.images.get(image_id).ready? ? true : false end server.destroy return image_id end end return success end |