Class: Vcloud::CLI::Utils::MakeVappTemplate

Inherits:
Object
  • Object
show all
Includes:
Methadone::CLILogging, Methadone::Main
Defined in:
lib/vcloud/cli/utils/make_vapp_template.rb

Class Method Summary collapse

Class Method Details

.runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/vcloud/cli/utils/make_vapp_template.rb', line 13

def self.run

  main do |vdc_name, blank_vapp_template_id, iso_id, template_name|

    vcloud = ::Fog::Compute::VcloudDirector.new
    Fog.mock! if ENV['FOG_MOCK']

    vdc = Vcloud::Core::Vdc.get_by_name(vdc_name)

    # Instantiate a 'blank vApp':
    #  * contains one VM
    #  * this VM has a single HDD
    #  * the VM HDD is blank
    puts "Instantiating blank vApp/VM"
    vapp = Vcloud::Core::Vapp.instantiate(
      'make_vapp_template_temp_vapp',
      ['VappCreationTesting'],
      blank_vapp_template_id,
      vdc_name,
    )

    child_vm_id = vapp.fog_vms.first[:href].split('/').last
    vm = Vcloud::Core::Vm.new(child_vm_id, vapp)
    puts "Found child VM id: #{vm.id}"

    # Add our ISO to the VM inside the vApp
    puts "Inserting ISO into VM"
    task = vcloud.post_insert_cd_rom(vm.id, iso_id).body
    vcloud.process_task(task)

    puts "Powering on vApp to install OS"
    vapp.power_on

    # vapp will now boot. VM will be shut down at the end
    puts "Waiting for OS to install"
    while vapp.vcloud_attributes[:status].to_i == 4
      # vapp is in RUNNING state, so OS is still installing
      printf('.')
      sleep(5)
    end
    puts ""

    puts "Removing ISO from VM"
    task = vcloud.post_eject_cd_rom(vm.id, iso_id).body
    vcloud.process_task(task)

    puts "Stopping vApp completely"
    task = vcloud.post_undeploy_vapp(vapp.id).body
    vcloud.process_task(task)

    puts "Turn the newly provisioned vApp into a vAppTemplate (in vDC #{vdc_name})"
    capture_body = vcloud.post_capture_vapp(vdc.id, template_name, vapp.id).body
    #vcloud.process_task(task)
    pp capture_body

  end

  arg :vdc_id
  arg :empty_vapp_template_id
  arg :iso_name
  arg :template_name

  description "
  "

  go!

end