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

[xenserver|compute] Updates reference to service

This commit is contained in:
Paul Thornthwaite 2012-12-22 23:21:33 +00:00
parent e8630a0083
commit 0c674865d6
20 changed files with 162 additions and 162 deletions

View file

@ -7,9 +7,9 @@ module Fog
class Host < Fog::Model class Host < Fog::Model
# API Reference here: # API Reference here:
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=host # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=host
identity :reference identity :reference
attribute :name, :aliases => :name_label attribute :name, :aliases => :name_label
attribute :uuid attribute :uuid
attribute :address attribute :address
@ -22,17 +22,17 @@ module Fog
attribute :__pbds, :aliases => :PBDs attribute :__pbds, :aliases => :PBDs
attribute :__pifs, :aliases => :PIFs attribute :__pifs, :aliases => :PIFs
attribute :__resident_vms, :aliases => :resident_VMs attribute :__resident_vms, :aliases => :resident_VMs
def pifs def pifs
__pifs.collect { |pif| connection.pifs.get pif } __pifs.collect { |pif| service.pifs.get pif }
end end
def pbds def pbds
__pbds.collect { |pbd| connection.pbds.get pbd } __pbds.collect { |pbd| service.pbds.get pbd }
end end
def resident_servers def resident_servers
__resident_vms.collect { |ref| connection.servers.get ref } __resident_vms.collect { |ref| service.servers.get ref }
end end
def resident_vms def resident_vms
@ -41,7 +41,7 @@ module Fog
def metrics def metrics
return nil unless __metrics return nil unless __metrics
rec = connection.get_record(__metrics, 'host_metrics' ) rec = service.get_record(__metrics, 'host_metrics' )
Fog::Compute::XenServer::HostMetrics.new(rec) Fog::Compute::XenServer::HostMetrics.new(rec)
end end
@ -107,7 +107,7 @@ module Fog
end end
end end
end end
end end
end end

View file

@ -4,26 +4,26 @@ require 'fog/xenserver/models/compute/host'
module Fog module Fog
module Compute module Compute
class XenServer class XenServer
class Hosts < Fog::Collection class Hosts < Fog::Collection
model Fog::Compute::XenServer::Host model Fog::Compute::XenServer::Host
def all(options={}) def all(options={})
data = connection.get_records 'host' data = service.get_records 'host'
load(data) load(data)
end end
def get( host_ref ) def get( host_ref )
if host_ref && host = connection.get_record( host_ref, 'host' ) if host_ref && host = service.get_record( host_ref, 'host' )
new(host) new(host)
else else
nil nil
end end
end end
end end
end end
end end
end end

View file

@ -3,15 +3,15 @@ require 'fog/core/model'
module Fog module Fog
module Compute module Compute
class XenServer class XenServer
class Network < Fog::Model class Network < Fog::Model
# API Reference here: # API Reference here:
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=network # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=network
identity :reference identity :reference
attribute :uuid attribute :uuid
attribute :__vifs, :aliases => :VIFs attribute :__vifs, :aliases => :VIFs
attribute :tags attribute :tags
attribute :mtu, :aliases => :MTU attribute :mtu, :aliases => :MTU
attribute :bridge attribute :bridge
@ -19,23 +19,23 @@ module Fog
attribute :name, :aliases => :name_label attribute :name, :aliases => :name_label
attribute :other_config attribute :other_config
attribute :__pifs, :aliases => :PIFs attribute :__pifs, :aliases => :PIFs
attribute :allowed_operations attribute :allowed_operations
attribute :current_operations attribute :current_operations
attribute :blobs attribute :blobs
def refresh def refresh
data = connection.get_record( reference, 'network' ) data = service.get_record( reference, 'network' )
merge_attributes( data ) merge_attributes( data )
true true
end end
# #
# Return the list of network related PIFs # Return the list of network related PIFs
# #
def pifs def pifs
p = [] p = []
__pifs.each do |pif| __pifs.each do |pif|
p << connection.pifs.get(pif) p << service.pifs.get(pif)
end end
p p
end end
@ -46,13 +46,13 @@ module Fog
def vifs def vifs
v = [] v = []
__vifs.each do |vif| __vifs.each do |vif|
v << connection.vifs.get(vif) v << service.vifs.get(vif)
end end
v v
end end
end end
end end
end end
end end

