2012-04-02 13:25:03 +02:00
|
|
|
require 'fog/core/model'
|
|
|
|
|
|
|
|
module Fog
|
|
|
|
module Compute
|
|
|
|
class XenServer
|
|
|
|
class StorageRepository < Fog::Model
|
|
|
|
# API Reference here:
|
2013-12-10 23:05:42 -02:00
|
|
|
# http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=SR
|
2012-12-22 23:21:33 +00:00
|
|
|
|
2012-04-02 13:25:03 +02:00
|
|
|
identity :reference
|
2012-12-22 23:21:33 +00:00
|
|
|
|
2012-04-02 15:27:35 +02:00
|
|
|
attribute :name, :aliases => :name_label
|
|
|
|
attribute :description, :aliases => :name_description
|
2012-04-02 13:25:03 +02:00
|
|
|
attribute :uuid
|
2013-12-10 23:05:42 -02:00
|
|
|
attribute :blobs
|
2012-04-02 13:25:03 +02:00
|
|
|
attribute :allowed_operations
|
2012-04-02 15:27:35 +02:00
|
|
|
attribute :current_operations
|
2013-12-10 23:05:42 -02:00
|
|
|
attribute :introduced_by
|
|
|
|
attribute :local_cache_enabled
|
2012-04-02 13:25:03 +02:00
|
|
|
attribute :content_type
|
|
|
|
attribute :other_config
|
2012-04-02 15:27:35 +02:00
|
|
|
attribute :__pbds, :aliases => :PBDs
|
2012-04-02 13:25:03 +02:00
|
|
|
attribute :shared
|
|
|
|
attribute :type
|
2012-04-02 15:27:35 +02:00
|
|
|
attribute :tags
|
|
|
|
attribute :__vdis, :aliases => :VDIs
|
|
|
|
attribute :physical_size
|
|
|
|
attribute :physical_utilisation
|
2012-04-16 21:09:52 +02:00
|
|
|
attribute :sm_config
|
|
|
|
attribute :virtual_allocation
|
2012-12-22 23:21:33 +00:00
|
|
|
|
2012-04-02 15:27:35 +02:00
|
|
|
def vdis
|
2014-05-23 02:40:43 +01:00
|
|
|
__vdis.map { |vdi| service.vdis.get vdi }
|
2012-04-02 13:25:03 +02:00
|
|
|
end
|
2012-12-22 23:21:33 +00:00
|
|
|
|
2012-04-02 15:27:35 +02:00
|
|
|
def pbds
|
2014-05-23 02:40:43 +01:00
|
|
|
__pbds.map { |pbd| service.pbds.get pbd }
|
2012-04-02 15:27:35 +02:00
|
|
|
end
|
|
|
|
|
2012-04-16 21:09:52 +02:00
|
|
|
def scan
|
2012-12-22 23:21:33 +00:00
|
|
|
service.scan_sr reference
|
2012-04-16 21:09:52 +02:00
|
|
|
reload
|
|
|
|
end
|
|
|
|
|
2012-12-31 00:55:42 +01:00
|
|
|
def destroy
|
2013-01-08 00:14:13 +01:00
|
|
|
service.destroy_sr reference
|
2012-12-31 00:55:42 +01:00
|
|
|
end
|
2014-02-19 12:30:59 +00:00
|
|
|
|
2012-12-31 00:55:42 +01:00
|
|
|
def save
|
|
|
|
requires :name
|
|
|
|
requires :type
|
|
|
|
|
2014-02-19 12:30:59 +00:00
|
|
|
# host is not a model attribute (not in XAPI at least),
|
2012-12-31 00:55:42 +01:00
|
|
|
# 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-08 00:14:13 +01:00
|
|
|
attr = service.get_record(
|
2014-02-19 12:30:59 +00:00
|
|
|
service.create_sr( host.reference,
|
2012-12-31 00:55:42 +01:00
|
|
|
name,
|
|
|
|
type,
|
2013-01-06 14:31:26 +01:00
|
|
|
description || '',
|
|
|
|
device_config || {},
|
|
|
|
physical_size || '0',
|
|
|
|
content_type || 'user',
|
2012-12-31 00:55:42 +01:00
|
|
|
shared || false,
|
2013-01-06 14:31:26 +01:00
|
|
|
sm_config || {}),
|
2012-12-31 00:55:42 +01:00
|
|
|
'SR'
|
|
|
|
)
|
2014-02-19 12:30:59 +00:00
|
|
|
merge_attributes attr
|
2012-12-31 00:55:42 +01:00
|
|
|
true
|
|
|
|
end
|
2014-02-19 12:30:59 +00:00
|
|
|
|
2012-12-31 00:55:42 +01:00
|
|
|
def set_attribute(name, *val)
|
2013-01-08 00:14:13 +01:00
|
|
|
data = service.set_attribute( 'SR', reference, name, *val )
|
2012-12-31 00:55:42 +01: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 13:25:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|