Class: Nucleon::Plugin::Machine

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

Instance Method Summary collapse

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(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




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(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)


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(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




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, 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




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, options = {})
  results = []
  
  if running?
    logger.debug("Executing command on #{plugin_provider} machine with: #{options.inspect}")
    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




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

def hostname
  nil
end

#imageObject




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

def image
  nil
end

#imagesObject




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

#loadObject




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_typeObject




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

def machine_type
  nil
end

#machine_typesObject




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

def machine_types
  []
end

#nodeObject


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_ipObject




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

def private_ip
  nil
end

#public_ipObject




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(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)


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

#stateObject




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(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




174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/core/plugin/machine.rb', line 174

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



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, 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