View file

@ -8,18 +8,18 @@ module Fog
class Networks < Fog::Collection class Networks < Fog::Collection
model Fog::Compute::XenServer::Network model Fog::Compute::XenServer::Network
def initialize(attributes) def initialize(attributes)
super super
end end
def all(options = {}) def all(options = {})
data = connection.get_records 'network' data = service.get_records 'network'
load(data) load(data)
end end
def get( ref ) def get( ref )
if ref && obj = connection.get_record( ref, 'network' ) if ref && obj = service.get_record( ref, 'network' )
new(obj) new(obj)
end end
rescue Fog::XenServer::NotFound rescue Fog::XenServer::NotFound

View file

@ -3,20 +3,20 @@ require 'fog/core/model'
module Fog module Fog
module Compute module Compute
class XenServer class XenServer
class PBD < Fog::Model class PBD < Fog::Model
# API Reference here: # API Reference here:
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=PBD # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=PBD
identity :reference identity :reference
attribute :uuid attribute :uuid
attribute :__host, :aliases => :host attribute :__host, :aliases => :host
attribute :__sr, :aliases => :SR attribute :__sr, :aliases => :SR
attribute :currently_attached attribute :currently_attached
def sr def sr
connection.storage_repositories.get __sr service.storage_repositories.get __sr
end end
def storage_repository def storage_repository
@ -24,7 +24,7 @@ module Fog
end end
def host def host
connection.hosts.get __host service.hosts.get __host
end end
def unplug def unplug
@ -32,7 +32,7 @@ module Fog
end end
end end
end end
end end
end end

View file

@ -8,18 +8,18 @@ module Fog
class Pbds < Fog::Collection class Pbds < Fog::Collection
model Fog::Compute::XenServer::PBD model Fog::Compute::XenServer::PBD
def initialize(attributes) def initialize(attributes)
super super
end end
def all(options = {}) def all(options = {})
data = connection.get_records 'PBD' data = service.get_records 'PBD'
load(data) load(data)
end end
def get( ref ) def get( ref )
if ref && obj = connection.get_record( ref, 'PBD' ) if ref && obj = service.get_record( ref, 'PBD' )
new(obj) new(obj)
else else
nil nil

View file

@ -3,13 +3,13 @@ require 'fog/core/model'
module Fog module Fog
module Compute module Compute
class XenServer class XenServer
class PIF < Fog::Model class PIF < Fog::Model
# API Reference here: # API Reference here:
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=PIF # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=PIF
identity :reference identity :reference
attribute :uuid attribute :uuid
attribute :physical attribute :physical
attribute :mac, :aliases => :MAC attribute :mac, :aliases => :MAC
@ -20,7 +20,7 @@ module Fog
attribute :dns, :aliases => :DNS attribute :dns, :aliases => :DNS
attribute :gateway attribute :gateway
attribute :ip, :aliases => :IP attribute :ip, :aliases => :IP
attribute :ip_configuration_mode attribute :ip_configuration_mode
attribute :mtu, :aliases => :MTU attribute :mtu, :aliases => :MTU
attribute :__network, :aliases => :network attribute :__network, :aliases => :network
attribute :netmask attribute :netmask
@ -30,17 +30,17 @@ module Fog
attribute :vlan, :aliases => :VLAN attribute :vlan, :aliases => :VLAN
attribute :other_config attribute :other_config
attribute :__host, :aliases => :host attribute :__host, :aliases => :host
def network def network
connection.networks.get __network service.networks.get __network
end end
def host def host
connection.hosts.get __host service.hosts.get __host
end end
end end
end end
end end
end end

View file

