Method: Beaker::Vcloud#provision

Defined in:
lib/beaker/hypervisor/vcloud.rb

#provisionObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/beaker/hypervisor/vcloud.rb', line 95

def provision
  connect_to_vsphere
  begin
    vsphere_vms = {}

    try = 1
    attempts = @options[:timeout].to_i / 5

    start = Time.now
    tasks = []
    @hosts.each_with_index do |h, i|
      if h['name']
        h['vmhostname'] = h['name']
      else
        h['vmhostname'] = generate_host_name
      end

      if h['template'] =~ /\//
        templatefolders = h['template'].split('/')
        h['template'] = templatefolders.pop
      end

      @logger.notify "Deploying #{h['vmhostname']} (#{h.name}) to #{@options['folder']} from template '#{h['template']}'"

      vm = {}

      if templatefolders
        vm[h['template']] = @vsphere_helper.find_folder(templatefolders.join('/')).find(h['template'])
      else
        vm = @vsphere_helper.find_vms(h['template'])
      end

      if vm.length == 0
        raise "Unable to find template '#{h['template']}'!"
      end

      spec = create_clone_spec(h)

      # Deploy from specified template
      tasks << vm[h['template']].CloneVM_Task( :folder => @vsphere_helper.find_folder(@options['folder']), :name => h['vmhostname'], :spec => spec )
    end
    try = (Time.now - start) / 5
    @vsphere_helper.wait_for_tasks(tasks, try, attempts)
    @logger.notify 'Spent %.2f seconds deploying VMs' % (Time.now - start)

    try = (Time.now - start) / 5
    duration = run_and_report_duration do
      @hosts.each_with_index do |h, i|
        booting_host(h, try, attempts)
      end
    end
    @logger.notify "Spent %.2f seconds booting and waiting for vSphere registration" % duration

    try = (Time.now - start) / 5
    duration = run_and_report_duration do
      @hosts.each_with_index do |h, i|
        wait_for_dns_resolution(h, try, attempts)
      end
    end
    @logger.notify "Spent %.2f seconds waiting for DNS resolution" % duration
  rescue => e
    @vsphere_helper.close
    report_and_raise(@logger, e, "Vcloud.provision")
  end
end