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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/vagrant-libvirt/action/create_domain.rb', line 23
def call(env)
config = env[:machine].provider_config
@name = env[:domain_name]
@cpus = config.cpus
@cpu_mode = config.cpu_mode
@disk_bus = config.disk_bus
@nested = config.nested
@memory_size = config.memory*1024
@domain_volume_cache = config.volume_cache
@kernel = config.kernel
@cmd_line = config.cmd_line
@initrd = config.initrd
@storage_pool_name = config.storage_pool_name
@disks = config.disks
config = env[:machine].provider_config
@domain_type = config.driver
@os_type = 'hvm'
domain_volume = ProviderLibvirt::Util::Collection.find_matching(
env[:libvirt_compute].volumes.all, "#{@name}.img")
raise Errors::DomainVolumeExists if domain_volume == nil
@domain_volume_path = domain_volume.path
storage_prefix = File.dirname(@domain_volume_path)+'/'
@disks.each do |disk|
disk[:name] = _disk_name(@name, disk)
if disk[:path].nil?
disk[:path] = "#{storage_prefix}#{_disk_name(@name, disk)}" end
begin
domain_volume_disk = env[:libvirt_compute].volumes.create(
:name => disk[:name],
:format_type => disk[:type],
:path => disk[:path],
:capacity => disk[:size],
:pool_name => @storage_pool_name)
rescue Fog::Errors::Error => e
raise Errors::FogDomainVolumeCreateError,
:error_message => e.message
end
end
env[:ui].info(I18n.t("vagrant_libvirt.creating_domain"))
env[:ui].info(" -- Name: #{@name}")
env[:ui].info(" -- Domain type: #{@domain_type}")
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(" -- Storage pool: #{@storage_pool_name}")
env[:ui].info(" -- Image: #{@domain_volume_path}")
env[:ui].info(" -- Volume Cache: #{@domain_volume_cache}")
env[:ui].info(" -- Kernel: #{@kernel}")
env[:ui].info(" -- Initrd: #{@initrd}")
if @disks.length > 0
env[:ui].info(" -- Disks: #{_disks_print(@disks)}")
end
@disks.each do |disk|
env[:ui].info(" -- Disk(#{disk[:device]}): #{disk[:path]}")
end
env[:ui].info(" -- Command line : #{@cmd_line}")
begin
server = env[:libvirt_compute].servers.create(
:xml => to_xml('domain'))
rescue Fog::Errors::Error => e
raise Errors::FogCreateServerError,
:error_message => e.message
end
env[:machine].id = server.id
@app.call(env)
end
|