@ -8,18 +8,18 @@ module Fog
class Pifs < Fog::Collection class Pifs < Fog::Collection
model Fog::Compute::XenServer::PIF model Fog::Compute::XenServer::PIF
def initialize(attributes) def initialize(attributes)
super super
end end
def all(options = {}) def all(options = {})
data = connection.get_records 'PIF' data = service.get_records 'PIF'
load(data) load(data)
end end
def get( ref ) def get( ref )
if ref && obj = connection.get_record( ref, 'PIF' ) if ref && obj = service.get_record( ref, 'PIF' )
new(obj) new(obj)
end end
rescue Fog::XenServer::NotFound rescue Fog::XenServer::NotFound

View file

@ -3,27 +3,27 @@ require 'fog/core/model'
module Fog module Fog
module Compute module Compute
class XenServer class XenServer
class Pool < Fog::Model class Pool < Fog::Model
# API Reference here: # API Reference here:
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=pool # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=pool
identity :reference identity :reference
attribute :uuid attribute :uuid
attribute :name, :aliases => :name_label attribute :name, :aliases => :name_label
attribute :description, :aliases => :name_description attribute :description, :aliases => :name_description
attribute :__default_sr, :aliases => :default_SR attribute :__default_sr, :aliases => :default_SR
attribute :__master, :aliases => :master attribute :__master, :aliases => :master
attribute :tags attribute :tags
attribute :restrictions attribute :restrictions
attribute :ha_enabled attribute :ha_enabled
attribute :vswitch_controller attribute :vswitch_controller
attribute :__suspend_image_sr, :aliases => :suspend_image_SR attribute :__suspend_image_sr, :aliases => :suspend_image_SR
def default_sr def default_sr
connection.storage_repositories.get __default_sr service.storage_repositories.get __default_sr
end end
def default_sr=(sr) def default_sr=(sr)
@ -44,7 +44,7 @@ module Fog
end end
def master def master
connection.hosts.get __master service.hosts.get __master
end end
def set_attribute(name, *val) def set_attribute(name, *val)
@ -56,7 +56,7 @@ module Fog
end end
end end
end end
end end
end end

View file

@ -8,18 +8,18 @@ module Fog
class Pools < Fog::Collection class Pools < Fog::Collection
model Fog::Compute::XenServer::Pool model Fog::Compute::XenServer::Pool
def initialize(attributes) def initialize(attributes)
super super
end end
def all(options = {}) def all(options = {})
data = connection.get_records 'pool' data = service.get_records 'pool'
load(data) load(data)
end end
def get( pool_ref ) def get( pool_ref )
if pool_ref && pool = connection.get_record( pool_ref, 'pool' ) if pool_ref && pool = service.get_record( pool_ref, 'pool' )
new(pool) new(pool)
else else
nil nil

View file

