Class: Skytap::Commands::VmImportJob
- Inherits:
-
Object
- Object
- Skytap::Commands::VmImportJob
- Defined in:
- lib/skytap/plugins/vm_upload.rb
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#import_path ⇒ Object
readonly
Returns the value of attribute import_path.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#other_credentials ⇒ Object
readonly
Returns the value of attribute other_credentials.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
-
#vm ⇒ Object
readonly
Returns the value of attribute vm.
Instance Method Summary collapse
- #at_capacity?(exception) ⇒ Boolean
- #create_on_server ⇒ Object
- #import(force_reload = false) ⇒ Object
-
#initialize(logger, username, api_token, vm, params = {}) ⇒ VmImportJob
constructor
A new instance of VmImportJob.
- #setup ⇒ Object
Constructor Details
#initialize(logger, username, api_token, vm, params = {}) ⇒ VmImportJob
Returns a new instance of VmImportJob.
188 189 190 191 192 193 194 195 196 197 |
# File 'lib/skytap/plugins/vm_upload.rb', line 188 def initialize(logger, username, api_token, vm, params = {}) @logger = logger @username = username @api_token = api_token @vm = File.(vm) @params = params @vm_filename = File.basename(@vm) create_on_server end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
186 187 188 |
# File 'lib/skytap/plugins/vm_upload.rb', line 186 def api_token @api_token end |
#import_path ⇒ Object (readonly)
Returns the value of attribute import_path.
186 187 188 |
# File 'lib/skytap/plugins/vm_upload.rb', line 186 def import_path @import_path end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
186 187 188 |
# File 'lib/skytap/plugins/vm_upload.rb', line 186 def logger @logger end |
#other_credentials ⇒ Object (readonly)
Returns the value of attribute other_credentials.
186 187 188 |
# File 'lib/skytap/plugins/vm_upload.rb', line 186 def other_credentials @other_credentials end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
186 187 188 |
# File 'lib/skytap/plugins/vm_upload.rb', line 186 def params @params end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
186 187 188 |
# File 'lib/skytap/plugins/vm_upload.rb', line 186 def username @username end |
#vm ⇒ Object (readonly)
Returns the value of attribute vm.
186 187 188 |
# File 'lib/skytap/plugins/vm_upload.rb', line 186 def vm @vm end |
Instance Method Details
#at_capacity?(exception) ⇒ Boolean
212 213 214 |
# File 'lib/skytap/plugins/vm_upload.rb', line 212 def at_capacity?(exception) exception..include?('You cannot import a VM because you may not have more than') end |
#create_on_server ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/skytap/plugins/vm_upload.rb', line 199 def create_on_server setup begin import rescue Exception => ex if at_capacity?(ex) raise NoSlotsAvailable.new else raise end end end |
#import(force_reload = false) ⇒ Object
243 244 245 246 247 248 249 250 251 252 |
# File 'lib/skytap/plugins/vm_upload.rb', line 243 def import(force_reload=false) return @import unless @import.nil? || force_reload if @import id = @import['id'] @import = Skytap.invoke!(username, api_token, "import show #{id}") else @import = Skytap.invoke!(username, api_token, 'import create', {}, :param => params) end end |
#setup ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/skytap/plugins/vm_upload.rb', line 216 def setup if File.directory?(vm) @import_path = File.join(vm, 'vm.7z') unless File.exist?(@import_path) raise Skytap::Error.new("Directory provided (#{vm}) but no vm.7z file found inside") end = File.join(vm, 'vm.yaml') if File.exist?() #TODO:NLA If hostname is present, truncate it to 15 chars. This is the max import hostname length. extra_params = YAML.load_file() end elsif File.exist?(vm) @import_path = vm else raise Skytap::Error.new("File does not exist: #{vm}") end @params = (extra_params || {}).merge(params) if @params['credentials'].is_a?(Array) cred = @params['credentials'].shift @other_credentials = @params['credentials'] @params['credentials'] = cred end end |