diff --git a/lib/fog/libvirt/models/compute/network.rb b/lib/fog/libvirt/models/compute/network.rb
index ee2799a..b6282fc 100644
--- a/lib/fog/libvirt/models/compute/network.rb
+++ b/lib/fog/libvirt/models/compute/network.rb
@@ -27,6 +27,17 @@ def save
def shutdown
service.destroy_network(uuid)
end
+
+ def to_xml
+ builder = Nokogiri::XML::Builder.new do |xml|
+ xml.network do
+ xml.name(name)
+ xml.bridge(:name => bridge_name, :stp => 'on', :delay => '0')
+ end
+ end
+
+ builder.to_xml
+ end
end
end
end
diff --git a/lib/fog/libvirt/models/compute/pool.rb b/lib/fog/libvirt/models/compute/pool.rb
index 34d8b81..baca2fd 100644
--- a/lib/fog/libvirt/models/compute/pool.rb
+++ b/lib/fog/libvirt/models/compute/pool.rb
@@ -78,6 +78,20 @@ def persistent?
def volumes
service.list_pool_volumes uuid
end
+
+ def to_xml
+ builder = Nokogiri::XML::Builder.new do |xml|
+ xml.pool(:type => 'dir') do
+ xml.name(name)
+
+ xml.target do
+ xml.path(path)
+ end
+ end
+ end
+
+ builder.to_xml
+ end
end
end
end
diff --git a/lib/fog/libvirt/models/compute/templates/network.xml.erb b/lib/fog/libvirt/models/compute/templates/network.xml.erb
deleted file mode 100644
index 91493dd..0000000
--- a/lib/fog/libvirt/models/compute/templates/network.xml.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-
- <%= name %>
-
-
-
-
diff --git a/lib/fog/libvirt/models/compute/templates/volume.xml.erb b/lib/fog/libvirt/models/compute/templates/volume.xml.erb
deleted file mode 100644
index 9bba14a..0000000
--- a/lib/fog/libvirt/models/compute/templates/volume.xml.erb
+++ /dev/null
@@ -1,34 +0,0 @@
-
- <%= name %>
- <%= split_size_unit(allocation)[0] %>
- <%= split_size_unit(capacity)[0] %>
-
-
-
- <% if owner -%>
- <%= owner %>
- <% end -%>
- <% if group -%>
- <%= group %>
- <% end -%>
- 0744
-
-
-
- <% if backing_volume -%>
-
- <%= backing_volume.path %>
-
-
- <% if owner -%>
- <%= owner %>
- <% end -%>
- <% if group -%>
- <%= group %>
- <% end -%>
- 0744
-
-
-
- <% end -%>
-
diff --git a/lib/fog/libvirt/models/compute/util/util.rb b/lib/fog/libvirt/models/compute/util/util.rb
index f0939bf..6f6893a 100644
--- a/lib/fog/libvirt/models/compute/util/util.rb
+++ b/lib/fog/libvirt/models/compute/util/util.rb
@@ -16,14 +16,6 @@ def xml_elements(xml, path, attribute=nil)
attribute.nil? ? (xml/path).map : (xml/path).map{|element| element[attribute.to_sym]}
end
- def to_xml template_name = nil
- # figure out our ERB template filename
- erb = template_name || self.class.to_s.split("::").last.downcase
- path = File.join(File.dirname(__FILE__), "..", "templates", "#{erb}.xml.erb")
- template = File.read(path)
- ERB.new(template, nil, '-').result(binding)
- end
-
def randomized_name
"fog-#{(SecureRandom.random_number*10E14).to_i.round}"
end
diff --git a/lib/fog/libvirt/models/compute/volume.rb b/lib/fog/libvirt/models/compute/volume.rb
index db7f0d4..2241579 100644
--- a/lib/fog/libvirt/models/compute/volume.rb
+++ b/lib/fog/libvirt/models/compute/volume.rb
@@ -79,6 +79,47 @@ def upload_image(file_path)
service.upload_volume(pool_name, name, file_path)
end
+ def to_xml
+ builder = Nokogiri::XML::Builder.new do |xml|
+ xml.volume do
+ xml.name(name)
+
+ allocation_size, allocation_unit = split_size_unit(allocation)
+ xml.allocation(allocation_size, :unit => allocation_unit)
+
+ capacity_size, capacity_unit = split_size_unit(capacity)
+ xml.capacity(capacity_size, :unit => capacity_unit)
+
+ xml.target do
+ xml.format(:type => format_type)
+
+ xml.permissions do
+ xml.owner(owner) if owner
+ xml.group(group) if group
+ xml.mode('0744')
+ xml.label('virt_image_t')
+ end
+ end
+
+ if backing_volume
+ xml.backingStore do
+ xml.path(backing_volume.path)
+ xml.format(:type => backing_volume.format_type)
+
+ xml.permissions do
+ xml.owner(owner) if owner
+ xml.group(group) if group
+ xml.mode('0744')
+ xml.label('virt_image_t')
+ end
+ end
+ end
+ end
+ end
+
+ builder.to_xml
+ end
+
private
def image_suffix
diff --git a/tests/libvirt/models/compute/network_tests.rb b/tests/libvirt/models/compute/network_tests.rb
index 5a9a7a4..a83886d 100644
--- a/tests/libvirt/models/compute/network_tests.rb
+++ b/tests/libvirt/models/compute/network_tests.rb
@@ -30,12 +30,14 @@
tests("to_xml") do
test("default") do
- begin
- network.to_xml
- false
- rescue NameError # forward_mode is undefined
- true
- end
+ expected = <<~NETWORK
+
+
+ default
+
+
+ NETWORK
+ network.to_xml == expected
end
end
end
diff --git a/tests/libvirt/models/compute/volume_tests.rb b/tests/libvirt/models/compute/volume_tests.rb
index 26238a1..4515941 100644
--- a/tests/libvirt/models/compute/volume_tests.rb
+++ b/tests/libvirt/models/compute/volume_tests.rb
@@ -38,18 +38,19 @@
test('to_xml') do
test('default') do
expected = <<~VOLUME
+
- fog_test
- 1
- 10
-
-
-
- 0744
-
-
-
-
+ fog_test
+ 1
+ 10
+
+
+
+ 0744
+
+
+
+
VOLUME
volume.to_xml == expected
end