@ -7,9 +7,9 @@ module Fog
class Server < Fog::Compute::Server class Server < Fog::Compute::Server
# API Reference here: # API Reference here:
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VM # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VM
identity :reference identity :reference
attribute :uuid attribute :uuid
attribute :name, :aliases => :name_label attribute :name, :aliases => :name_label
attribute :__affinity, :aliases => :affinity attribute :__affinity, :aliases => :affinity
@ -56,11 +56,11 @@ module Fog
end end
def vbds def vbds
__vbds.collect {|vbd| connection.vbds.get vbd } __vbds.collect {|vbd| service.vbds.get vbd }
end end
def affinity def affinity
connection.hosts.get __affinity service.hosts.get __affinity
end end
def destroy def destroy
@ -74,26 +74,26 @@ module Fog
if vbd.vdi.allowed_operations.include?("destroy") if vbd.vdi.allowed_operations.include?("destroy")
end end
end end
connection.destroy_server( reference ) service.destroy_server( reference )
true true
end end
def set_attribute(name, *val) def set_attribute(name, *val)
data = connection.set_attribute( 'VM', reference, name, *val ) data = service.set_attribute( 'VM', reference, name, *val )
# Do not reload automatically for performance reasons # Do not reload automatically for performance reasons
# We can set multiple attributes at the same time and # We can set multiple attributes at the same time and
# then reload manually # then reload manually
#reload #reload
end end
def refresh def refresh
data = connection.get_record( reference, 'VM' ) data = service.get_record( reference, 'VM' )
merge_attributes( data ) merge_attributes( data )
true true
end end
def vifs def vifs
__vifs.collect { |vif| connection.vifs.get vif } __vifs.collect { |vif| service.vifs.get vif }
end end
# associations # associations
@ -102,44 +102,44 @@ module Fog
end end
def resident_on def resident_on
connection.hosts.get __resident_on service.hosts.get __resident_on
end end
# #
# This is not always present in XenServer VMs # This is not always present in XenServer VMs
# Guest needs XenTools installed to report this AFAIK # Guest needs XenTools installed to report this AFAIK
def guest_metrics def guest_metrics
return nil unless __guest_metrics return nil unless __guest_metrics
rec = connection.get_record( __guest_metrics, 'VM_guest_metrics' ) rec = service.get_record( __guest_metrics, 'VM_guest_metrics' )
Fog::Compute::XenServer::GuestMetrics.new(rec) Fog::Compute::XenServer::GuestMetrics.new(rec)
end end
def tools_installed? def tools_installed?
!guest_metrics.nil? !guest_metrics.nil?
end end
def home_hypervisor def home_hypervisor
connection.hosts.first service.hosts.first
end end
def mac_address def mac_address
networks.first.MAC networks.first.MAC
end end
def running? def running?
reload reload
power_state == "Running" power_state == "Running"
end end
def halted? def halted?
reload reload
power_state == "Halted" power_state == "Halted"
end end
# operations # operations
def start def start
return false if running? return false if running?
connection.start_server( reference ) service.start_server( reference )
true true
end end
@ -149,25 +149,25 @@ module Fog
if params[:auto_start].nil? if params[:auto_start].nil?
auto_start = true auto_start = true
else else
auto_start = params[:auto_start] auto_start = params[:auto_start]
end end
if template_name if template_name
attr = connection.get_record( attr = service.get_record(
connection.create_server( name, template_name, nets, :auto_start => auto_start), service.create_server( name, template_name, nets, :auto_start => auto_start),
'VM' 'VM'
) )
else else
attr = connection.get_record( attr = service.get_record(
connection.create_server_raw(attributes), service.create_server_raw(attributes),
'VM' 'VM'
) )
end end
merge_attributes attr merge_attributes attr
true true
end end
def reboot(stype = 'clean') def reboot(stype = 'clean')
connection.reboot_server(reference, stype) service.reboot_server(reference, stype)
true true
end end
@ -181,7 +181,7 @@ module Fog
def stop(stype = 'clean') def stop(stype = 'clean')
return false if !running? return false if !running?
connection.shutdown_server( reference, stype ) service.shutdown_server( reference, stype )
wait_for { power_state == 'Halted' } wait_for { power_state == 'Halted' }
true true
end end
@ -195,12 +195,12 @@ module Fog
end end
def provision def provision
connection.provision_server reference service.provision_server reference
end end
# def snapshot # def snapshot
# requires :reference, :name_label # requires :reference, :name_label
# data = connection.snapshot_server(@reference, @name_label) # data = service.snapshot_server(@reference, @name_label)
# merge_attributes(data.body) # merge_attributes(data.body)
# true # true
# end # end

View file

