Revision c20cef82

View differences:

share/hooks/image.rb
30 30

  
31 31
require 'OpenNebula'
32 32
require 'client_utilities'
33
require 'ftools'
33
require 'fileutils'
34 34

  
35 35
TYPES=%w{OS CDROM DATABLOCK}
36 36

  
......
40 40

  
41 41
vm=OpenNebula::VirtualMachine.new_with_id(vm_id, get_one_client)
42 42
vm.info
43
template=vm.to_hash
44
template=template['VM']['TEMPLATE']
45
disks=[template['DISK']].flatten if template['DISK']
46
disks.each_with_index do |disk,i|
47
    source_path=VMDIR+"/#{vm_id}/disk.#{i}"
48
    if disk["NAME"] and File.exists?(source_path)
49
        if disk["SAVE_AS"] 
50
            # Get Type
51
            image=OpenNebula::Image.new_with_id(disk['IID'], get_one_client)
52
            image.info
53
            type=image['TYPE']
54
            # Perform the allocate if all goes well
55
            image=OpenNebula::Image.new(
56
                OpenNebula::Image.build_xml, get_one_client)
43
template=vm['VM/TEMPLATE']
44
if template['DISK']
45
    i = 0
46
    template.each('DISK') do |disk| 
47
        source_path=VMDIR+"/#{vm_id}/disk.#{i}"
48
        if disk["NAME"] and File.exists?(source_path)
49
            if disk["SAVE_AS"] 
50
                # Get Type
51
                image=OpenNebula::Image.new_with_id(disk['IMAGE_ID'], get_one_client)
52
                image.info
53
                type=image['TYPE']
54
                # Perform the allocate if all goes well
55
                image=OpenNebula::Image.new(
56
                    OpenNebula::Image.build_xml, get_one_client)
57 57
            
58
            template="NAME=#{disk['SAVE_AS']}\n"
59
            template+="TYPE=#{TYPES[type.to_i]}\n" if type
60
            result=image.allocate(template)
58
                template="NAME=#{disk['SAVE_AS']}\n"
59
                template+="TYPE=#{TYPES[type.to_i]}\n" if type
60
                result=image.allocate(template)
61 61

  
62
            # Get the allocated image 
63
            image=OpenNebula::Image.new_with_id(image.id, get_one_client)
64
            image.info
65
            template=image.to_hash
66
            template=template['IMAGE']['TEMPLATE']
62
                # Get the allocated image 
63
                image=OpenNebula::Image.new_with_id(image.id, get_one_client)
64
                image.info
65
                template=image['IMAGE/TEMPLATE']
67 66
            
68
            if !is_successful?(result) 
69
                exit -1
67
                if !is_successful?(result) 
68
                    exit -1
69
                end
70
            elsif disk["OVERWRITE"]
71
                # Get the allocated image 
72
                image=OpenNebula::Image.new_with_id(disk['IMAGE_ID'], get_one_client)
73
                image.info
74
                image.disable                                        
75
            end
76
            # Perform the copy to the image repo if needed
77
            if FileUtils.copy(source_path, image['SOURCE'])
78
                result=image.enable
70 79
            end
71
        elsif disk["OVERWRITE"]
72
            # Get the allocated image 
73
            image=OpenNebula::Image.new_with_id(disk['IID'], get_one_client)
74
            image.info
75
            image.disable                                        
76
        end
77
        # Perform the copy to the image repo if needed
78
        if File.copy(source_path, image['SOURCE'])
79
            result=image.enable
80 80
        end
81
        i = i + 1
81 82
    end
82 83
end
src/tm_mad/TMScript.rb
17 17

  
18 18
require 'pp'
19 19
require 'open3'
20
require 'ftools'
21 20
require 'CommandManager'
22 21

  
23 22
=begin rdoc
......
84 83
        scripts_text=""
85 84
        
86 85
        if File.exist?(scripts_file)
87
            scripts_text = open(scripts_file).read
86
            scripts_text = File.read(scripts_file)
88 87
        else
89 88
            STDERR.puts("Can not open #{scripts_file}")
90 89
            STDERR.flush

Also available in: Unified diff