Class: CORL::Plugin::Machine

Inherits:
Object
  • Object
show all
Defined in:
lib/core/plugin/machine.rb

Instance Method Summary collapse

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(options = {})
  success = true
  
  if created?
    logger.debug("Machine #{plugin_name} already exists")
  else
    logger.debug("Creating #{plugin_provider} machine with: #{options.inspect}")
    config  = Config.ensure(options)
    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(options = {})
  success = true
  
  if running?
    logger.debug("Creating image of #{plugin_provider} machine with: #{options.inspect}")
    config  = Config.ensure(options)      
    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

Returns:

  • (Boolean)


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(options = {})   
  success = true
  
  if created?
    logger.debug("Destroying #{plugin_provider} machine with: #{options.inspect}")
    config  = Config.ensure(options)
    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, options = {})
  success = true
  
  if running?
    logger.debug("Downloading #{local_path} from #{remote_path} on #{plugin_provider} machine with: #{options.inspect}")
    config  = Config.ensure(options)      
    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, options = {})
  results = []
  
  if running?
    logger.info("Executing commands ( #{commands.inspect} ) on machine #{plugin_name}")
    config  = Config.ensure(options)      
    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

#hostnameObject




44
45
46
# File 'lib/core/plugin/machine.rb', line 44

def hostname
  nil
end

#imageObject




80
81
82
# File 'lib/core/plugin/machine.rb', line 80

def image
  nil
end

#imagesObject




74
75
76
# File 'lib/core/plugin/machine.rb', line 74

def images
  []
end

#loadObject


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_typeObject




68
69
70
# File 'lib/core/plugin/machine.rb', line 68

def machine_type
  nil
end

#machine_typesObject




62
63
64
# File 'lib/core/plugin/machine.rb', line 62

def machine_types
  []
end

#nodeObject


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_ipObject




56
57
58
# File 'lib/core/plugin/machine.rb', line 56

def private_ip
  nil
end

#public_ipObject




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(options = {})
  success = true
  
  if created?
    logger.debug("Reloading #{plugin_provider} machine with: #{options.inspect}")
    config  = Config.ensure(options)
    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


Returns:

  • (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(options = {})
  success = true
  
  if running?
    logger.debug("Machine #{plugin_name} is already running")  
  else
    logger.debug("Starting #{plugin_provider} machine with: #{options.inspect}")
    
    logger.debug("Machine #{plugin_name} is not running yet")
    if block_given?
      success = yield(config)  
    else
      success = create(options)  
    end            
  end
  
  logger.warn("There was an error starting the machine #{plugin_name}") unless success
  success
end

#stateObject




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(options = {})
  success = true
  
  if running?
    logger.debug("Stopping #{plugin_provider} machine with: #{options.inspect}")
    config  = Config.ensure(options)      
    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, options = {})
  status = code.unknown_status
  
  if running?
    logger.debug("Launching #{user} terminal on #{plugin_provider} machine with: #{options.inspect}")
    config = Config.ensure(options)      
    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, options = {})
  success = true
  
  if running?
    logger.debug("Uploading #{local_path} to #{remote_path} on #{plugin_provider} machine with: #{options.inspect}")
    config  = Config.ensure(options)      
    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