@ -10,7 +10,7 @@ module Fog
model Fog::Compute::XenServer::Server model Fog::Compute::XenServer::Server
def templates def templates
data = connection.get_records 'VM' data = service.get_records 'VM'
data.delete_if do |vm| data.delete_if do |vm|
!vm[:is_a_template] !vm[:is_a_template]
end end
@ -18,15 +18,15 @@ module Fog
end end
def custom_templates def custom_templates
data = connection.get_records 'VM' data = service.get_records 'VM'
data.delete_if do |vm| data.delete_if do |vm|
!vm[:is_a_template] or !vm[:other_config]['default_template'].nil? !vm[:is_a_template] or !vm[:other_config]['default_template'].nil?
end end
load(data) load(data)
end end
def builtin_templates def builtin_templates
data = connection.get_records 'VM' data = service.get_records 'VM'
data.delete_if do |vm| data.delete_if do |vm|
!vm[:is_a_template] or vm[:other_config]['default_template'].nil? !vm[:is_a_template] or vm[:other_config]['default_template'].nil?
end end
@ -34,7 +34,7 @@ module Fog
end end
def all(options = {}) def all(options = {})
data = connection.get_records 'VM' data = service.get_records 'VM'
# Exclude templates # Exclude templates
data.delete_if { |vm| vm[:is_control_domain] or vm[:is_a_template] } data.delete_if { |vm| vm[:is_control_domain] or vm[:is_a_template] }
data.delete_if { |vm| vm[:is_a_snapshot] and !options[:include_snapshots] } data.delete_if { |vm| vm[:is_a_snapshot] and !options[:include_snapshots] }
@ -44,12 +44,12 @@ module Fog
end end
def get_by_name( name ) def get_by_name( name )
ref = connection.get_vm_by_name( name ) ref = service.get_vm_by_name( name )
get ref get ref
end end
def get( vm_ref ) def get( vm_ref )
if vm_ref && vm = connection.get_record( vm_ref, 'VM' ) if vm_ref && vm = service.get_record( vm_ref, 'VM' )
new(vm) new(vm)
end end
rescue Fog::XenServer::NotFound rescue Fog::XenServer::NotFound

View file

@ -10,14 +10,14 @@ module Fog
model Fog::Compute::XenServer::StorageRepository model Fog::Compute::XenServer::StorageRepository
def all def all
data = connection.get_records 'SR' data = service.get_records 'SR'
#data.delete_if {|sr| sr[:shared].eql?(false)} #data.delete_if {|sr| sr[:shared].eql?(false)}
#data.delete_if {|sr| sr[:content_type].eql?('iso')} #data.delete_if {|sr| sr[:content_type].eql?('iso')}
load(data) load(data)
end end
def get( sr_ref ) def get( sr_ref )
if sr_ref && sr = connection.get_record( sr_ref, 'SR' ) if sr_ref && sr = service.get_record( sr_ref, 'SR' )
new(sr) new(sr)
else else
nil nil

View file

@ -3,13 +3,13 @@ require 'fog/core/model'
module Fog module Fog
module Compute module Compute
class XenServer class XenServer
class StorageRepository < Fog::Model class StorageRepository < Fog::Model
# API Reference here: # API Reference here:
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=SR # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=SR
identity :reference identity :reference
attribute :name, :aliases => :name_label attribute :name, :aliases => :name_label
attribute :description, :aliases => :name_description attribute :description, :aliases => :name_description
attribute :uuid attribute :uuid
@ -26,17 +26,17 @@ module Fog
attribute :physical_utilisation attribute :physical_utilisation
attribute :sm_config attribute :sm_config
attribute :virtual_allocation attribute :virtual_allocation
def vdis def vdis
__vdis.collect { |vdi| connection.vdis.get vdi } __vdis.collect { |vdi| service.vdis.get vdi }
end end
def pbds def pbds
__pbds.collect { |pbd| connection.pbds.get pbd } __pbds.collect { |pbd| service.pbds.get pbd }
end end
def scan def scan
connection.scan_sr reference service.scan_sr reference
reload reload
end end
@ -84,7 +84,7 @@ module Fog
end end
end end
end end
end end
end end

View file

