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




93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/core/plugin/machine.rb', line 93

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




194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/core/plugin/machine.rb', line 194

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)


9
10
11
# File 'lib/core/plugin/machine.rb', line 9

def created?
  false
end

#destroy(options = {}) ⇒ Object




250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/core/plugin/machine.rb', line 250

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




110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/core/plugin/machine.rb', line 110

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




144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/core/plugin/machine.rb', line 144

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




38
39
40
# File 'lib/core/plugin/machine.rb', line 38

def hostname
  nil
end

#imageObject




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

def image
  nil
end

#imagesObject




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

def images
  []
end

#loadObject


Management



81
82
83
84
85
86
87
88
89
# File 'lib/core/plugin/machine.rb', line 81

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




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

def machine_type
  nil
end

#machine_typesObject




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

def machine_types
  []
end

#nodeObject


Property accessors / modifiers



22
23
24
# File 'lib/core/plugin/machine.rb', line 22

def node
  plugin_parent
end

#node=(node) ⇒ Object



26
27
28
# File 'lib/core/plugin/machine.rb', line 26

def node=node
  myself.plugin_parent = node
end

#private_ipObject




50
51
52
# File 'lib/core/plugin/machine.rb', line 50

def private_ip
  nil
end

#public_ipObject




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

def public_ip
  nil
end

#reload(options = {}) ⇒ Object




177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/core/plugin/machine.rb', line 177

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)


15
16
17
# File 'lib/core/plugin/machine.rb', line 15

def running?
  ( created? && false )
end

#start(options = {}) ⇒ Object




228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/core/plugin/machine.rb', line 228

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




32
33
34
# File 'lib/core/plugin/machine.rb', line 32

def state
  nil
end

#stop(options = {}) ⇒ Object




211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/core/plugin/machine.rb', line 211

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




161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/core/plugin/machine.rb', line 161

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



268
269
270
271
# File 'lib/core/plugin/machine.rb', line 268

def translate_state(state)
  return string(state).downcase.to_sym if status
  :unknown
end

#upload(local_path, remote_path, options = {}) ⇒ Object




127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/core/plugin/machine.rb', line 127

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