Class: Skytap::Commands::ExportableVm

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

Constant Summary collapse

DEFAULT_IP =
'10.0.0.1'
DEFAULT_HOSTNAME =
'host-1'
DEFAULT_SUBNET =
'10.0.0.0/24'
DEFAULT_DOMAIN =
'test.net'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(vm, template) ⇒ ExportableVm

Returns a new instance of ExportableVm.



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/skytap/plugins/vm_download.rb', line 368

def initialize(vm, template)
  @vm = vm
  @template = template

  @name = vm['name']
  @description = template['description'].present? ? template['description'] : @name

  if iface = vm['interfaces'][0]
    case iface['network_type']
    when 'automatic'
      @ip = iface['ip']
      @hostname = iface['hostname']

      network = template['networks'].detect {|net| net['id'] == iface['network_id']}
      raise Skytap::Error.new('Network for VM interface not found') unless network
      @subnet = network['subnet']
      @domain = network['domain']
    when 'manual'
      @manual_network = true

      network = template['networks'].detect {|net| net['id'] == iface['network_id']}
      raise Skytap::Error.new('Network for VM interface not found') unless network

      @subnet = network['subnet']
      @domain = DEFAULT_DOMAIN

      @ip = Subnet.new(@subnet).min_machine_ip.to_s
      @hostname = DEFAULT_HOSTNAME
    else # not connected
      @ip = DEFAULT_IP
      @hostname = iface['hostname'] || DEFAULT_HOSTNAME
      @subnet = DEFAULT_SUBNET
      @domain = DEFAULT_DOMAIN
    end
  else
    # Choose default everything for VM hostname, address and network subnet and domain
    @ip = DEFAULT_IP
    @hostname = DEFAULT_HOSTNAME
    @domain = DEFAULT_DOMAIN
    @subnet = DEFAULT_SUBNET
  end
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



366
367
368
# File 'lib/skytap/plugins/vm_download.rb', line 366

def credentials
  @credentials
end

#descriptionObject (readonly)

Returns the value of attribute description.



366
367
368
# File 'lib/skytap/plugins/vm_download.rb', line 366

def description
  @description
end

#domainObject (readonly)

Returns the value of attribute domain.



366
367
368
# File 'lib/skytap/plugins/vm_download.rb', line 366

def domain
  @domain
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



366
367
368
# File 'lib/skytap/plugins/vm_download.rb', line 366

def hostname
  @hostname
end

#ipObject (readonly)

Returns the value of attribute ip.



366
367
368
# File 'lib/skytap/plugins/vm_download.rb', line 366

def ip
  @ip
end

#nameObject (readonly)

Returns the value of attribute name.



366
367
368
# File 'lib/skytap/plugins/vm_download.rb', line 366

def name
  @name
end

#subnetObject (readonly)

Returns the value of attribute subnet.



366
367
368
# File 'lib/skytap/plugins/vm_download.rb', line 366

def subnet
  @subnet
end

#templateObject (readonly)

Returns the value of attribute template.



365
366
367
# File 'lib/skytap/plugins/vm_download.rb', line 365

def template
  @template
end

#vmObject (readonly)

Returns the value of attribute vm.



365
366
367
# File 'lib/skytap/plugins/vm_download.rb', line 365

def vm
  @vm
end

Instance Method Details

#dataObject



411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/skytap/plugins/vm_download.rb', line 411

def data
  @data ||= {
    'template_name' => @name,
    'template_description' => @description,
    'network_domain' => @domain,
    'network_subnet' => @subnet,
    'interface_ip' => @ip,
    'interface_hostname' => @hostname,
  }.tap do |d|
    if creds = vm['credentials'].try(:collect){|c| c['text']}
      d['credentials'] = creds
    end
  end
end

#manual_network?Boolean

Returns:

  • (Boolean)


426
427
428
# File 'lib/skytap/plugins/vm_download.rb', line 426

def manual_network?
  @manual_network
end