@ -3,13 +3,13 @@ require 'fog/core/model'
module Fog module Fog
module Compute module Compute
class XenServer class XenServer
class VBD < Fog::Model class VBD < Fog::Model
# API Reference here: # API Reference here:
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VBD # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VBD
identity :reference identity :reference
attribute :uuid attribute :uuid
attribute :currently_attached attribute :currently_attached
attribute :allowed_operations attribute :allowed_operations
@ -23,7 +23,7 @@ module Fog
attribute :userdevice attribute :userdevice
attribute :empty attribute :empty
attribute :type attribute :type
attribute :mode attribute :mode
attribute :storage_lock attribute :storage_lock
attribute :runtime_properties attribute :runtime_properties
attribute :unpluggable attribute :unpluggable
@ -38,36 +38,36 @@ module Fog
# May return nil # May return nil
# #
def vdi def vdi
connection.vdis.get __vdi service.vdis.get __vdi
end end
# #
# TODO: May it return nil? # TODO: May it return nil?
# #
def server def server
connection.servers.get __vm service.servers.get __vm
end end
def save def save
requires :vdi, :server requires :vdi, :server
ref = connection.create_vbd attributes[:server], attributes[:vdi], attributes ref = service.create_vbd attributes[:server], attributes[:vdi], attributes
merge_attributes connection.vbds.get(ref).attributes merge_attributes service.vbds.get(ref).attributes
end end
def unplug def unplug
connection.unplug_vbd reference service.unplug_vbd reference
end end
def unplug_force def unplug_force
connection.unplug_force_vbd reference service.unplug_force_vbd reference
end end
def eject def eject
connection.eject_vbd reference service.eject_vbd reference
end end
def insert(vdi) def insert(vdi)
connection.insert_vbd reference, vdi.reference service.insert_vbd reference, vdi.reference
end end
# #
@ -79,12 +79,12 @@ module Fog
# #
def metrics def metrics
return nil unless currently_attached return nil unless currently_attached
rec = connection.get_record( __metrics, 'VBD_metrics' ) rec = service.get_record( __metrics, 'VBD_metrics' )
Fog::Compute::XenServer::VbdMetrics.new(rec) Fog::Compute::XenServer::VbdMetrics.new(rec)
end end
end end
end end
end end
end end

View file

@ -8,18 +8,18 @@ module Fog
class Vbds < Fog::Collection class Vbds < Fog::Collection
model Fog::Compute::XenServer::VBD model Fog::Compute::XenServer::VBD
def initialize(attributes) def initialize(attributes)
super super
end end
def all(options = {}) def all(options = {})
data = connection.get_records 'VBD' data = service.get_records 'VBD'
load(data) load(data)
end end
def get( vbd_ref ) def get( vbd_ref )
if vbd_ref && vbd = connection.get_record( vbd_ref, 'VBD' ) if vbd_ref && vbd = service.get_record( vbd_ref, 'VBD' )
new(vbd) new(vbd)
end end
rescue Fog::XenServer::NotFound rescue Fog::XenServer::NotFound

View file

@ -3,13 +3,13 @@ require 'fog/core/model'
module Fog module Fog
module Compute module Compute
class XenServer class XenServer
class VDI < Fog::Model class VDI < Fog::Model
# API Reference here: # API Reference here:
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VDI # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VDI
identity :reference identity :reference
attribute :uuid attribute :uuid
attribute :is_a_snapshot attribute :is_a_snapshot
attribute :name, :aliases => :name_label attribute :name, :aliases => :name_label
@ -34,10 +34,10 @@ module Fog
attribute :on_boot attribute :on_boot
attribute :sm_config attribute :sm_config
attribute :snapshot_time attribute :snapshot_time
attribute :__snapshots, :aliases => :snapshots attribute :__snapshots, :aliases => :snapshots
attribute :__snapshot_of, :aliases => :snapshot_of attribute :__snapshot_of, :aliases => :snapshot_of
attribute :xenstore_data attribute :xenstore_data
# #
# Default VDI type is system # Default VDI type is system
# Default size 8GB # Default size 8GB
@ -50,45 +50,45 @@ module Fog
self.read_only ||= false unless attributes[:read_only] self.read_only ||= false unless attributes[:read_only]
self.sharable ||= false unless attributes[:sharable] self.sharable ||= false unless attributes[:sharable]
self.other_config ||= {} unless attributes[:other_config] self.other_config ||= {} unless attributes[:other_config]
super super
end end
def set_attribute(name, *val) def set_attribute(name, *val)
data = connection.set_attribute( 'VDI', reference, name, *val ) data = service.set_attribute( 'VDI', reference, name, *val )
end end
def snapshot_of def snapshot_of
connection.vdis.get __sr service.vdis.get __sr
end end
def parent def parent
connection.vdis.get __parent service.vdis.get __parent
end end
def snapshots def snapshots
__snapshots.collect do |ref| __snapshots.collect do |ref|
connection.vdis.get ref service.vdis.get ref
end end
end end
def vbds def vbds
__vbds.collect do |ref| __vbds.collect do |ref|
connection.vbds.get ref service.vbds.get ref
end end
end end
def save def save
requires :name, :storage_repository requires :name, :storage_repository
ref = connection.create_vdi attributes ref = service.create_vdi attributes
merge_attributes connection.vdis.get(ref).attributes merge_attributes service.vdis.get(ref).attributes
end end
def destroy def destroy
connection.destroy_vdi reference service.destroy_vdi reference
end end
def storage_repository def storage_repository
connection.storage_repositories.get __sr service.storage_repositories.get __sr
end end
def sr def sr
@ -96,7 +96,7 @@ module Fog
end end
end end
end end
end end
end end

