mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[libvirt|compute] Allow volumes to be cloned at the disk level
This commit is contained in:
parent
2821afa750
commit
46b53e0db7
4 changed files with 38 additions and 0 deletions
|
@ -38,6 +38,7 @@ module Fog
|
|||
request :list_volumes
|
||||
request :volume_action
|
||||
request :create_volume
|
||||
request :clone_volume
|
||||
request :list_networks
|
||||
request :destroy_network
|
||||
request :list_interfaces
|
||||
|
|
|
@ -62,6 +62,17 @@ module Fog
|
|||
new_volume.reload
|
||||
end
|
||||
|
||||
def clone_volume(new_name)
|
||||
requires :pool_name
|
||||
|
||||
new_volume = self.dup
|
||||
new_volume.key = nil
|
||||
new_volume.name = new_name
|
||||
new_volume.path = service.clone_volume(pool_name, new_volume.to_xml, self.name).path
|
||||
|
||||
new_volume.reload
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def image_suffix
|
||||
|
|
18
lib/fog/libvirt/requests/compute/clone_volume.rb
Normal file
18
lib/fog/libvirt/requests/compute/clone_volume.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Libvirt
|
||||
class Real
|
||||
def clone_volume (pool_name, xml, name)
|
||||
vol = client.lookup_storage_pool_by_name(pool_name).lookup_volume_by_name(name)
|
||||
client.lookup_storage_pool_by_name(pool_name).create_vol_xml_from(xml, vol)
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def clone_volume(pool_name, xml, name)
|
||||
Fog::Compute::Libvirt::Volume.new({:pool_name => pool_name, :xml => xml})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -27,4 +27,12 @@ Shindo.tests('Fog::Compute[:libvirt] | volume model', ['libvirt']) do
|
|||
test('be a kind of Fog::Compute::Libvirt::Volume') { volume.kind_of? Fog::Compute::Libvirt::Volume }
|
||||
end
|
||||
|
||||
tests('Cloning volumes should') do
|
||||
test('respond to clone_volume') { volume.respond_to? :clone_volume }
|
||||
new_vol = volume.clone_volume('new_vol')
|
||||
# We'd like to test that the :name attr has changed, but it seems that's
|
||||
# not possible, so we can at least check the new_vol xml exists properly
|
||||
test('succeed') { volume.xml == new_vol.xml }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue