15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/vagrant-ovirt/action/create_vm.rb', line 15
def call(env)
config = env[:machine].provider_config
name = env[:domain_name]
cpus = config.cpus
memory_size = config.memory*1024
if config.cluster == nil
cluster = env[:ovirt_compute].clusters.first
else
cluster = OVirtProvider::Util::Collection.find_matching(
env[:ovirt_compute].clusters.all, config.cluster)
end
raise Error::NoClusterError if cluster == nil
env[:ovirt_cluster] = cluster
template = OVirtProvider::Util::Collection.find_matching(
env[:ovirt_compute].templates.all, config.template)
if template == nil
raise Error::NoTemplateError,
:template_name => config.template
end
if config.quota == nil
quota = env[:ovirt_client].quotas.first
else
quota = OVirtProvider::Util::Collection.find_matching(
env[:ovirt_client].quotas.all, config.quota)
end
raise Error::NoQuotaError if quota == nil
env[:ui].info(I18n.t("vagrant_ovirt.creating_vm"))
env[:ui].info(" -- Name: #{name}")
env[:ui].info(" -- Cpus: #{cpus}")
env[:ui].info(" -- Memory: #{memory_size/1024}M")
env[:ui].info(" -- Base box: #{env[:machine].box.name}")
env[:ui].info(" -- Template: #{template.name}")
env[:ui].info(" -- Quota: #{quota.name}")
env[:ui].info(" -- Datacenter: #{config.datacenter}")
env[:ui].info(" -- Cluster: #{cluster.name}")
attr = {
:name => name,
:cores => cpus,
:memory => memory_size*1024,
:cluster => cluster.id,
:template => template.id,
:quota => quota.id,
}
begin
server = env[:ovirt_compute].servers.create(attr)
rescue OVIRT::OvirtException => e
raise Errors::FogCreateServerError,
:error_message => e.message
end
env[:machine].id = server.id
env[:ui].info(I18n.t("vagrant_ovirt.wait_for_ready_vm"))
for i in 0..5
ready = true
server.volumes.each do |volume|
if volume.status != 'ok'
ready = false
break
end
end
break if ready
sleep 2
end
@app.call(env)
end
|