Class: Nucleon::Plugin::Machine
- Inherits:
-
Object
- Object
- Nucleon::Plugin::Machine
- Defined in:
- lib/core/plugin/machine.rb
Instance Method Summary collapse
-
#create(options = {}) ⇒ Object
—.
-
#create_image(options = {}) ⇒ Object
—.
-
#created? ⇒ Boolean
—————————————————————————– Checks.
-
#destroy(options = {}) ⇒ Object
—.
-
#download(remote_path, local_path, options = {}) ⇒ Object
—.
-
#exec(commands, options = {}) ⇒ Object
—.
-
#hostname ⇒ Object
—.
-
#image ⇒ Object
—.
-
#images ⇒ Object
—.
-
#init_ssh(ssh_port) ⇒ Object
—————————————————————————– Management.
-
#load ⇒ Object
—.
-
#machine_type ⇒ Object
—.
-
#machine_types ⇒ Object
—.
-
#node ⇒ Object
—————————————————————————– Property accessors / modifiers.
- #node=(node) ⇒ Object
-
#normalize(reload) ⇒ Object
—————————————————————————– Machine plugin interface.
-
#private_ip ⇒ Object
—.
-
#public_ip ⇒ Object
—.
-
#reload(options = {}) ⇒ Object
—.
-
#running? ⇒ Boolean
—.
-
#start(options = {}) ⇒ Object
—.
-
#state ⇒ Object
—.
-
#stop(options = {}) ⇒ Object
—.
-
#terminal(user, options = {}) ⇒ Object
—.
-
#translate_state(state) ⇒ Object
—————————————————————————– Utilities.
-
#upload(local_path, remote_path, options = {}) ⇒ Object
—.
Instance Method Details
#create(options = {}) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/core/plugin/machine.rb', line 106 def create( = {}) success = true if created? logger.debug("Machine #{plugin_name} already exists") else logger.debug("Creating #{plugin_provider} machine with: #{.inspect}") config = Config.ensure() success = yield(config) if block_given? end logger.warn("There was an error creating the machine #{plugin_name}") unless success success end |
#create_image(options = {}) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/core/plugin/machine.rb', line 207 def create_image( = {}) success = true if running? logger.debug("Creating image of #{plugin_provider} machine with: #{.inspect}") config = Config.ensure() success = yield(config) if block_given? else logger.debug("Machine #{plugin_name} is not running") end logger.warn("There was an error creating an image of the machine #{plugin_name}") unless success success end |
#created? ⇒ Boolean
Checks
16 17 18 |
# File 'lib/core/plugin/machine.rb', line 16 def created? false end |
#destroy(options = {}) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/core/plugin/machine.rb', line 263 def destroy( = {}) success = true if created? logger.debug("Destroying #{plugin_provider} machine with: #{.inspect}") config = Config.ensure() success = yield(config) if block_given? else logger.debug("Machine #{plugin_name} does not yet exist") end logger.warn("There was an error destroying the machine #{plugin_name}") unless success success end |
#download(remote_path, local_path, options = {}) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/core/plugin/machine.rb', line 123 def download(remote_path, local_path, = {}) success = true if running? logger.debug("Downloading #{local_path} from #{remote_path} on #{plugin_provider} machine with: #{.inspect}") config = Config.ensure() success = yield(config, success) if block_given? else logger.debug("Machine #{plugin_name} is not running") end logger.warn("There was an error downloading from the machine #{plugin_name}") unless success success end |
#exec(commands, options = {}) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/core/plugin/machine.rb', line 157 def exec(commands, = {}) results = [] if running? logger.debug("Executing command on #{plugin_provider} machine with: #{.inspect}") config = Config.ensure() results = yield(config, results) if block_given? else logger.debug("Machine #{plugin_name} is not running") end logger.warn("There was an error executing command on the machine #{plugin_name}") unless results results end |
#hostname ⇒ Object
45 46 47 |
# File 'lib/core/plugin/machine.rb', line 45 def hostname nil end |
#image ⇒ Object
81 82 83 |
# File 'lib/core/plugin/machine.rb', line 81 def image nil end |
#images ⇒ Object
75 76 77 |
# File 'lib/core/plugin/machine.rb', line 75 def images [] end |
#init_ssh(ssh_port) ⇒ Object
Management
88 89 90 |
# File 'lib/core/plugin/machine.rb', line 88 def init_ssh(ssh_port) # Implement in sub classes if needed end |
#load ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/core/plugin/machine.rb', line 94 def load success = true logger.debug("Loading #{plugin_provider} machine: #{plugin_name}") success = yield if block_given? logger.warn("There was an error loading the machine #{plugin_name}") unless success success end |
#machine_type ⇒ Object
69 70 71 |
# File 'lib/core/plugin/machine.rb', line 69 def machine_type nil end |
#machine_types ⇒ Object
63 64 65 |
# File 'lib/core/plugin/machine.rb', line 63 def machine_types [] end |
#node ⇒ Object
Property accessors / modifiers
29 30 31 |
# File 'lib/core/plugin/machine.rb', line 29 def node plugin_parent end |
#node=(node) ⇒ Object
33 34 35 |
# File 'lib/core/plugin/machine.rb', line 33 def node=node myself.plugin_parent = node end |
#normalize(reload) ⇒ Object
Machine plugin interface
9 10 11 |
# File 'lib/core/plugin/machine.rb', line 9 def normalize(reload) myself.plugin_name = node[:id] end |
#private_ip ⇒ Object
57 58 59 |
# File 'lib/core/plugin/machine.rb', line 57 def private_ip nil end |
#public_ip ⇒ Object
51 52 53 |
# File 'lib/core/plugin/machine.rb', line 51 def public_ip nil end |
#reload(options = {}) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/core/plugin/machine.rb', line 190 def reload( = {}) success = true if created? logger.debug("Reloading #{plugin_provider} machine with: #{.inspect}") config = Config.ensure() success = yield(config) if block_given? else logger.debug("Machine #{plugin_name} does not yet exist") end logger.warn("There was an error reloading the machine #{plugin_name}") unless success success end |
#running? ⇒ Boolean
22 23 24 |
# File 'lib/core/plugin/machine.rb', line 22 def running? ( created? && false ) end |
#start(options = {}) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/core/plugin/machine.rb', line 241 def start( = {}) success = true if running? logger.debug("Machine #{plugin_name} is already running") else logger.debug("Starting #{plugin_provider} machine with: #{.inspect}") if created? logger.debug("Machine #{plugin_name} has already been created") else logger.debug("Machine #{plugin_name} does not yet exist") success = create() end end logger.warn("There was an error starting the machine #{plugin_name}") unless success success end |
#state ⇒ Object
39 40 41 |
# File 'lib/core/plugin/machine.rb', line 39 def state nil end |
#stop(options = {}) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/core/plugin/machine.rb', line 224 def stop( = {}) success = true if running? logger.debug("Stopping #{plugin_provider} machine with: #{.inspect}") config = Config.ensure() success = yield(config) if block_given? else logger.debug("Machine #{plugin_name} is not running") end logger.warn("There was an error stopping the machine #{plugin_name}") unless success success end |
#terminal(user, options = {}) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/core/plugin/machine.rb', line 174 def terminal(user, = {}) status = code.unknown_status if running? logger.debug("Launching #{user} terminal on #{plugin_provider} machine with: #{.inspect}") config = Config.ensure() status = yield(config) if block_given? else logger.debug("Machine #{plugin_name} is not running") end logger.warn("There was an error launching a #{user} terminal on the machine #{plugin_name}") unless status == code.success status end |
#translate_state(state) ⇒ Object
Utilities
281 282 283 284 |
# File 'lib/core/plugin/machine.rb', line 281 def translate_state(state) return string(state).downcase.to_sym if status :unknown end |
#upload(local_path, remote_path, options = {}) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/core/plugin/machine.rb', line 140 def upload(local_path, remote_path, = {}) success = true if running? logger.debug("Uploading #{local_path} to #{remote_path} on #{plugin_provider} machine with: #{.inspect}") config = Config.ensure() success = yield(config, success) if block_given? else logger.debug("Machine #{plugin_name} is not running") end logger.warn("There was an error uploading to the machine #{plugin_name}") unless success success end |