View file

@ -8,14 +8,14 @@ module Fog
class Vdis < Fog::Collection class Vdis < Fog::Collection
model Fog::Compute::XenServer::VDI model Fog::Compute::XenServer::VDI
def all(options = {}) def all(options = {})
data = connection.get_records 'VDI' data = service.get_records 'VDI'
load(data) load(data)
end end
def get( vdi_ref ) def get( vdi_ref )
if vdi_ref && vdi = connection.get_record( vdi_ref, 'VDI' ) if vdi_ref && vdi = service.get_record( vdi_ref, 'VDI' )
new(vdi) new(vdi)
end end
rescue Fog::XenServer::NotFound rescue Fog::XenServer::NotFound

View file

@ -3,13 +3,13 @@ require 'fog/core/model'
module Fog module Fog
module Compute module Compute
class XenServer class XenServer
class VIF < Fog::Model class VIF < Fog::Model
# API Reference here: # API Reference here:
# http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VIF # http://docs.vmd.citrix.com/XenServer/5.6.0/1.0/en_gb/api/?c=VIF
identity :reference identity :reference
attribute :mac, :aliases => :MAC attribute :mac, :aliases => :MAC
attribute :uuid attribute :uuid
attribute :allowed_operations attribute :allowed_operations
@ -22,30 +22,30 @@ module Fog
attribute :status_code attribute :status_code
attribute :status_detail attribute :status_detail
attribute :__vm, :aliases => :VM attribute :__vm, :aliases => :VM
def destroy def destroy
connection.destroy_vif reference service.destroy_vif reference
end end
def network def network
connection.networks.get __network service.networks.get __network
end end
def server def server
connection.servers.get __vm service.servers.get __vm
end end
def save def save
requires :server requires :server
raise ArgumentError.new('network is required for this operation') \ raise ArgumentError.new('network is required for this operation') \
unless attributes[:__network] unless attributes[:__network]
ref = connection.create_vif attributes[:server], attributes[:__network] ref = service.create_vif attributes[:server], attributes[:__network]
merge_attributes connection.vifs.get(ref).attributes merge_attributes service.vifs.get(ref).attributes
end end
end end
end end
end end
end end

View file

@ -8,14 +8,14 @@ module Fog
class Vifs < Fog::Collection class Vifs < Fog::Collection
model Fog::Compute::XenServer::VIF model Fog::Compute::XenServer::VIF
def all(options = {}) def all(options = {})
data = connection.get_records 'VIF' data = service.get_records 'VIF'
load(data) load(data)
end end
def get( ref ) def get( ref )
if ref && obj = connection.get_record( ref, 'VIF' ) if ref && obj = service.get_record( ref, 'VIF' )
new(obj) new(obj)
end end
rescue Fog::XenServer::NotFound rescue Fog::XenServer::NotFound