mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[oVirt] added volumes to server and template
This commit is contained in:
parent
987390c70a
commit
ebbffe1993
12 changed files with 220 additions and 4 deletions
|
@ -54,7 +54,7 @@ Gem::Specification.new do |s|
|
|||
s.add_development_dependency('rdoc')
|
||||
s.add_development_dependency('thor')
|
||||
s.add_development_dependency('rspec', '~>1.3.1')
|
||||
s.add_development_dependency('rbovirt', '>=0.0.9')
|
||||
s.add_development_dependency('rbovirt', '>=0.0.10')
|
||||
s.add_development_dependency('shindo', '~>0.3.4')
|
||||
s.add_development_dependency('virtualbox', '~>0.9.1')
|
||||
s.add_development_dependency('fission')
|
||||
|
|
|
@ -15,6 +15,8 @@ module Fog
|
|||
collection :clusters
|
||||
model :interface
|
||||
collection :interfaces
|
||||
model :volume
|
||||
collection :volumes
|
||||
|
||||
request_path 'fog/ovirt/requests/compute'
|
||||
|
||||
|
@ -37,6 +39,10 @@ module Fog
|
|||
request :list_template_interfaces
|
||||
request :list_networks
|
||||
request :vm_ticket
|
||||
request :list_vm_volumes
|
||||
request :list_template_volumes
|
||||
request :add_volume
|
||||
request :destroy_volume
|
||||
|
||||
module Shared
|
||||
# converts an OVIRT object into an hash for fog to consume.
|
||||
|
|
|
@ -25,6 +25,7 @@ module Fog
|
|||
attribute :cluster
|
||||
attribute :template
|
||||
attribute :interfaces
|
||||
attribute :volumes
|
||||
attribute :raw
|
||||
|
||||
def ready?
|
||||
|
@ -65,6 +66,23 @@ module Fog
|
|||
connection.destroy_interface(id, attrs)
|
||||
end
|
||||
|
||||
def volumes
|
||||
attributes[:volumes] ||= id.nil? ? [] : Fog::Compute::Ovirt::Volumes.new(
|
||||
:connection => connection,
|
||||
:vm => self
|
||||
)
|
||||
end
|
||||
|
||||
def add_volume attrs
|
||||
wait_for { stopped? } if attrs[:blocking]
|
||||
connection.add_volume(id, attrs)
|
||||
end
|
||||
|
||||
def destroy_volume attrs
|
||||
wait_for { stopped? } if attrs[:blocking]
|
||||
connection.destroy_volume(id, attrs)
|
||||
end
|
||||
|
||||
def start(options = {})
|
||||
wait_for { stopped? } if options[:blocking]
|
||||
connection.vm_action(:id =>id, :action => :start)
|
||||
|
|
|
@ -20,7 +20,7 @@ module Fog
|
|||
attribute :memory
|
||||
attribute :cluster
|
||||
attribute :interfaces
|
||||
|
||||
attribute :volumes
|
||||
|
||||
def interfaces
|
||||
attributes[:interfaces] ||= id.nil? ? [] : Fog::Compute::Ovirt::Interfaces.new(
|
||||
|
@ -29,6 +29,13 @@ module Fog
|
|||
)
|
||||
end
|
||||
|
||||
def volumes
|
||||
attributes[:volumes] ||= id.nil? ? [] : Fog::Compute::Ovirt::Volumes.new(
|
||||
:connection => connection,
|
||||
:vm => self
|
||||
)
|
||||
end
|
||||
|
||||
def ready?
|
||||
!(status =~ /down/i)
|
||||
end
|
||||
|
|
25
lib/fog/ovirt/models/compute/volume.rb
Normal file
25
lib/fog/ovirt/models/compute/volume.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Ovirt
|
||||
|
||||
class Volume < Fog::Model
|
||||
attr_accessor :raw
|
||||
identity :id
|
||||
|
||||
attribute :storage_domain
|
||||
attribute :size
|
||||
attribute :disk_type
|
||||
attribute :bootable
|
||||
attribute :interface
|
||||
attribute :format
|
||||
attribute :sparse
|
||||
|
||||
def to_s
|
||||
id
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/ovirt/models/compute/volumes.rb
Normal file
32
lib/fog/ovirt/models/compute/volumes.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require 'fog/core/collection'
|
||||
require 'fog/ovirt/models/compute/volume'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class Ovirt
|
||||
|
||||
class Volumes < Fog::Collection
|
||||
|
||||
model Fog::Compute::Ovirt::Volume
|
||||
|
||||
attr_accessor :vm
|
||||
|
||||
def all(filters = {})
|
||||
requires :vm
|
||||
if vm.is_a? Fog::Compute::Ovirt::Server
|
||||
load connection.list_vm_volumes(vm.id)
|
||||
elsif vm.is_a? Fog::Compute::Ovirt::Template
|
||||
load connection.list_template_volumes(vm.id)
|
||||
else
|
||||
raise 'volumes should have vm or template'
|
||||
end
|
||||
end
|
||||
|
||||
def get(id)
|
||||
new connection.get_volume(id)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/ovirt/requests/compute/add_volume.rb
Normal file
23
lib/fog/ovirt/requests/compute/add_volume.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Ovirt
|
||||
class Real
|
||||
|
||||
def add_volume(id, options = {})
|
||||
raise ArgumentError, "instance id is a required parameter" unless id
|
||||
|
||||
client.add_volume(id, options)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
def add_volume(id, options = {})
|
||||
raise ArgumentError, "instance id is a required parameter" unless id
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
25
lib/fog/ovirt/requests/compute/destroy_volume.rb
Normal file
25
lib/fog/ovirt/requests/compute/destroy_volume.rb
Normal file
|
@ -0,0 +1,25 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Ovirt
|
||||
class Real
|
||||
|
||||
def destroy_volume(id, options)
|
||||
raise ArgumentError, "instance id is a required parameter" unless id
|
||||
raise ArgumentError, "volume id is a required parameter for destroy-volume" unless options.has_key? :id
|
||||
|
||||
client.destroy_volume(id, options[:id])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
def destroy_volume(id, options)
|
||||
raise ArgumentError, "instance id is a required parameter" unless id
|
||||
raise ArgumentError, "volume id is a required parameter for destroy-volume" unless options.has_key? :id
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
20
lib/fog/ovirt/requests/compute/list_template_volumes.rb
Normal file
20
lib/fog/ovirt/requests/compute/list_template_volumes.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Ovirt
|
||||
class Real
|
||||
def list_template_volumes(template_id)
|
||||
client.template_volumes(template_id).map {|ovirt_obj| ovirt_attrs ovirt_obj}
|
||||
end
|
||||
|
||||
end
|
||||
class Mock
|
||||
def list_template_volumes(template_id)
|
||||
xml = read_xml 'volumes.xml'
|
||||
Nokogiri::XML(xml).xpath('/disks/disk').collect do |vol|
|
||||
ovirt_attrs OVIRT::Volume::new(self, vol)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
20
lib/fog/ovirt/requests/compute/list_vm_volumes.rb
Normal file
20
lib/fog/ovirt/requests/compute/list_vm_volumes.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class Ovirt
|
||||
class Real
|
||||
def list_vm_volumes(vm_id)
|
||||
client.vm_volumes(vm_id).map {|ovirt_obj| ovirt_attrs ovirt_obj}
|
||||
end
|
||||
|
||||
end
|
||||
class Mock
|
||||
def list_vm_volumes(vm_id)
|
||||
xml = read_xml 'volumes.xml'
|
||||
Nokogiri::XML(xml).xpath('/disks/disk').collect do |vol|
|
||||
ovirt_attrs OVIRT::Volume::new(self, vol)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
40
lib/fog/ovirt/requests/compute/mock_files/volumes.xml
Normal file
40
lib/fog/ovirt/requests/compute/mock_files/volumes.xml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<disks>
|
||||
<disk href="/api/vms/192cdd3f-3281-4e20-b81d-93bdc57ac387/disks/9f68ecfd-218b-4f80-8e7a-e70b2ab054cd" id="9f68ecfd-218b-4f80-8e7a-e70b2ab054cd">
|
||||
<name>Disk 2</name>
|
||||
<link href="/api/vms/192cdd3f-3281-4e20-b81d-93bdc57ac387/disks/9f68ecfd-218b-4f80-8e7a-e70b2ab054cd/statistics" rel="statistics"/>
|
||||
<vm href="/api/vms/192cdd3f-3281-4e20-b81d-93bdc57ac387" id="192cdd3f-3281-4e20-b81d-93bdc57ac387"/>
|
||||
<storage_domains>
|
||||
<storage_domain id="cba62b33-887a-410c-b367-e3d9229a72f7"/>
|
||||
</storage_domains>
|
||||
<size>5368709120</size>
|
||||
<type>data</type>
|
||||
<status>
|
||||
<state>ok</state>
|
||||
</status>
|
||||
<interface>virtio</interface>
|
||||
<format>raw</format>
|
||||
<sparse>true</sparse>
|
||||
<bootable>false</bootable>
|
||||
<wipe_after_delete>false</wipe_after_delete>
|
||||
<propagate_errors>false</propagate_errors>
|
||||
</disk>
|
||||
<disk href="/api/vms/192cdd3f-3281-4e20-b81d-93bdc57ac387/disks/e373b1a5-6c89-43f1-9a2d-cdf674412349" id="e373b1a5-6c89-43f1-9a2d-cdf674412349">
|
||||
<name>Disk 1</name>
|
||||
<link href="/api/vms/192cdd3f-3281-4e20-b81d-93bdc57ac387/disks/e373b1a5-6c89-43f1-9a2d-cdf674412349/statistics" rel="statistics"/>
|
||||
<vm href="/api/vms/192cdd3f-3281-4e20-b81d-93bdc57ac387" id="192cdd3f-3281-4e20-b81d-93bdc57ac387"/>
|
||||
<storage_domains>
|
||||
<storage_domain id="cba62b33-887a-410c-b367-e3d9229a72f7"/>
|
||||
</storage_domains>
|
||||
<size>8589934592</size>
|
||||
<type>system</type>
|
||||
<status>
|
||||
<state>ok</state>
|
||||
</status>
|
||||
<interface>virtio</interface>
|
||||
<format>cow</format>
|
||||
<sparse>true</sparse>
|
||||
<bootable>true</bootable>
|
||||
<wipe_after_delete>false</wipe_after_delete>
|
||||
<propagate_errors>false</propagate_errors>
|
||||
</disk>
|
||||
</disks>
|
|
@ -4,7 +4,7 @@ module Fog
|
|||
class Real
|
||||
|
||||
def storage_domains filter={}
|
||||
client.storagedomains(filter).map {|ovirt_obj| ovirt_attrs ovirt_obj}
|
||||
client.storagedomains(filter)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ module Fog
|
|||
def storage_domains(filters = {})
|
||||
xml = read_xml 'storage_domains.xml'
|
||||
Nokogiri::XML(xml).xpath('/storage_domains/storage_domain').collect do |sd|
|
||||
ovirt_attrs OVIRT::StorageDomain::new(self, sd)
|
||||
OVIRT::StorageDomain::new(self, sd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue