Class: CORL::Plugin::Machine
- Inherits:
-
Object
- Object
- CORL::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
—.
-
#load ⇒ Object
—————————————————————————– Management.
-
#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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/core/plugin/machine.rb', line 99 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
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/core/plugin/machine.rb', line 200 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
15 16 17 |
# File 'lib/core/plugin/machine.rb', line 15 def created? false end |
#destroy(options = {}) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/core/plugin/machine.rb', line 256 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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/core/plugin/machine.rb', line 116 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
150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/core/plugin/machine.rb', line 150 def exec(commands, = {}) results = [] if running? logger.info("Executing commands ( #{commands.inspect} ) on machine #{plugin_name}") 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
44 45 46 |
# File 'lib/core/plugin/machine.rb', line 44 def hostname nil end |
#image ⇒ Object
80 81 82 |
# File 'lib/core/plugin/machine.rb', line 80 def image nil end |
#images ⇒ Object
74 75 76 |
# File 'lib/core/plugin/machine.rb', line 74 def images [] end |
#load ⇒ Object
Management
87 88 89 90 91 92 93 94 95 |
# File 'lib/core/plugin/machine.rb', line 87 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
68 69 70 |
# File 'lib/core/plugin/machine.rb', line 68 def machine_type nil end |
#machine_types ⇒ Object
62 63 64 |
# File 'lib/core/plugin/machine.rb', line 62 def machine_types [] end |
#node ⇒ Object
Property accessors / modifiers
28 29 30 |
# File 'lib/core/plugin/machine.rb', line 28 def node plugin_parent end |
#node=(node) ⇒ Object
32 33 34 |
# File 'lib/core/plugin/machine.rb', line 32 def node=node myself.plugin_parent = node end |
#normalize(reload) ⇒ Object
Machine plugin interface
9 10 |
# File 'lib/core/plugin/machine.rb', line 9 def normalize(reload) end |
#private_ip ⇒ Object
56 57 58 |
# File 'lib/core/plugin/machine.rb', line 56 def private_ip nil end |
#public_ip ⇒ Object
50 51 52 |
# File 'lib/core/plugin/machine.rb', line 50 def public_ip nil end |
#reload(options = {}) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/core/plugin/machine.rb', line 183 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
21 22 23 |
# File 'lib/core/plugin/machine.rb', line 21 def running? ( created? && false ) end |
#start(options = {}) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/core/plugin/machine.rb', line 234 def start( = {}) success = true if running? logger.debug("Machine #{plugin_name} is already running") else logger.debug("Starting #{plugin_provider} machine with: #{.inspect}") logger.debug("Machine #{plugin_name} is not running yet") if block_given? success = yield(config) else success = create() end end logger.warn("There was an error starting the machine #{plugin_name}") unless success success end |
#state ⇒ Object
38 39 40 |
# File 'lib/core/plugin/machine.rb', line 38 def state nil end |
#stop(options = {}) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/core/plugin/machine.rb', line 217 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
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/core/plugin/machine.rb', line 167 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
274 275 276 277 |
# File 'lib/core/plugin/machine.rb', line 274 def translate_state(state) return string(state).downcase.to_sym if status :unknown end |
#upload(local_path, remote_path, options = {}) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/core/plugin/machine.rb', line 133 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 |