Revision 69732b5d src/tm_mad/vcenter/mkimage

View differences:

src/tm_mad/vcenter/mkimage
1 1
#!/usr/bin/env ruby
2 2

  
3 3
# ---------------------------------------------------------------------------- #
4
# Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                  #
4
# Copyright 2002-2017, OpenNebula Project, OpenNebula Systems                  #
5 5
#                                                                              #
6 6
# Licensed under the Apache License, Version 2.0 (the "License"); you may      #
7 7
# not use this file except in compliance with the License. You may obtain      #
......
49 49

  
50 50
hostname, img_name = path.split(":")
51 51
disk_id  = img_name.split(".")[-1]
52
img_name = "one-#{vmid}-#{disk_id}"
53 52

  
54 53
# Get host ID
55 54
host = VCenterDriver::VIHelper.find_by_name(OpenNebula::HostPool, hostname)
......
59 58
one_ds = VCenterDriver::VIHelper.one_item(OpenNebula::Datastore, dsid)
60 59
ds_ref = one_ds['TEMPLATE/VCENTER_DS_REF']
61 60

  
62
# Get adapter and disk type
61
# Get one_vm
63 62
one_vm = VCenterDriver::VIHelper.one_item(OpenNebula::VirtualMachine, vmid)
63

  
64
# Adapter and disk type from one_vm
64 65
adapter_type = one_vm["/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/VCENTER_ADAPTER_TYPE"] ||
65 66
               VCenterDriver::VIHelper.get_default("IMAGE/TEMPLATE/VCENTER_ADAPTER_TYPE")
66 67
disk_type = one_vm["/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/VCENTER_DISK_TYPE"] ||
......
69 70
check_valid adapter_type, "adapter_type"
70 71
check_valid disk_type, "disk_type"
71 72

  
73
# Volatile images dir from one_vm
74
ds_volatile_dir = one_vm["/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/VCENTER_DS_VOLATILE_DIR"] ||
75
            "one-volatile"
76

  
72 77
begin
73 78
    vi_client = VCenterDriver::VIClient.new_from_host(host_id)
74 79

  
80
    img_name = "#{ds_volatile_dir}/#{vmid}/one-#{vmid}-#{disk_id}"
81

  
75 82
    ds_vc = VCenterDriver::Datastore.new_from_ref(ds_ref, vi_client)
76 83

  
77 84
    ds_vc.create_virtual_disk(img_name, size, adapter_type, disk_type)
......
81 88
                " Reason: #{e.message}\n#{e.backtrace}"
82 89
    exit -1
83 90
ensure
84
    vi_client.close_connection
91
    vi_client.close_connection if vi_client
85 92
end

Also available in: Unified diff