Revision aae5b614 src/tm_mad/vcenter/mkimage

View differences:

src/tm_mad/vcenter/mkimage
35 35
$: << RUBY_LIB_LOCATION
36 36
$: << File.dirname(__FILE__)
37 37

  
38
require 'opennebula'
38 39
require 'vcenter_driver'
39 40

  
41
client = OpenNebula::Client.new
42

  
43
################################################################################
44

  
45
def check_valid(parameter, label)
46
    if parameter.nil? || parameter.empty?
47
        STDERR.puts "Not enough information to create the volatile disk. " +
48
                    "Missing '#{label}'."
49
        exit -1
50
    end
51
end
52

  
53
################################################################################
54

  
40 55
size               = ARGV[0]
41 56
fstype             = ARGV[1]
42
hostname, img_path = ARGV[2].split(":")
57
hostname, img_name = ARGV[2].split(":")
43 58
vmid               = ARGV[3]
44 59
dsid               = ARGV[4]
45 60

  
46
begin
47
    disk_id  = img_path.split(".")[1]
48
    vm       = OpenNebula::VirtualMachine.new_with_id(vmid, 
49
                                                      OpenNebula::Client.new)
50
    vm.info
51
    adapter_type = vm["VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/ADAPTER_TYPE"]
52
    disk_type    = vm["VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/DISK_TYPE"]
53
rescue Exception => e
54
    STDERR.puts "Error getting attributes from VM template #{vmid}."\
55
                " Reason: #{e.message}"
56
    exit -1
57
end
61
disk_id  = img_name.split(".")[-1]
62
img_name = "one_#{vmid}_#{disk_id}"
63

  
64
################################################################################
65

  
66
vm = OpenNebula::VirtualMachine.new_with_id(vmid, client)
58 67

  
59
if disk_type.nil? or disk_type.empty?
60
  disk_type = "thin"
68
rc = vm.info
69
if OpenNebula.is_error?(rc)
70
     puts rc.message
71
     exit -1
61 72
end
62 73

  
74
adapter_type = vm["/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/ADAPTER_TYPE"]
75
check_valid adapter_type, "adapter_type"
76

  
77
# TODO get the DISK_TYPE
78
# disk_type    = vm["/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/DISK_TYPE"]
79
# if disk_type.nil? || disk_type.empty?
80
#   disk_type = "thin"
81
# end
82
disk_type = "thin"
83

  
63 84
begin
64 85
    host_id      = VCenterDriver::VIClient.translate_hostname(hostname)
65 86
    vi_client    = VCenterDriver::VIClient.new host_id
......
74 95
    STDERR.puts "Error creating virtual disk in #{ds_name}."\
75 96
                " Reason: #{e.message}"
76 97
    exit -1
77
end
98
end

Also available in: Unified diff