Class: Skytap::Commands::VmExportJob

Inherits:
Object
  • Object
show all
Defined in:
lib/skytap/plugins/vm_download.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, username, api_token, vm_id, dir = nil) ⇒ VmExportJob

Returns a new instance of VmExportJob.



176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/skytap/plugins/vm_download.rb', line 176

def initialize(logger, username, api_token, vm_id, dir=nil)
  @logger = logger
  @username = username
  @api_token = api_token
  @vm_id = vm_id

  @vm = Skytap.invoke!(username, api_token, "vm show #{vm_id}")
  @export_dir = File.join(File.expand_path(dir || '.'), "vm_#{vm_id}")
  FileUtils.mkdir_p(export_dir)

  create_on_server
end

Instance Attribute Details

#api_tokenObject (readonly)

Returns the value of attribute api_token.



174
175
176
# File 'lib/skytap/plugins/vm_download.rb', line 174

def api_token
  @api_token
end

#export_dirObject (readonly)

Returns the value of attribute export_dir.



174
175
176
# File 'lib/skytap/plugins/vm_download.rb', line 174

def export_dir
  @export_dir
end

#loggerObject (readonly)

Returns the value of attribute logger.



174
175
176
# File 'lib/skytap/plugins/vm_download.rb', line 174

def logger
  @logger
end

#usernameObject (readonly)

Returns the value of attribute username.



174
175
176
# File 'lib/skytap/plugins/vm_download.rb', line 174

def username
  @username
end

#vmObject (readonly)

Returns the value of attribute vm.



174
175
176
# File 'lib/skytap/plugins/vm_download.rb', line 174

def vm
  @vm
end

#vm_idObject (readonly)

Returns the value of attribute vm_id.



174
175
176
# File 'lib/skytap/plugins/vm_download.rb', line 174

def vm_id
  @vm_id
end

Instance Method Details

#at_capacity?(exception) ⇒ Boolean

Returns:

  • (Boolean)


201
202
203
# File 'lib/skytap/plugins/vm_download.rb', line 201

def at_capacity?(exception)
  exception.message.include?('You cannot export a VM because you may not have more than')
end

#create_on_serverObject



189
190
191
192
193
194
195
196
197
198
199
# File 'lib/skytap/plugins/vm_download.rb', line 189

def create_on_server
  begin
    export
  rescue Exception => ex
    if at_capacity?(ex)
      raise NoSlotsAvailable.new
    else
      raise
    end
  end
end

#export(force_reload = false) ⇒ Object



205
206
207
208
209
210
211
212
213
214
# File 'lib/skytap/plugins/vm_download.rb', line 205

def export(force_reload=false)
  return @export unless @export.nil? || force_reload

  if @export
    id = @export['id']
    @export = Skytap.invoke!(username, api_token, "export show #{id}")
  else
    @export = Skytap.invoke!(username, api_token, "export create", {}, :param => {'vm_id' => vm_id})
  end
end