2012-04-02 07:25:03 -04:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class XenServer
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
class StorageRepository < Fog::Model
|
|
|
|
# API Reference here:
|
2013-12-10 20:05:42 -05:00
|
|
|
# http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=SR
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
identity :reference
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 09:27:35 -04:00
|
|
|
attribute :name, :aliases => :name_label
|
|
|
|
attribute :description, :aliases => :name_description
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :uuid
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :blobs
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :allowed_operations
|
2012-04-02 09:27:35 -04:00
|
|
|
attribute :current_operations
|
2013-12-10 20:05:42 -05:00
|
|
|
attribute :introduced_by
|
|
|
|
attribute :local_cache_enabled
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :content_type
|
|
|
|
attribute :other_config
|
2012-04-02 09:27:35 -04:00
|
|
|
attribute :__pbds, :aliases => :PBDs
|
2012-04-02 07:25:03 -04:00
|
|
|
attribute :shared
|
|
|
|
attribute :type
|
2012-04-02 09:27:35 -04:00
|
|
|
attribute :tags
|
|
|
|
attribute :__vdis, :aliases => :VDIs
|
|
|
|
attribute :physical_size
|
|
|
|
attribute :physical_utilisation
|
2012-04-16 15:09:52 -04:00
|
|
|
attribute :sm_config
|
|
|
|
attribute :virtual_allocation
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 09:27:35 -04:00
|
|
|
def vdis
|
2012-12-22 18:21:33 -05:00
|
|
|
__vdis.collect { |vdi| service.vdis.get vdi }
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 09:27:35 -04:00
|
|
|
def pbds
|
2012-12-22 18:21:33 -05:00
|
|
|
__pbds.collect { |pbd| service.pbds.get pbd }
|
2012-04-02 09:27:35 -04:00
|
|
|
end
|
|
|
|
|
2012-04-16 15:09:52 -04:00
|
|
|
def scan
|
2012-12-22 18:21:33 -05:00
|
|
|
service.scan_sr reference
|
2012-04-16 15:09:52 -04:00
|
|
|
reload
|
|
|
|
end
|
|
|
|
|
2012-12-30 18:55:42 -05:00
|
|
|
def destroy
|
2013-01-07 18:14:13 -05:00
|
|
|
service.destroy_sr reference
|
2012-12-30 18:55:42 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
|
|
|
requires :name
|
|
|
|
requires :type
|
|
|
|
|
|
|
|
# host is not a model attribute (not in XAPI at least),
|
|
|
|
# but we need it here
|
|
|
|
host = attributes[:host]
|
|
|
|
raise ArgumentError.new('host is required for this operation') unless
|
|
|
|
host
|
|
|
|
|
|
|
|
# Not sure if this is always required, so not raising exception if nil
|
|
|
|
device_config = attributes[:device_config]
|
|
|
|
|
|
|
|
# create_sr request provides sane defaults if some attributes are
|
|
|
|
# missing
|
2013-01-07 18:14:13 -05:00
|
|
|
attr = service.get_record(
|
|
|
|
service.create_sr( host.reference,
|
2012-12-30 18:55:42 -05:00
|
|
|
name,
|
|
|
|
type,
|
2013-01-06 08:31:26 -05:00
|
|
|
description || '',
|
|
|
|
device_config || {},
|
|
|
|
physical_size || '0',
|
|
|
|
content_type || 'user',
|
2012-12-30 18:55:42 -05:00
|
|
|
shared || false,
|
2013-01-06 08:31:26 -05:00
|
|
|
sm_config || {}),
|
2012-12-30 18:55:42 -05:00
|
|
|
'SR'
|
|
|
|
)
|
|
|
|
merge_attributes attr
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_attribute(name, *val)
|
2013-01-07 18:14:13 -05:00
|
|
|
data = service.set_attribute( 'SR', reference, name, *val )
|
2012-12-30 18:55:42 -05:00
|
|
|
# Do not reload automatically for performance reasons
|
|
|
|
# We can set multiple attributes at the same time and
|
|
|
|
# then reload manually
|
|
|
|
#reload
|
|
|
|
end
|
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
2012-12-22 18:21:33 -05:00
|
|
|
|
2012-04-02 07:25:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|