Revision 781a9928 src/vmm_mad/remotes/vcenter/vcenter_driver.rb

View differences:

src/vmm_mad/remotes/vcenter/vcenter_driver.rb
823 823
    end
824 824

  
825 825
    def self.find_ds_name(ds_id)
826
        ds = OpenNebula::Datastore.new_with_id(ds_id)
826
        ds = OpenNebula::Datastore.new_with_id(ds_id, OpenNebula::Client.new)
827 827
        rc = ds.info
828 828
        raise "Could not find datastore #{ds_id}" if OpenNebula.is_error?(rc)
829 829

  
......
1524 1524
            reconfigure_vm(vm, xml, false, hostname)
1525 1525

  
1526 1526
            vm.PowerOnVM_Task.wait_for_completion
1527

  
1527 1528
            return vm.config.uuid
1528 1529
        end
1529 1530
    end
......
1537 1538
    #  @param disks VM attached disks
1538 1539
    ############################################################################
1539 1540
    def self.cancel(deploy_id, hostname, lcm_state, keep_disks, disks, to_template)
1541

  
1540 1542
        case lcm_state
1541 1543
            when "SHUTDOWN_POWEROFF", "SHUTDOWN_UNDEPLOY"
1542 1544
                shutdown(deploy_id, hostname, lcm_state, keep_disks, disks, to_template)
1543 1545
            when "CANCEL", "LCM_INIT", "CLEANUP_RESUBMIT", "SHUTDOWN", "CLEANUP_DELETE"
1544 1546
                hid         = VIClient::translate_hostname(hostname)
1545 1547
                connection  = VIClient.new(hid)
1546
                vm          = connection.find_vm_template(deploy_id)
1548

  
1549
                vm = connection.find_vm_template(deploy_id)
1547 1550

  
1548 1551
                begin
1549 1552
                    if vm.summary.runtime.powerState == "poweredOn"
......
1551 1554
                    end
1552 1555
                rescue
1553 1556
                end
1557

  
1554 1558
                if keep_disks
1555 1559
                    detach_all_disks(vm)
1556 1560
                else
......
1661 1665
        hid         = VIClient::translate_hostname(hostname)
1662 1666
        connection  = VIClient.new(hid)
1663 1667

  
1664
        vm          = connection.find_vm_template(deploy_id)
1668
        vm   = connection.find_vm_template(deploy_id)
1669
        vmid = get_vm_id
1665 1670

  
1666 1671
        case lcm_state
1667 1672
            when "SHUTDOWN"
......
2628 2633

  
2629 2634
        end
2630 2635

  
2631

  
2632

  
2633 2636
        reconfigure_vm(vm, xml, true, hostname)
2634 2637

  
2635 2638
        # Power on the VM
......
2860 2863
            hid         = VIClient::translate_hostname(hostname)
2861 2864
            connection  = VIClient.new(hid)
2862 2865
            disks.each{|disk|
2863
               ds_name    = disk.elements["DATASTORE"].text
2864
               img_name   = disk.elements["SOURCE"].text
2865
               type_str   = disk.elements["TYPE"].text
2866
                ds_name    = disk.elements["DATASTORE"].text
2867
                img_name   = get_disk_img_path(disk, vmid)
2868
                type_str   = disk.elements["TYPE"].text
2866 2869

  
2867
               disk_array += attach_disk("", "", ds_name, img_name, type_str, 0, vm, connection)[:deviceChange]
2870
                disk_array += attach_disk("", "", ds_name, img_name, type_str, 0, vm, connection)[:deviceChange]
2868 2871
            }
2869 2872

  
2870 2873
            device_change += disk_array
......
2888 2891
        end
2889 2892

  
2890 2893
        spec      = RbVmomi::VIM.VirtualMachineConfigSpec(spec_hash)
2894

  
2891 2895
        vm.ReconfigVM_Task(:spec => spec).wait_for_completion
2892 2896
    end
2893 2897

  
......
2924 2928
            end
2925 2929
        }
2926 2930

  
2927
        ds         = datastores.select{|ds| ds.name == ds_name}[0]
2931
        ds = datastores.select{|ds| ds.name == ds_name}[0]
2928 2932

  
2929 2933
        controller, new_number = find_free_controller(vm)
2930 2934

  
......
3165 3169
        hid         = VIClient::translate_hostname(hostname)
3166 3170
        connection  = VIClient.new(hid)
3167 3171

  
3172
        vmid =  vm.config.extraConfig.select do |val|
3173
                    val[:key] == "opennebula.vm.id"
3174
                end.first.value
3175

  
3168 3176
        spec = { :deviceChange => [] }
3169 3177

  
3170 3178
        disks.each{ |disk|
3171
          ds_and_img_name = "[#{disk['DATASTORE']}] #{disk['SOURCE']}"
3172
          vcenter_disk = vm.config.hardware.device.select { |d| is_disk?(d) &&
3179
            img_name = get_disk_img_path(disk, vmid)
3180
            ds_and_img_name = "[#{disk['DATASTORE']}] #{img_name}"
3181

  
3182
            vcenter_disk = vm.config.hardware.device.select { |d| is_disk?(d) &&
3173 3183
                                    d.backing.respond_to?(:fileName) &&
3174 3184
                                    d.backing.fileName == ds_and_img_name }[0]
3175
           spec[:deviceChange] <<  {
3185
            spec[:deviceChange] <<  {
3176 3186
                :operation => :remove,
3177 3187
                :device => vcenter_disk
3178 3188
            }
......
3180 3190

  
3181 3191
        vm.ReconfigVM_Task(:spec => spec).wait_for_completion
3182 3192
    end
3193

  
3194

  
3195
    ############################################################################
3196
    # Returns the source path of a disk. It will use the 'SOURCE' path if
3197
    # persistent and one-#{vm_id}-#{disk_id}.vmdk otherwise
3198
    # @param disks VM attached disks, either an REXML document, or a hash
3199
    # @param vmid The VM ID
3200
    ############################################################################
3201
    def self.get_disk_img_path(disk, vmid)
3202
        if disk.respond_to? :elements
3203
            # It's a REXML::Document, probably coming from self.reconfigure_vm
3204
            persistent = disk.elements["PERSISTENT"].text == "YES" rescue false
3205

  
3206
            if persistent
3207
                disk.elements["SOURCE"].text
3208
            else
3209
                disk_id = disk.elements["DISK_ID"].text
3210
                "one_#{vmid}_#{disk_id}.vmdk"
3211
            end
3212
        else
3213
            # It's a hash, probably coming from self.detach_attached_disks
3214
            persistent = disk["PERSISTENT"] == "YES"
3215

  
3216
            if persistent
3217
                disk["SOURCE"]
3218
            else
3219
                disk_id = disk["DISK_ID"]
3220
                "one_#{vmid}_#{disk_id}.vmdk"
3221
            end
3222
        end
3223
    end
3224

  
3183 3225
end
3184 3226
end

Also available in: Unified diff