1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

* Added create_vdi request

* Added missing VDI methods and attributes
This commit is contained in:
Sergio Rubio 2012-04-09 21:33:47 +02:00
parent f4dd7b3835
commit f34fed46f2
4 changed files with 63 additions and 9 deletions

View file

@ -39,6 +39,7 @@ module Fog
request_path 'fog/xenserver/requests/compute'
request :create_server
request :create_vif
request :create_vdi
request :destroy_vif
request :clone_server
request :destroy_server

View file

@ -15,17 +15,47 @@ module Fog
attribute :name, :aliases => :name_label
attribute :description, :aliases => :name_description
attribute :__parent, :aliases => :parent
attribute :virtual_size, :aliases => :parent
attribute :virtual_size
attribute :__vbds, :aliases => :VBDs
attribute :__sr, :aliases => :SR
attribute :sharable
attribute :readonly
attribute :read_only
attribute :current_operations
attribute :allowed_operations
attribute :type
attribute :other_config
def initialize(attributes={})
@uuid ||= 0
super
#
# Default VDI type is system
# Default size 8GB
# Sharable is false by default
# read_only is false by default
#
def initialize(attributes = {})
self.virtual_size ||= '8589934592' unless attributes[:virtual_size]
self.type ||= 'system' unless attributes[:type]
self.read_only ||= false unless attributes[:read_only]
self.sharable ||= false unless attributes[:sharable]
self.other_config ||= {} unless attributes[:other_config]
super
end
def save
requires :name, :storage_repository
ref = connection.create_vdi attributes
merge_attributes connection.vdis.get(ref).attributes
end
def destroy
connection.destroy_vdi reference
end
def storage_repository
connection.storage_repositories.get __sr
end
def sr
storage_repository
end
end

View file

@ -9,10 +9,6 @@ module Fog
model Fog::Compute::XenServer::VDI
def initialize(attributes)
super
end
def all(options = {})
data = connection.get_records 'VDI'
load(data)

View file

@ -0,0 +1,27 @@
module Fog
module Compute
class XenServer
class Real
def create_vdi( config )
raise ArgumentError.new('Invalid config') if config.nil?
config[:SR] = config[:storage_repository].reference
config[:name_label] = config[:name]
config[:name_description] = config[:description] if config[:description]
config.reject! { |k,v| (k == :__sr) or (k == :storage_repository) }
@connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VDI.create'}, config )
end
end
class Mock
def create_vdi( ref )
Fog::Mock.not_implemented
end
end
end
end
end