mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
* Added missing VBD operations
This commit is contained in:
parent
f34fed46f2
commit
2754694787
8 changed files with 157 additions and 8 deletions
|
@ -35,6 +35,7 @@ module Fog
|
|||
collection :pbds
|
||||
model :pbd
|
||||
model :guest_metrics
|
||||
model :vbd_metrics
|
||||
|
||||
request_path 'fog/xenserver/requests/compute'
|
||||
request :create_server
|
||||
|
@ -43,7 +44,9 @@ module Fog
|
|||
request :destroy_vif
|
||||
request :clone_server
|
||||
request :destroy_server
|
||||
request :destroy_vbd
|
||||
request :unplug_vbd
|
||||
request :eject_vbd
|
||||
request :insert_vbd
|
||||
request :destroy_vdi
|
||||
request :shutdown_server
|
||||
request :start_vm
|
||||
|
|
|
@ -54,9 +54,9 @@ module Fog
|
|||
stop('hard')
|
||||
vbds.each do |vbd|
|
||||
if vbd.type == "Disk"
|
||||
connection.destroy_vbd( vbd.reference ) \
|
||||
vbd.unplug \
|
||||
if vbd.allowed_operations.include?("unplug")
|
||||
connection.destroy_vdi( vbd.vdi.reference ) \
|
||||
vbd.vdi.destroy \
|
||||
if vbd.vdi.allowed_operations.include?("destroy")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,7 +14,6 @@ module Fog
|
|||
attribute :currently_attached
|
||||
attribute :allowed_operations
|
||||
attribute :current_operations
|
||||
attribute :reserved
|
||||
attribute :__vdi, :aliases => :VDI
|
||||
attribute :__vm, :aliases => :VM
|
||||
attribute :device
|
||||
|
@ -25,8 +24,12 @@ module Fog
|
|||
attribute :empty
|
||||
attribute :type
|
||||
attribute :mode
|
||||
attribute :storage_lock
|
||||
attribute :runtime_properties
|
||||
attribute :unpluggable
|
||||
attribute :bootable
|
||||
attribute :empty
|
||||
attribute :__metrics, :aliases => :metrics
|
||||
|
||||
#
|
||||
# May return nil
|
||||
|
@ -42,6 +45,27 @@ module Fog
|
|||
connection.servers.get __vm
|
||||
end
|
||||
|
||||
def unplug
|
||||
connection.unplug_vbd reference
|
||||
end
|
||||
|
||||
def unplug_force
|
||||
connection.unplug_force_vbd reference
|
||||
end
|
||||
|
||||
def eject
|
||||
connection.eject_vbd reference
|
||||
end
|
||||
|
||||
def insert(vdi)
|
||||
connection.insert_vbd reference, vdi.reference
|
||||
end
|
||||
|
||||
def metrics
|
||||
rec = connection.get_record( __metrics, 'VBD_metrics' )
|
||||
Fog::Compute::XenServer::VbdMetrics.new(rec)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
27
lib/fog/xenserver/models/compute/vbd_metrics.rb
Normal file
27
lib/fog/xenserver/models/compute/vbd_metrics.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'fog/core/model'
|
||||
|
||||
module Fog
|
||||
module Compute
|
||||
class XenServer
|
||||
|
||||
class VbdMetrics < Fog::Model
|
||||
# API Reference here:
|
||||
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VBD_metrics
|
||||
|
||||
identity :reference
|
||||
|
||||
attribute :uuid
|
||||
attribute :last_updated
|
||||
attribute :other_config
|
||||
attribute :io_read_kbs
|
||||
attribute :io_write_kbs
|
||||
|
||||
def initialize(attributes = {})
|
||||
super
|
||||
self.last_updated = attributes[:last_updated].to_time
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,15 +4,15 @@ module Fog
|
|||
|
||||
class Real
|
||||
|
||||
def destroy_vbd( vbd_ref, extra_args = {})
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VBD.unplug'}, vbd_ref)
|
||||
def eject_vbd(ref, extra_args = {})
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VBD.eject'}, ref)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def destroy_vbd()
|
||||
def eject_vbd(ref, extra_args = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
22
lib/fog/xenserver/requests/compute/insert_vbd.rb
Normal file
22
lib/fog/xenserver/requests/compute/insert_vbd.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class XenServer
|
||||
|
||||
class Real
|
||||
|
||||
def insert_vbd(ref, vdi_ref, extra_args = {})
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VBD.insert'}, ref, vdi_ref)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def insert_vbd(ref, vdi_ref, extra_args = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/xenserver/requests/compute/unplug_vbd.rb
Normal file
30
lib/fog/xenserver/requests/compute/unplug_vbd.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class XenServer
|
||||
|
||||
class Real
|
||||
|
||||
def unplug_vbd( vbd_ref, extra_args = {})
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VBD.unplug'}, vbd_ref)
|
||||
end
|
||||
|
||||
def unplug_force_vbd(ref, extra_args = {})
|
||||
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VBD.unplug_force'}, ref)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def unplug_vbd(ref, extra_args = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
def unplug_force_vbd(ref, extra_args = {})
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -6,6 +6,10 @@ Shindo.tests('Fog::Compute[:xenserver] | VBD model', ['VBD']) do
|
|||
tests('The VBD model should') do
|
||||
tests('have the action') do
|
||||
test('reload') { vbd.respond_to? 'reload' }
|
||||
test('eject') { vbd.respond_to? 'eject' }
|
||||
test('insert') { vbd.respond_to? 'insert' }
|
||||
test('unplug') { vbd.respond_to? 'unplug' }
|
||||
test('unplug_force') { vbd.respond_to? 'unplug_force' }
|
||||
end
|
||||
tests('have attributes') do
|
||||
model_attribute_hash = vbd.attributes
|
||||
|
@ -18,7 +22,17 @@ Shindo.tests('Fog::Compute[:xenserver] | VBD model', ['VBD']) do
|
|||
:device,
|
||||
:status_detail,
|
||||
:type,
|
||||
:userdevice
|
||||
:allowed_operations,
|
||||
:current_operations,
|
||||
:status_code,
|
||||
:storage_lock,
|
||||
:mode,
|
||||
:runtime_properties,
|
||||
:unpluggable,
|
||||
:userdevice,
|
||||
:bootable,
|
||||
:empty,
|
||||
:__metrics
|
||||
]
|
||||
tests("The VBD model should respond to") do
|
||||
attributes.each do |attribute|
|
||||
|
@ -37,6 +51,23 @@ Shindo.tests('Fog::Compute[:xenserver] | VBD model', ['VBD']) do
|
|||
end
|
||||
|
||||
tests("A real VBD should") do
|
||||
test("have a valid OpaqueRef") do
|
||||
puts vbd.reference
|
||||
(vbd.reference =~ /OpaqueRef:/).eql?(0) and \
|
||||
vbd.reference != "OpaqueRef:NULL"
|
||||
end
|
||||
tests("belong to a VM when attached") do
|
||||
vbds.each do |vbd|
|
||||
test("#{vbd.uuid}") do
|
||||
if vbd.currently_attached
|
||||
(vbd.__vm =~ /OpaqueRef/).eql?(0) and \
|
||||
vbd.__vm != "OpaqueRef:NULL"
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
vbds.each do |vbd|
|
||||
test("return a Fog::Compute::XenServer::VDI when type Disk") do
|
||||
if vbd.type == 'Disk'
|
||||
|
@ -60,7 +91,19 @@ Shindo.tests('Fog::Compute[:xenserver] | VBD model', ['VBD']) do
|
|||
tests("return valid Server") do
|
||||
test("should be a Fog::Compute::XenServer::Server") { vbd.server.kind_of? Fog::Compute::XenServer::Server }
|
||||
end
|
||||
test("return a VbdMetrics object") { vbd.metrics.kind_of? Fog::Compute::XenServer::VbdMetrics }
|
||||
test("be able to be unplugged when type is CD") do
|
||||
if vbd.type == "CD"
|
||||
vbd.unpluggable == true
|
||||
else
|
||||
vbd.unpluggable == false
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests("VBD Metrics should") do
|
||||
test("have a last_updated Time property") { vbd.metrics.last_updated.kind_of? Time }
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue