1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
|
# File 'lib/vm_template.rb', line 1805
def import(selected)
opts = @info[selected[:ref]][:opts]
working_template = selected
vcenter = selected[:vcenter]
vc_uuid = selected[:vcenter_instance_uuid]
dc = selected[:dc_name]
linked_clone = opts[:linked_clone] == '1'
copy = opts[:copy] == '1'
deploy_in_folder = !opts[:folder].empty?
res = { :id => [], :name => selected[:name] }
dpool, ipool, npool, hpool = create_pools
template =
VCenterDriver::Template
.new_from_ref(
selected[:vcenter_ref],
@vi_client
)
if linked_clone
if copy
error, template_copy_ref =
selected[:template]
.create_template_copy(
opts[:name]
)
unless template_copy_ref
raise 'There is a problem creating creating' \
"your copy: #{error}"
end
template =
VCenterDriver::Template
.new_from_ref(
template_copy_ref,
@vi_client
)
@rollback <<
Raction
.new(
template,
:delete_template
)
one_template =
VCenterDriver::Template
.get_xml_template(
template,
vc_uuid,
@vi_client,
dc
)
unless one_template
raise 'There is a problem obtaining info '\
"from your template's copy"
end
working_template = one_template
end
lc_error, use_lc = template.create_delta_disks
if lc_error
raise 'Something was wront with create \
delta disk operation'
end
if use_lc
working_template[:one] <<
"\nVCENTER_LINKED_CLONES=\"YES\"\n"
end
end
if deploy_in_folder
working_template[:one] <<
"VCENTER_VM_FOLDER=\"#{opts[:folder]}\"\n"
end
working_template[:one] <<
"VCENTER_TEMPLATE_NAME=\"#{selected[:name]}\"\n"
create(working_template[:one]) do |one_object, id|
res[:id] << id
type = { :object => 'template', :id => id }
error, template_disks, allocated_images =
template
.import_vcenter_disks(
vc_uuid,
dpool,
ipool,
type
)
if allocated_images
allocated_images.reverse.each do |i|
@rollback.unshift(Raction.new(i, :delete))
end
end
raise error unless error.empty?
working_template[:one] << template_disks
if template_copy_ref
template_moref = template_copy_ref
else
template_moref = selected[:vcenter_ref]
end
opts_nics = {
:vi_client => @vi_client,
:vc_uuid => vc_uuid,
:npool => npool,
:hpool => hpool,
:vcenter => vcenter,
:template_moref => template_moref,
:vm_object => nil
}
error, template_nics, _ar_ids, allocated_nets =
template
.import_vcenter_nics(
opts_nics,
id,
dc
)
if allocated_nets
allocated_nets.reverse.each do |n|
@rollback.unshift(Raction.new(n, :delete))
end
end
raise error unless error.empty?
working_template[:one] << template_nics
working_template[:one] << rp_opts(
opts[:type],
opts[:resourcepool]
)
one_object.update(working_template[:one])
end
res
end
|