Revision 933f4a61

View differences:

share/hooks/image.rb
28 28

  
29 29
$: << RUBY_LIB_LOCATION
30 30

  
31
require 'fileutils'
32

  
33 31
require 'OpenNebula'
34 32
include OpenNebula
35 33

  
......
44 42
                client)
45 43
vm.info
46 44

  
47
if vm['TEMPLATE/DISK']
48
    vm.each('TEMPLATE/DISK') do |disk| 
49
        
50
        disk_id     = disk["DISK_ID"]
51
        source_path = VMDIR+"/#{vm_id}/disk.#{disk_id}"
52
        
53
        image_id = nil
54
        if disk["SAVE_AS"] 
55
            image_id = disk["SAVE_AS"]
56
        end
57
        
58
        if image_id and source_path
59
            image=Image.new(
60
                    Image.build_xml(image_id), 
61
                    client)
62
                    
63
            result = image.info
64
            exit -1 if !is_successful?(result) 
65
            
66
            # Disable the Image for a safe overwriting
67
            image.disable 
68
        
69
            # Save the image file
70
            result = image.move(source_path, image['SOURCE']) 
71
            exit -1 if !is_successful?(result) 
45
vm.each('TEMPLATE/DISK') do |disk| 
46
    disk_id     = disk["DISK_ID"]
47
    source_path = VMDIR+"/#{vm_id}/disk.#{disk_id}"
48
    
49
    image_id = nil
50
    if disk["SAVE_AS"] 
51
        image_id = disk["SAVE_AS"]
52
    end
53
    
54
    if image_id and source_path
55
        image=Image.new(
56
                Image.build_xml(image_id), 
57
                client)
58
                
59
        result = image.info
60
        exit -1 if !is_successful?(result) 
72 61
        
73
            image.enable
74
        end
62
        # Disable the Image for a safe overwriting
63
        image.disable 
64
    
65
        # Save the image file
66
        result = image.move(source_path, image['SOURCE']) 
67
        exit -1 if !is_successful?(result) 
68
    
69
        image.enable
75 70
    end
76
end
71
end
src/cli/onevm
717 717
    
718 718
    # Build the template and allocate the new Image
719 719
    template = "NAME=#{image_name}\n"
720
    template << "TYPE=#{image_type}\n" if type
720
    template << "TYPE=#{image_type}\n" if image_type
721 721

  
722 722
    
723 723
    image = OpenNebula::Image.new(
......
731 731
        exit -1
732 732
    end
733 733
    
734
    result = vm.save_disk(disk_id.to_i, image.id)
734
    result = vm.save_as(disk_id.to_i, image.id)
735 735

  
736 736
when "save"
737 737
    check_parameters("save", 2)
......
751 751
    
752 752
    image_id = vm["TEMPLATE/DISK[DISK_ID=\"#{disk_id}\"]/IMAGE_ID"]
753 753
    
754
    result = vm.save_disk(disk_id.to_i, image_id)
754
    result = vm.save_as(disk_id.to_i, image_id)
755 755
    
756 756
when "show"
757 757
    check_parameters("get_info", 1)
src/oca/ruby/OpenNebula/Image.rb
192 192

  
193 193
            begin
194 194
                FileUtils.copy(path, source)
195
                FileUtils.chmod(0660, source)
195 196
            rescue Exception => e
196 197
                return OpenNebula::Error.new(e.message)
197 198
            end
src/oca/ruby/OpenNebula/ImagePool.rb
16 16
        
17 17
        # +client+ a Client object that represents a XML-RPC connection
18 18
        # +user_id+ is to refer to a Pool with Images from that user
19
        def initialize(client, user_id=0)
19
        def initialize(client, user_id=-1)
20 20
            super('IMAGE_POOL','IMAGE',client)
21 21

  
22 22
            @user_id  = user_id

Also available in: Unified diff